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
Provenance
- Commit
3b085ed- Tree
8a3a73c- Author
Kenneth Reitz <me@kennethreitz.com>- Committer
Kenneth Reitz <me@kennethreitz.com>- Parent 1
81d5997- Parent 2
8b64097
10 files changed+100 added−34 removed
modified:docs/user/advanced.rst+1 added-1 removed
32 unmodified lines33 34 with requests.session(auth=auth, headers=headers) as c:35 36 # 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'})38 39 40 .. admonition:: Global Settings41 96 unmodified linesmodified:requests/config.py+1 added
59 unmodified lines60 settings.accept_gzip = True61 settings.proxies = None62 settings.verbose = None63 settings.timeout = None64+settings.max_redirects = 3065 66 #: Use socket.setdefaulttimeout() as fallback?67 settings.timeout_fallback = Truemodified:requests/core.py+2 added-2 removed
10 unmodified lines11 12 """13 14 __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 linesmodified:requests/exceptions.py+3 added
19 unmodified lines20 """A valid URL is required to make a request."""21 22 class InvalidMethod(RequestException):23 """An inappropriate method was attempted."""24+25+class TooManyRedirects(RequestException):26+ """Too many redirects."""modified:requests/models.py+34 added-21 removed
19 unmodified lines20 from .structures import CaseInsensitiveDict21 from .packages.poster.encode import multipart_encode22 from .packages.poster.streaminghttp import register_openers, get_handlers23 from .utils import dict_from_cookiejar24-from .exceptions import RequestException, AuthenticationError, Timeout, URLRequired, InvalidMethod24+from .exceptions import RequestException, AuthenticationError, Timeout, URLRequired, InvalidMethod, TooManyRedirects25+from .status_codes import codes26 27 27-REDIRECT_STATI = (301, 302, 303, 307)28+REDIRECT_STATI = (codes.moved, codes.found, codes.other, codes.temporary_moved)29 30 31+32 class Request(object):33 """The :class:`Request <models.Request>` object. It carries out all functionality of34 Requests. Recommended interface is with the Requests functions.35 """36 35- _METHODS = ('GET', 'HEAD', 'PUT', 'POST', 'DELETE', 'PATCH')36-37 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 lines115 def __repr__(self):116 return '<Request [%s]>' % (self.method)117 118 119- def __setattr__(self, name, value):120- if (name == 'method') and (value):121- if not value in self._METHODS:122- raise InvalidMethod()123-124- object.__setattr__(self, name, value)125-126-119 def _checks(self):120 """Deterministic checks for consistency."""121 122 if not self.url:52 unmodified lines175 176 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.close181 182 if self.cookiejar:183 184 response.cookies = dict_from_cookiejar(self.cookiejar)18 unmodified lines203 204 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 ):210 211+ r.close()212+213+ if not len(history) < settings.max_redirects:214+ raise TooManyRedirects()215+216 history.append(r)217 218 url = r.headers['location']219 220+ # 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)224+225 # 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)))229 230 # 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 lines272 273 def _build_url(self):274 """Build the actual URL to use."""275 272- # 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 ]))283 284 if self._enc_params:285 if urlparse(self.url).query:286 return '%s&%s' % (self.url, self._enc_params)145 unmodified lines432 self._content = zlib.decompress(self._content, 16+zlib.MAX_WBITS)433 except zlib.error:434 pass435 return self._content436+ else:437+ raise AttributeError438 430-439 def raise_for_status(self):440 """Raises stored :class:`HTTPError` or :class:`URLError`, if one occured."""441 if self.error:442 raise self.error443 444 445+ 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()449+450 class AuthManager(object):451 """Requests Authentication Manager."""452 453 def __new__(cls):170 unmodified linesmodified:requests/status_codes.py+4 added-4 removed
20 unmodified lines21 208: ('im_used',),22 23 # 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 lines35 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 lines61 450: ('blocked_by_windows_parental_controls', 'parental_controls'),62 499: ('client_closed_request',),63 64 # 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 linesmodified:AUTHORS+4 added
33 unmodified lines34 - Jeremy Selier35 - Jens Diemer36 - Alex <@alopatin>37 - Tom Hogans <tomhsx@gmail.com>38+- Armin Ronacher39+- Shrikant Sharat Kandula40+- Mikko Ohtamaa41+- Den Shabalinadded:AUTHORS.orig+40 added
1+Requests is written and maintained by Kenneth Reitz and2+various contributors:3+4+Development Lead5+````````````````6+7+- Kenneth Reitz <me@kennethreitz.com>8+9+10+Patches and Suggestions11+```````````````````````12+13+- 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+>>>>>>> 0ed641a26ec2200de00e4bbf3d170c767375351emodified:HISTORY.rst+11 added
1 History2 -------3 4 5+0.6.1 (2011-08-20)6+++++++++++++++++++7+8+* 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+* Bugfixes14+15+16 0.6.0 (2011-08-17)17 ++++++++++++++++++18 19 * New callback hook system142 unmodified linesmodified:README.rst-6 removed
98 unmodified lines99 100 If 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_.101 102 103-104-Roadmap105--------106-107-- Sphinx Documentation108-103 .. _`the repository`: http://github.com/kennethreitz/requests104 .. _AUTHORS: http://github.com/kennethreitz/requests/blob/master/AUTHORS