Added support for OPTIONS method.

This commit is contained in:
jbrendel
2011-11-08 12:31:18 +13:00
parent 8c90c610cd
commit 73ba48be2e
5 changed files with 29 additions and 5 deletions
+2 -1
View File
@@ -49,4 +49,5 @@ Patches and Suggestions
- Daniel Hengeveld
- Dan Head
- Bruno Renié
- David Fischer
- David Fischer
- Juergen Brendel
+1 -1
View 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 (
+12 -1
View 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.
+2 -1
View 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)
+12 -1
View 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)
return Session(**kwargs)