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 d1dfa02, 10eed63 · Browse files · 20 files·+82 added−41 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
20 files+82 added−41 removed
- other:+82 added−41 removed
Provenance
- Commit
8c1fd5d- Tree
d77c694- Author
Kenneth Reitz <me@kennethreitz.com>- Committer
Kenneth Reitz <me@kennethreitz.com>- Parent 1
d1dfa02- Parent 2
10eed63
20 files changed+82 added−41 removed
modified:docs/_themes/README.rst+1 added-1 removed
1 krTheme Sphinx Style2 ====================3 4 This repository contains sphinx styles Kenneth Reitz uses in most of 5-his projects. It is a drivative of Mitsuhiko's themes for Flask and Flask related5+his projects. It is a derivative of Mitsuhiko's themes for Flask and Flask related6 projects. To use this style in your Sphinx documentation, follow7 this guide:8 9 1. put this folder as _themes into your docs folder. Alternatively16 unmodified linesmodified:docs/user/advanced.rst+8 added-6 removed
8 unmodified lines9 Session Objects10 ---------------11 12 The Session object allows you to persist certain parameters across13-requests. It also perstists cookies across all requests made from the13+requests. It also persists cookies across all requests made from the14 Session instance.15 16 A session object has all the methods of the main Requests API.17 30 unmodified lines48 49 Body Content Workflow50 ----------------------51 52-By default, When you make a request, the body of the response isn't downloaded immediately. The response headers are downloaded when you make a request, but the content isn't downloaded until you access the :class:`Response.content` attribute.52+By default, when you make a request, the body of the response isn't downloaded immediately. The response headers are downloaded when you make a request, but the content isn't downloaded until you access the :class:`Response.content` attribute.53 54 Let's walk through it::55 56 tarball_url = 'https://github.com/kennethreitz/requests/tarball/master'22 unmodified lines79 ----------80 81 Excellent news — thanks to urllib3, keep-alive is 100% automatic within a session! Any requests that you make within a session will automatically reuse the appropriate connection!82 83+Note that connections are only released back to the pool for reuse once all body data has been read; be sure to either set ``prefetch`` to ``True`` or read the ``content`` property of the ``Response`` object.84+85 If you'd like to disable keep-alive, you can simply set the ``keep_alive`` configuration to ``False``::86 87 s = requests.session()88 s.config['keep_alive'] = False1 unmodified line90 91 Asynchronous Requests92 ----------------------93 92-Requests has first-class support for concurrent requests, powered93-by gevent. This allows you to send a bunch of HTTP requests at the same94+Requests has first-class support for concurrent requests, powered by gevent.95+This allows you to send a bunch of HTTP requests at the same time.96 97 First, let's import the async module. Heads up — if you don't have98 `gevent <http://pypi.python.org/pypi/gevent>`_ this will fail::99 23 unmodified lines123 [<Response [200]>, <Response [200]>, <Response [200]>, <Response [200]>]124 125 .. admonition:: Throttling126 125- The ``map`` function also takes a ``size`` parameter, that specifies the nubmer of connections to make at a time::127+ The ``map`` function also takes a ``size`` parameter, that specifies the number of connections to make at a time::128 129 async.map(rs, size=5)130 131 98 unmodified lines230 """Attaches HTTP Pizza Authentication to the given Request object."""231 def __init__(self, username):232 # setup any auth-related data here233 self.username = username232- 234+235 def __call__(self, r):236 # modify and return the request237 r.headers['X-Pizza'] = self.username238 return r19 unmodified linesmodified:docs/user/quickstart.rst+4 added-4 removed
298 unmodified lines299 300 Redirection and History301 -----------------------302 303-Requests will automatically perform location redirection while using impodotent methods.303+Requests will automatically perform location redirection while using idempotent methods.304 305 GitHub redirects all HTTP requests to HTTPS. Let's see what happens::306 307 >>> r = requests.get('http://github.com')7 unmodified lines315 The :class:`Response.history` list contains a list of the316 :class:`Request` objects that were created in order to complete the request.317 318 If you're using GET, HEAD, or OPTIONS, you can disable redirection319-handling with the ``disable_redirects`` parameter::319+handling with the ``allow_redirects`` parameter::320 321- >>> r = requests.get('http://github.com')321+ >>> r = requests.get('http://github.com', allow_redirects=False)322 >>> r.status_code323 301324 >>> r.history325 []18 unmodified lines344 requests.exceptions.Timeout: Request timed out.345 346 .. admonition:: Note347 348- ``timeout`` only effects the connection process itself, not the downloading of the respone body.348+ ``timeout`` only effects the connection process itself, not the downloading of the response body.349 350 351 Errors and Exceptions352 ---------------------17 unmodified linesmodified:docs/index.rst+1 added-1 removed
36 unmodified lines37 `The Washington Post <http://www.washingtonpost.com/>`_,38 `Twitter, Inc <http://twitter.com>`_,39 `Readability <http://readability.com>`_, and40 Federal US Institutions41-use Requests internally. It has been installed over 45,000 times from PyPi.41+use Requests internally. It has been installed over 45,000 times from PyPI.42 43 **Armin Ronacher**44 Requests is the perfect example how beautiful an API can be with the45 right level of abstraction.86 unmodified linesmodified:requests/__init__.py+3 added-2 removed
13 unmodified lines14 15 """16 17 __title__ = 'requests'18-__version__ = '0.8.3'19-__build__ = 0x00080318+__version__ = '0.8.4'19+__build__ = 0x00080420 __author__ = 'Kenneth Reitz'21 __license__ = 'ISC'22 __copyright__ = 'Copyright 2011 Kenneth Reitz'23 24 25+26 from . import utils27 from .models import Request, Response28 from .api import request, get, head, post, patch, put, delete, options29 from .sessions import session, Session5 unmodified linesmodified:requests/api.py+1 added-1 removed
37 unmodified lines38 :param data: (optional) Dictionary or bytes to send in the body of the :class:`Request`.39 :param headers: (optional) Dictionary of HTTP Headers to send with the :class:`Request`.40 :param cookies: (optional) Dict or CookieJar object to send with the :class:`Request`.41 :param files: (optional) Dictionary of 'name': file-like-objects (or {'name': ('filename', fileobj)}) for multipart encoding upload.42- :param auth: (optional) Auth typle to enable Basic/Digest/Custom HTTP Auth.42+ :param auth: (optional) Auth tuple to enable Basic/Digest/Custom HTTP Auth.43 :param timeout: (optional) Float describing the timeout of the request.44 :param allow_redirects: (optional) Boolean. Set to True if POST/PUT/DELETE redirect following is allowed.45 :param proxies: (optional) Dictionary mapping protocol to the URL of the proxy.46 :param return_response: (optional) If False, an un-sent Request object will returned.99 unmodified linesmodified:requests/defaults.py+1 added-1 removed
9 unmodified lines10 11 :base_headers: Default HTTP headers.12 :verbose: Stream to write request logging to.13 :timeout: Seconds until request timeout.14-:max_redirects: Maximum njumber of redirects allowed within a request.14+:max_redirects: Maximum number of redirects allowed within a request.15 :decode_unicode: Decode unicode responses automatically?16 :keep_alive: Reuse HTTP Connections?17 :max_retries: The number of times a request should be retried in the event of a connection failure.18 :safe_mode: If true, Requests will catch all errors.24 unmodified linesmodified:requests/exceptions.py+2 added-2 removed
11 unmodified lines12 """There was an ambiguous exception that occurred while handling your13 request."""14 15 class HTTPError(RequestException):16- """An HTTP error occured."""16+ """An HTTP error occurred."""17 18 class ConnectionError(RequestException):19- """A Connection error occured."""19+ """A Connection error occurred."""20 21 class Timeout(RequestException):22 """The request timed out."""23 5 unmodified linesmodified:requests/models.py+6 added-4 removed
149 unmodified lines150 response.config = self.config151 152 if resp:153 154- # Fallback to None if there's no staus_code, for whatever reason.154+ # Fallback to None if there's no status_code, for whatever reason.155 response.status_code = getattr(resp, 'status', None)156 157 # Make headers case-insensitive.158 response.headers = CaseInsensitiveDict(getattr(resp, 'headers', None))11 unmodified lines170 171 # Save cookies in Response.172 response.cookies = cookies173 174- # Save original resopnse for later.174+ # Save original response for later.175 response.raw = resp176 177 if is_error:178 response.error = resp261 unmodified lines440 body=body,441 headers=self.headers,442 redirect=False,443 assert_same_host=False,444- preload_content=prefetch,444+ preload_content=False,445 decode_content=False,446 retries=self.config.get('max_retries', 0),447 timeout=self.timeout,448 )449+ self.sent = True450 451 452 except MaxRetryError, e:453 if not self.config.get('safe_mode', False):15 unmodified lines469 self.__dict__.update(r.__dict__)470 471 # If prefetch is True, mark content as consumed.472 if prefetch:472- self.response._content_consumed = True473+ # Save the response.474+ self.response.content475 476 return self.sent477 478 159 unmodified linesmodified:requests/sessions.py+1 added-1 removed
121 unmodified lines122 :param data: (optional) Dictionary or bytes to send in the body of the :class:`Request`.123 :param headers: (optional) Dictionary of HTTP Headers to send with the :class:`Request`.124 :param cookies: (optional) Dict or CookieJar object to send with the :class:`Request`.125 :param files: (optional) Dictionary of 'filename': file-like-objects for multipart encoding upload.126- :param auth: (optional) Auth typle to enable Basic/Digest/Custom HTTP Auth.126+ :param auth: (optional) Auth tuple to enable Basic/Digest/Custom HTTP Auth.127 :param timeout: (optional) Float describing the timeout of the request.128 :param allow_redirects: (optional) Boolean. Set to True if POST/PUT/DELETE redirect following is allowed.129 :param proxies: (optional) Dictionary mapping protocol to the URL of the proxy.130 :param return_response: (optional) If False, an un-sent Request object will returned.149 unmodified linesmodified:requests/utils.py+2 added-2 removed
2 unmodified lines3 """4 requests.utils5 ~~~~~~~~~~~~~~6 7-This module provides utlity functions that are used within Requests7+This module provides utility functions that are used within Requests8 that are also useful for external consumption.9 10 """11 361 unmodified lines373 def requote_path(path):374 """Re-quote the given URL path component.375 376 This function passes the given path through an unquote/quote cycle to377- ensure that it is fully and consistenty quoted.377+ ensure that it is fully and consistently quoted.378 """379 parts = path.split("/")380 parts = (urllib.quote(urllib.unquote(part), safe="") for part in parts)381 return "/".join(parts)modified:.gitignore-1 removed
1-.idea1 MANIFEST2 coverage.xml3 nosetests.xml4 pylint.txt5 unmodified linesmodified:AUTHORS.rst+3 added-1 removed
60 unmodified lines61 - Juan Riaza62 - Ryan Kelly63 - Rolando Espinoza La fuente64 - Robert Gieseke65-- Idan Gazit65+- Idan Gazit66+- Ed Summers67+- Chris Van Hornemodified:HISTORY.rst+6 added
1 History2 -------3 4+0.8.4 (2011-12-11)5+++++++++++++++++++6+7+* Prefetch bugfix.8+* Added license to installed version.9+10 0.8.3 (2011-11-27)11 ++++++++++++++++++12 13 * Converted auth system to use simpler callable objects.269 unmodified linesmodified:Makefile+1 added-1 removed
1 init:2 pip install -r reqs.txt3 4 test:5- nosetests test_requests.py5+ nosetests --with-color test_requests.py6 7 ci: init8 nosetests test_requests.py --with-xunit --xunit-file=junit-report.xml9 7 unmodified linesmodified:MANIFEST.in+1 added-1 removed
1-include README.rst LICENSE HISTORY.rst test_requests.py1+include README.rst LICENSE NOTICE HISTORY.rst test_requests.pymodified:NOTICE+20 added-6 removed
1 Request includes some vendorized python libraries to ease installation.2 3-Poster License4-==============3+Urllib3 License4+===============5 6-Copyright (c) 2010 Chris AtLee6+This is the MIT license: http://www.opensource.org/licenses/mit-license.php7 8-Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:8+Copyright 2008-2011 Andrey Petrov and contributors (see CONTRIBUTORS.txt),9+Modifications copyright 2022 Kenneth Reitz.10 10-The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.11+Permission is hereby granted, free of charge, to any person obtaining a copy of this12+software and associated documentation files (the "Software"), to deal in the Software13+without restriction, including without limitation the rights to use, copy, modify, merge,14+publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons15+to whom the Software is furnished to do so, subject to the following conditions:16 12-THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.17+The above copyright notice and this permission notice shall be included in all copies or18+substantial portions of the Software.19+20+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,21+INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR22+PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE23+FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR24+OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER25+DEALINGS IN THE SOFTWARE.26+modified:reqs.txt+1 added-1 removed
2 unmodified lines3 gunicorn4 nose5 pyflakes6 omnijson7-rudolf7+rudolf2modified:setup.py+7 added-5 removed
10 unmodified lines11 from distutils.core import setup12 13 14 15-if sys.argv[-1] == "publish":16- os.system("python setup.py sdist upload")15+if sys.argv[-1] == 'publish':16+ os.system('python setup.py sdist upload')17 sys.exit()18 19-if sys.argv[-1] == "test":20- os.system("python test_requests.py")19+if sys.argv[-1] == 'test':20+ os.system('python test_requests.py')21 sys.exit()22 23 required = []24 8 unmodified lines33 open('HISTORY.rst').read(),34 author='Kenneth Reitz',35 author_email='me@kennethreitz.com',36 url='http://python-requests.org',37- packages= [37+ packages=[38 'requests',39 'requests.packages',40 'requests.packages.urllib3',41 'requests.packages.oreos'42 ],43+ package_data={'': ['LICENSE', 'NOTICE']},44+ include_package_data=True,45 install_requires=required,46 license='ISC',47 classifiers=(48 'Development Status :: 5 - Production/Stable',11 unmodified linesmodified:test_requests.py+13 added
79 unmodified lines80 def test_HTTP_200_OK_GET(self):81 r = requests.get(httpbin('/get'))82 self.assertEqual(r.status_code, 200)83 84+ def test_response_sent(self):85+ r = requests.get(httpbin('/get'))86+87+ self.assertTrue(r.request.sent)88+89 def test_HTTP_302_ALLOW_REDIRECT_GET(self):90 r = requests.get(httpbin('redirect', '1'))91 self.assertEqual(r.status_code, 200)92 488 unmodified lines581 config = {'safe_mode': True}582 r = requests.get(hah, allow_redirects=False, config=config)583 assert r.content == None584 585+ def test_cached_response(self):586 587+ r1 = requests.get(httpbin('get'), prefetch=False)588+ assert r1.content589+ assert r1.content590+591+ r2 = requests.get(httpbin('get'), prefetch=True)592+ assert r2.content593+594 if __name__ == '__main__':595 unittest.main()