From: jbrendel Date: Mon, 7 Nov 2011 23:31:18 +0000 (+1300) Subject: Added support for OPTIONS method. X-Git-Tag: v0.8.0~40^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=73ba48be2e51e2dea2f4e6c924495796c112a9a3;p=services%2Fpython-requests.git Added support for OPTIONS method. --- diff --git a/AUTHORS b/AUTHORS index 131c0f6..2ebcdfd 100644 --- 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 diff --git a/requests/__init__.py b/requests/__init__.py index 1140a52..d496b98 100644 --- a/requests/__init__.py +++ b/requests/__init__.py @@ -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 ( diff --git a/requests/api.py b/requests/api.py index a139f3d..764e490 100644 --- a/requests/api.py +++ b/requests/api.py @@ -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. diff --git a/requests/async.py b/requests/async.py index 92839c3..cef383f 100644 --- a/requests/async.py +++ b/requests/async.py @@ -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) diff --git a/requests/sessions.py b/requests/sessions.py index eaeb96e..7cc8479 100644 --- a/requests/sessions.py +++ b/requests/sessions.py @@ -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)