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 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

20 files+82 added−41 removed

modified:docs/_themes/README.rst+1 added-1 removed
1krTheme Sphinx Style2====================34This repository contains sphinx styles Kenneth Reitz uses in most of 5his projects. It is a drivative of Mitsuhiko's themes for Flask and Flask related5his projects. It is a derivative of Mitsuhiko's themes for Flask and Flask related6projects. To use this style in your Sphinx documentation, follow7this guide:891. put this folder as _themes into your docs folder. Alternatively
16 unmodified lines
modified:docs/user/advanced.rst+8 added-6 removed
8 unmodified lines
9Session Objects10---------------1112The Session object allows you to persist certain parameters across13requests. It also perstists cookies across all requests made from the13requests. It also persists cookies across all requests made from the14Session instance.1516A session object has all the methods of the main Requests API.17
30 unmodified lines
4849Body Content Workflow50----------------------5152By 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.52By 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.5354Let's walk through it::5556 tarball_url = 'https://github.com/kennethreitz/requests/tarball/master'
22 unmodified lines
79----------8081Excellent 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!8283Note 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.8485If you'd like to disable keep-alive, you can simply set the ``keep_alive`` configuration to ``False``::8687 s = requests.session()88 s.config['keep_alive'] = False
1 unmodified line
9091Asynchronous Requests92----------------------9392Requests has first-class support for concurrent requests, powered93by gevent. This allows you to send a bunch of HTTP requests at the same94Requests has first-class support for concurrent requests, powered by gevent.95This allows you to send a bunch of HTTP requests at the same time.9697First, 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 lines
123 [<Response [200]>, <Response [200]>, <Response [200]>, <Response [200]>]124125.. admonition:: Throttling126125 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::128129 async.map(rs, size=5)130131
98 unmodified lines
230 """Attaches HTTP Pizza Authentication to the given Request object."""231 def __init__(self, username):232 # setup any auth-related data here233 self.username = username232 234235 def __call__(self, r):236 # modify and return the request237 r.headers['X-Pizza'] = self.username238 return r
19 unmodified lines
modified:docs/user/quickstart.rst+4 added-4 removed
298 unmodified lines
299300Redirection and History301-----------------------302303Requests will automatically perform location redirection while using impodotent methods.303Requests will automatically perform location redirection while using idempotent methods.304305GitHub redirects all HTTP requests to HTTPS. Let's see what happens::306307 >>> r = requests.get('http://github.com')
7 unmodified lines
315The :class:`Response.history` list contains a list of the316:class:`Request` objects that were created in order to complete the request.317318If you're using GET, HEAD, or OPTIONS, you can disable redirection319handling with the ``disable_redirects`` parameter::319handling with the ``allow_redirects`` parameter::320321 >>> 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 lines
344 requests.exceptions.Timeout: Request timed out.345346.. admonition:: Note347348 ``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.349350351Errors and Exceptions352---------------------
17 unmodified lines
modified:docs/index.rst+1 added-1 removed
36 unmodified lines
37`The Washington Post <http://www.washingtonpost.com/>`_,38`Twitter, Inc <http://twitter.com>`_,39`Readability <http://readability.com>`_, and40Federal US Institutions41use Requests internally. It has been installed over 45,000 times from PyPi.41use Requests internally. It has been installed over 45,000 times from PyPI.4243**Armin Ronacher**44 Requests is the perfect example how beautiful an API can be with the45 right level of abstraction.
86 unmodified lines
modified:requests/__init__.py+3 added-2 removed
13 unmodified lines
1415"""1617__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'23242526from . import utils27from .models import Request, Response28from .api import request, get, head, post, patch, put, delete, options29from .sessions import session, Session
5 unmodified lines
modified:requests/api.py+1 added-1 removed
37 unmodified lines
38 :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 lines
modified:requests/defaults.py+1 added-1 removed
9 unmodified lines
1011: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 lines
modified:requests/exceptions.py+2 added-2 removed
11 unmodified lines
12 """There was an ambiguous exception that occurred while handling your13 request."""1415class HTTPError(RequestException):16 """An HTTP error occured."""16 """An HTTP error occurred."""1718class ConnectionError(RequestException):19 """A Connection error occured."""19 """A Connection error occurred."""2021class Timeout(RequestException):22 """The request timed out."""23
5 unmodified lines
modified:requests/models.py+6 added-4 removed
149 unmodified lines
150 response.config = self.config151152 if resp:153154 # 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)156157 # Make headers case-insensitive.158 response.headers = CaseInsensitiveDict(getattr(resp, 'headers', None))
11 unmodified lines
170171 # Save cookies in Response.172 response.cookies = cookies173174 # Save original resopnse for later.174 # Save original response for later.175 response.raw = resp176177 if is_error:178 response.error = resp
261 unmodified lines
440 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 = True450451452 except MaxRetryError, e:453 if not self.config.get('safe_mode', False):
15 unmodified lines
469 self.__dict__.update(r.__dict__)470471 # If prefetch is True, mark content as consumed.472 if prefetch:472 self.response._content_consumed = True473 # Save the response.474 self.response.content475476 return self.sent477478
159 unmodified lines
modified:requests/sessions.py+1 added-1 removed
121 unmodified lines
122 :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 lines
modified:requests/utils.py+2 added-2 removed
2 unmodified lines
3"""4requests.utils5~~~~~~~~~~~~~~67This module provides utlity functions that are used within Requests7This module provides utility functions that are used within Requests8that are also useful for external consumption.910"""11
361 unmodified lines
373def requote_path(path):374 """Re-quote the given URL path component.375376 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.idea1MANIFEST2coverage.xml3nosetests.xml4pylint.txt
5 unmodified lines
modified:AUTHORS.rst+3 added-1 removed
60 unmodified lines
61- Juan Riaza62- Ryan Kelly63- Rolando Espinoza La fuente64- Robert Gieseke65- Idan Gazit65- Idan Gazit66- Ed Summers67- Chris Van Horne
modified:HISTORY.rst+6 added
1History2-------340.8.4 (2011-12-11)5++++++++++++++++++67* Prefetch bugfix.8* Added license to installed version.9100.8.3 (2011-11-27)11++++++++++++++++++1213* Converted auth system to use simpler callable objects.
269 unmodified lines
modified:Makefile+1 added-1 removed
1init:2 pip install -r reqs.txt34test:5 nosetests test_requests.py5 nosetests --with-color test_requests.py67ci: init8 nosetests test_requests.py --with-xunit --xunit-file=junit-report.xml9
7 unmodified lines
modified:MANIFEST.in+1 added-1 removed
1include README.rst LICENSE HISTORY.rst test_requests.py1include README.rst LICENSE NOTICE HISTORY.rst test_requests.py
modified:NOTICE+20 added-6 removed
1Request includes some vendorized python libraries to ease installation.23Poster License4==============3Urllib3 License4===============56Copyright (c) 2010 Chris AtLee6This is the MIT license: http://www.opensource.org/licenses/mit-license.php78Permission 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:8Copyright 2008-2011 Andrey Petrov and contributors (see CONTRIBUTORS.txt),9Modifications copyright 2022 Kenneth Reitz.1010The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.11Permission is hereby granted, free of charge, to any person obtaining a copy of this12software and associated documentation files (the "Software"), to deal in the Software13without restriction, including without limitation the rights to use, copy, modify, merge,14publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons15to whom the Software is furnished to do so, subject to the following conditions:1612THE 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.17The above copyright notice and this permission notice shall be included in all copies or18substantial portions of the Software.1920THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,21INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR22PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE23FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR24OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER25DEALINGS IN THE SOFTWARE.26
modified:reqs.txt+1 added-1 removed
2 unmodified lines
3gunicorn4nose5pyflakes6omnijson7rudolf7rudolf2
modified:setup.py+7 added-5 removed
10 unmodified lines
11 from distutils.core import setup12131415if sys.argv[-1] == "publish":16 os.system("python setup.py sdist upload")15if sys.argv[-1] == 'publish':16 os.system('python setup.py sdist upload')17 sys.exit()1819if sys.argv[-1] == "test":20 os.system("python test_requests.py")19if sys.argv[-1] == 'test':20 os.system('python test_requests.py')21 sys.exit()2223required = []24
8 unmodified lines
33 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 lines
modified:test_requests.py+13 added
79 unmodified lines
80 def test_HTTP_200_OK_GET(self):81 r = requests.get(httpbin('/get'))82 self.assertEqual(r.status_code, 200)8384 def test_response_sent(self):85 r = requests.get(httpbin('/get'))8687 self.assertTrue(r.request.sent)8889 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 lines
581 config = {'safe_mode': True}582 r = requests.get(hah, allow_redirects=False, config=config)583 assert r.content == None584585 def test_cached_response(self):586587 r1 = requests.get(httpbin('get'), prefetch=False)588 assert r1.content589 assert r1.content590591 r2 = requests.get(httpbin('get'), prefetch=True)592 assert r2.content593594if __name__ == '__main__':595 unittest.main()