Skip to content
Myr

Merge branch 'develop'

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Kenneth Reitz · committed by Kenneth Reitz · parents 81d5997, 8b64097 · Browse files · 10 files+100 added−34 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

10 files+100 added−34 removed

  • other:+100 added−34 removed

10 files+100 added−34 removed

modified:docs/user/advanced.rst+1 added-1 removed
32 unmodified lines
3334 with requests.session(auth=auth, headers=headers) as c:3536 # both 'x-test' and 'x-test2' are sent37 c.get('http://httpbin.org/headers', header={'x-test2', 'true'})37 c.get('http://httpbin.org/headers', headers={'x-test2': 'true'})383940.. admonition:: Global Settings41
96 unmodified lines
modified:requests/config.py+1 added
59 unmodified lines
60settings.accept_gzip = True61settings.proxies = None62settings.verbose = None63settings.timeout = None64settings.max_redirects = 306566#: Use socket.setdefaulttimeout() as fallback?67settings.timeout_fallback = True
modified:requests/core.py+2 added-2 removed
10 unmodified lines
1112"""1314__title__ = 'requests'15__version__ = '0.6.0'16__build__ = 0x00060015__version__ = '0.6.1'16__build__ = 0x00060117__author__ = 'Kenneth Reitz'18__license__ = 'ISC'19__copyright__ = 'Copyright 2011 Kenneth Reitz'20
7 unmodified lines
modified:requests/exceptions.py+3 added
19 unmodified lines
20 """A valid URL is required to make a request."""2122class InvalidMethod(RequestException):23 """An inappropriate method was attempted."""2425class TooManyRedirects(RequestException):26 """Too many redirects."""
modified:requests/models.py+34 added-21 removed
19 unmodified lines
20from .structures import CaseInsensitiveDict21from .packages.poster.encode import multipart_encode22from .packages.poster.streaminghttp import register_openers, get_handlers23from .utils import dict_from_cookiejar24from .exceptions import RequestException, AuthenticationError, Timeout, URLRequired, InvalidMethod24from .exceptions import RequestException, AuthenticationError, Timeout, URLRequired, InvalidMethod, TooManyRedirects25from .status_codes import codes262727REDIRECT_STATI = (301, 302, 303, 307)28REDIRECT_STATI = (codes.moved, codes.found, codes.other, codes.temporary_moved)29303132class Request(object):33 """The :class:`Request <models.Request>` object. It carries out all functionality of34 Requests. Recommended interface is with the Requests functions.35 """3635 _METHODS = ('GET', 'HEAD', 'PUT', 'POST', 'DELETE', 'PATCH')3637 def __init__(self,38 url=None, headers=dict(), files=None, method=None, data=dict(),39 params=dict(), auth=None, cookiejar=None, timeout=None, redirect=False,40 allow_redirects=False, proxies=None):
74 unmodified lines
115 def __repr__(self):116 return '<Request [%s]>' % (self.method)117118119 def __setattr__(self, name, value):120 if (name == 'method') and (value):121 if not value in self._METHODS:122 raise InvalidMethod()123124 object.__setattr__(self, name, value)125126119 def _checks(self):120 """Deterministic checks for consistency."""121122 if not self.url:
52 unmodified lines
175176 try:177 response.headers = CaseInsensitiveDict(getattr(resp.info(), 'dict', None))178 response.read = resp.read179 response._resp = resp187 response.close = resp.close180 response._close = resp.close181182 if self.cookiejar:183184 response.cookies = dict_from_cookiejar(self.cookiejar)
18 unmodified lines
203204 while (205 ('location' in r.headers) and206 ((self.method in ('GET', 'HEAD')) or214 (r.status_code is 303) or207 (r.status_code is codes.see_other) or208 (self.allow_redirects))209 ):210211 r.close()212213 if not len(history) < settings.max_redirects:214 raise TooManyRedirects()215216 history.append(r)217218 url = r.headers['location']219220 # Handle redirection without scheme (see: RFC 1808 Section 4)221 if url.startswith('//'):222 parsed_rurl = urlparse(r.url)223 url = '%s:%s' % (parsed_rurl.scheme, url)224225 # Facilitate non-RFC2616-compliant 'location' headers226 # (e.g. '/path/to/resource' instead of 'http://domain.tld/path/to/resource')224 url = urljoin(r.url, url)227 if not urlparse(url).netloc:228 url = urljoin(r.url, urllib.quote(urllib.unquote(url)))229230 # http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.4227 if r.status_code is 303:231 if r.status_code is codes.see_other:232 method = 'GET'233 else:234 method = self.method235
36 unmodified lines
272273 def _build_url(self):274 """Build the actual URL to use."""275272 # Support for unicode domain names.273 parsed_url = list(urlparse(self.url))274 parsed_url[1] = parsed_url[1].encode('idna')275 self.url = urlunparse(parsed_url)276 # Support for unicode domain names and paths.277 scheme, netloc, path, params, query, fragment = urlparse(self.url)278 netloc = netloc.encode('idna')279 if isinstance(path, unicode):280 path = path.encode('utf-8')281 path = urllib.quote(urllib.unquote(path))282 self.url = str(urlunparse([ scheme, netloc, path, params, query, fragment ]))283284 if self._enc_params:285 if urlparse(self.url).query:286 return '%s&%s' % (self.url, self._enc_params)
145 unmodified lines
432 self._content = zlib.decompress(self._content, 16+zlib.MAX_WBITS)433 except zlib.error:434 pass435 return self._content436 else:437 raise AttributeError438430439 def raise_for_status(self):440 """Raises stored :class:`HTTPError` or :class:`URLError`, if one occured."""441 if self.error:442 raise self.error443444445 def close(self):446 if self._resp.fp is not None and hasattr(self._resp.fp, '_sock'):447 self._resp.fp._sock.recv = None448 self._close()449450class AuthManager(object):451 """Requests Authentication Manager."""452453 def __new__(cls):
170 unmodified lines
modified:requests/status_codes.py+4 added-4 removed
20 unmodified lines
21 208: ('im_used',),2223 # Redirection.24 300: ('multiple_choices',),25 301: ('moved_permanently', 'moved'),25 301: ('moved_permanently', 'moved', '\\o-'),26 302: ('found',),27 302: ('see_other', 'other'),27 303: ('see_other', 'other'),28 304: ('not_modified',),29 305: ('use_proxy',),30 306: ('switch_proxy',),31 307: ('temporary_redirect', 'temporary_moved', 'temporary'),
3 unmodified lines
35 400: ('bad_request', 'bad'),36 401: ('unauthorized',),37 402: ('payment_required', 'payment'),38 403: ('forbidden',),39 404: ('not_found',),39 404: ('not_found', '-o-'),40 405: ('method_not_allowed', 'not_allowed'),41 406: ('not_acceptable',),42 407: ('proxy_authentication_required', 'proxy_auth', 'proxy_authentication'),43 408: ('request_timeout', 'timeout'),
17 unmodified lines
61 450: ('blocked_by_windows_parental_controls', 'parental_controls'),62 499: ('client_closed_request',),6364 # Server Error.65 500: ('internal_server_error', 'server_error'),65 500: ('internal_server_error', 'server_error', '/o\\'),66 501: ('not_implemented',),67 502: ('bad_gateway',),68 503: ('service_unavailable', 'unavailable'),69 504: ('gateway_timeout',),
14 unmodified lines
modified:AUTHORS+4 added
33 unmodified lines
34- Jeremy Selier35- Jens Diemer36- Alex <@alopatin>37- Tom Hogans <tomhsx@gmail.com>38- Armin Ronacher39- Shrikant Sharat Kandula40- Mikko Ohtamaa41- Den Shabalin
added:AUTHORS.orig+40 added
1Requests is written and maintained by Kenneth Reitz and2various contributors:34Development Lead5````````````````67- Kenneth Reitz <me@kennethreitz.com>8910Patches and Suggestions11```````````````````````1213- Various Pocoo Members14- Chris Adams15- Flavio Percoco Premoli16- Dj Gilcrease17- Justin Murphy18- Rob Madole19- Aram Dulyan20- Johannes Gorset21- 村山めがね (Megane Murayama)22- James Rowe23- Daniel Schauenberg24- Zbigniew Siciarz25- Daniele Tricoli 'Eriol'26- Richard Boulton27- Miguel Olivares <miguel@moliware.com>28- Alberto Paro29- Jérémy Bethmont30- 潘旭 (Xu Pan)31- Tamás Gulácsi32- Rubén Abad33- Peter Manser34- Jeremy Selie35<<<<<<< HEAD36- Jens Diemer37- Alex <@alopatin>38=======39- Tom Hogans <tomhsx@gmail.com>40>>>>>>> 0ed641a26ec2200de00e4bbf3d170c767375351e
modified:HISTORY.rst+11 added
1History2-------3450.6.1 (2011-08-20)6++++++++++++++++++78* Enhanced status codes experience ``\o/``9* Set a maximum number of redirects (``settings.max_redirects``)10* Full Unicode URL support11* Support for protocol-less redirects.12* Allow for arbitrary request types.13* Bugfixes1415160.6.0 (2011-08-17)17++++++++++++++++++1819* New callback hook system
142 unmodified lines
modified:README.rst-6 removed
98 unmodified lines
99100If you'd like to contribute, simply fork `the repository`_, commit your changes to the **develop** branch (or branch off of it), and send a pull request. Make sure you add yourself to AUTHORS_.101102103104Roadmap105-------106107- Sphinx Documentation108103.. _`the repository`: http://github.com/kennethreitz/requests104.. _AUTHORS: http://github.com/kennethreitz/requests/blob/master/AUTHORS