mirror of
https://github.com/kennethreitz/requests.git
synced 2026-06-05 22:50:18 +00:00
accept any extra args to r.read()
This commit is contained in:
+17
-17
@@ -31,8 +31,8 @@ __license__ = 'ISC'
|
||||
__copyright__ = 'Copyright 2011 Kenneth Reitz'
|
||||
|
||||
__all__ = [
|
||||
'Request', 'Response', 'request', 'get', 'head', 'post', 'put', 'delete',
|
||||
'auth_manager', 'AuthObject','RequestException', 'AuthenticationError',
|
||||
'Request', 'Response', 'request', 'get', 'head', 'post', 'put', 'delete',
|
||||
'auth_manager', 'AuthObject','RequestException', 'AuthenticationError',
|
||||
'URLRequired', 'InvalidMethod', 'HTTPError'
|
||||
]
|
||||
|
||||
@@ -63,7 +63,7 @@ class Request(object):
|
||||
|
||||
def __init__(self, url=None, headers=dict(), files=None, method=None,
|
||||
data=dict(), auth=None, cookiejar=None):
|
||||
|
||||
|
||||
self.url = url
|
||||
self.headers = headers
|
||||
self.files = files
|
||||
@@ -141,7 +141,7 @@ class Request(object):
|
||||
|
||||
def _build_response(self, resp):
|
||||
"""Build internal Response object from given response."""
|
||||
|
||||
|
||||
self.response.status_code = getattr(resp, 'code', None)
|
||||
self.response.headers = getattr(resp.info(), 'dict', None)
|
||||
self.response.url = getattr(resp, 'url', None)
|
||||
@@ -151,7 +151,7 @@ class Request(object):
|
||||
@staticmethod
|
||||
def _build_url(url, data):
|
||||
"""Build URLs."""
|
||||
|
||||
|
||||
if urlparse(url).query:
|
||||
return '%s&%s' % (url, data)
|
||||
else:
|
||||
@@ -182,10 +182,10 @@ class Request(object):
|
||||
|
||||
if self.data:
|
||||
self.files.update(self.data)
|
||||
|
||||
|
||||
datagen, headers = multipart_encode(self.files)
|
||||
req = _Request(self.url, data=datagen, headers=headers, method=self.method)
|
||||
|
||||
|
||||
else:
|
||||
req = _Request(self.url, data=self._enc_data, method=self.method)
|
||||
|
||||
@@ -199,7 +199,7 @@ class Request(object):
|
||||
|
||||
if self.cookiejar is not None:
|
||||
self.cookiejar.extract_cookies(resp, req)
|
||||
|
||||
|
||||
except urllib2.HTTPError, why:
|
||||
self._build_response(why)
|
||||
self.response.error = why
|
||||
@@ -216,9 +216,9 @@ class Request(object):
|
||||
return self.sent
|
||||
|
||||
|
||||
def read(self):
|
||||
def read(self, *args):
|
||||
return self.response.read()
|
||||
|
||||
|
||||
class Response(object):
|
||||
"""The :class:`Request` object. All :class:`Request` objects contain a
|
||||
:class:`Request.response <response>` attribute, which is an instance of
|
||||
@@ -249,13 +249,13 @@ class Response(object):
|
||||
if self.error:
|
||||
raise self.error
|
||||
|
||||
def read(self):
|
||||
def read(self, *args):
|
||||
return self.content
|
||||
|
||||
|
||||
class AuthManager(object):
|
||||
"""Authentication Manager."""
|
||||
|
||||
|
||||
def __new__(cls):
|
||||
singleton = cls.__dict__.get('__singleton__')
|
||||
if singleton is not None:
|
||||
@@ -277,7 +277,7 @@ class AuthManager(object):
|
||||
|
||||
def add_auth(self, uri, auth):
|
||||
"""Registers AuthObject to AuthManager."""
|
||||
|
||||
|
||||
uri = self.reduce_uri(uri, False)
|
||||
self._auth[uri] = auth
|
||||
|
||||
@@ -286,9 +286,9 @@ class AuthManager(object):
|
||||
# uri could be a single URI or a sequence
|
||||
if isinstance(uri, basestring):
|
||||
uri = [uri]
|
||||
|
||||
|
||||
reduced_uri = tuple([self.reduce_uri(u, False) for u in uri])
|
||||
|
||||
|
||||
if reduced_uri not in self.passwd:
|
||||
self.passwd[reduced_uri] = {}
|
||||
self.passwd[reduced_uri] = (user, passwd)
|
||||
@@ -332,7 +332,7 @@ class AuthManager(object):
|
||||
authority = "%s:%d" % (host, dport)
|
||||
return authority, path
|
||||
|
||||
|
||||
|
||||
def is_suburi(self, base, test):
|
||||
"""Check if test is below base in a URI tree
|
||||
|
||||
@@ -441,7 +441,7 @@ def get(url, params={}, headers={}, cookies=None, auth=None):
|
||||
:param cookies: (optional) CookieJar object to send with the :class:`Request`.
|
||||
:param auth: (optional) AuthObject to enable Basic HTTP Auth.
|
||||
"""
|
||||
|
||||
|
||||
return request('GET', url, params=params, headers=headers, cookies=cookies, auth=auth)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user