Added support for OPTIONS method.
authorjbrendel <juergen@brendel.com>
Mon, 7 Nov 2011 23:31:18 +0000 (12:31 +1300)
committerjbrendel <juergen@brendel.com>
Mon, 7 Nov 2011 23:31:18 +0000 (12:31 +1300)
AUTHORS
requests/__init__.py
requests/api.py
requests/async.py
requests/sessions.py

diff --git a/AUTHORS b/AUTHORS
index 131c0f6..2ebcdfd 100644 (file)
--- a/AUTHORS
+++ b/AUTHORS
@@ -49,4 +49,5 @@ Patches and Suggestions
 - Daniel Hengeveld
 - Dan Head
 - Bruno ReniĆ©
-- David Fischer
\ No newline at end of file
+- David Fischer
+- Juergen Brendel
index 1140a52..d496b98 100644 (file)
@@ -24,7 +24,7 @@ __copyright__ = 'Copyright 2011 Kenneth Reitz'
 
 from . import utils
 from .models import Request, Response
-from .api import request, get, head, post, patch, put, delete
+from .api import request, get, options, head, post, patch, put, delete
 from .sessions import session
 from .status_codes import codes
 from .exceptions import (
index a139f3d..764e490 100644 (file)
@@ -13,7 +13,7 @@ This module implements the Requests API.
 
 from .sessions import session
 
-__all__ = ('request', 'get', 'head', 'post', 'patch', 'put', 'delete')
+__all__ = ('request', 'get', 'options', 'head', 'post', 'patch', 'put', 'delete')
 
 
 def request(method, url,
@@ -67,6 +67,17 @@ def get(url, **kwargs):
     return request('GET', url, **kwargs)
 
 
+def options(url, **kwargs):
+    """Sends a OPTIONS request. Returns :class:`Response` object.
+
+    :param url: URL for the new :class:`Request` object.
+    :param **kwargs: Optional arguments that ``request`` takes.
+    """
+
+    kwargs.setdefault('allow_redirects', True)
+    return request('OPTIONS', url, **kwargs)
+
+
 def head(url, **kwargs):
     """Sends a HEAD request. Returns :class:`Response` object.
 
index 92839c3..cef383f 100644 (file)
@@ -24,7 +24,7 @@ from .hooks import dispatch_hook
 
 __all__ = (
     'map',
-    'get', 'head', 'post', 'put', 'patch', 'delete', 'request'
+    'get', 'options', 'head', 'post', 'put', 'patch', 'delete', 'request'
 )
 
 
@@ -53,6 +53,7 @@ def send(r, pools=None):
 
 # Patched requests.api functions.
 get = patched(api.get)
+options = patched(api.options)
 head = patched(api.head)
 post = patched(api.post)
 put = patched(api.put)
index eaeb96e..7cc8479 100644 (file)
@@ -188,6 +188,17 @@ class Session(object):
         return self.request('GET', url, **kwargs)
 
 
+    def options(self, url, **kwargs):
+        """Sends a OPTIONS request. Returns :class:`Response` object.
+
+        :param url: URL for the new :class:`Request` object.
+        :param **kwargs: Optional arguments that ``request`` takes.
+        """
+
+        kwargs.setdefault('allow_redirects', True)
+        return self.request('OPTIONS', url, **kwargs)
+
+
     def head(self, url, **kwargs):
         """Sends a HEAD request. Returns :class:`Response` object.
 
@@ -246,4 +257,4 @@ class Session(object):
 def session(**kwargs):
     """Returns a :class:`Session` for context-management."""
 
-    return Session(**kwargs)
\ No newline at end of file
+    return Session(**kwargs)