Skip to content
Myr

Merge branch 'master' of github.com:kennethreitz/requests

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 3857431, 4ad4670 · Browse files · 17 files+49 added−75 removed
This commit

State

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

Diff stats

17 files+49 added−75 removed

  • tests:+5 added−5 removed
  • other:+44 added−70 removed

17 files+49 added−75 removed

modified:docs/_templates/sidebarintro.html+2 added-2 removed
modified:docs/community/support.rst+1 added-1 removed
24 unmodified lines
25-------------2627If you notice some unexpected behaviour in Requests, or want to see support28for a new feature,29`file an issue on GitHub <https://github.com/kennethreitz/requests/issues>`_.29`file an issue on GitHub <https://github.com/requests/requests/issues>`_.303132E-mail33------
18 unmodified lines
modified:docs/community/updates.rst+1 added-1 removed
10 unmodified lines
11GitHub12------1314The best way to track the development of Requests is through15`the GitHub repo <https://github.com/kennethreitz/requests>`_.15`the GitHub repo <https://github.com/requests/requests>`_.1617Twitter18-------19
11 unmodified lines
modified:docs/dev/contributing.rst+1 added-1 removed
185 unmodified lines
186through the `GitHub issues`_, **both open and closed**, to confirm that the bug187hasn't been reported before. Duplicate bug reports are a huge drain on the time188of other contributors, and should be avoided as much as possible.189190.. _GitHub issues: https://github.com/kennethreitz/requests/issues190.. _GitHub issues: https://github.com/requests/requests/issues191192193Feature Requests194----------------
12 unmodified lines
modified:docs/dev/todo.rst+2 added-2 removed
4 unmodified lines
56#. Check for open issues or open a fresh issue to start a discussion around a bug.7 There is a Contributor Friendly tag for issues that should be ideal for people who are not very8 familiar with the codebase yet.9#. Fork `the repository <https://github.com/kennethreitz/requests>`_ on GitHub and start making your9#. Fork `the repository <https://github.com/requests/requests>`_ on GitHub and start making your10 changes to a new branch.11#. Write a test which shows that the bug was fixed.12#. Send a pull request and bug the maintainer until it gets merged and published. :)13 Make sure to add yourself to `AUTHORS <https://github.com/kennethreitz/requests/blob/master/AUTHORS.rst>`_.13 Make sure to add yourself to `AUTHORS <https://github.com/requests/requests/blob/master/AUTHORS.rst>`_.1415Feature Freeze16--------------17
54 unmodified lines
modified:docs/user/advanced.rst+6 added-6 removed
278 unmodified lines
279immediately. You can override this behaviour and defer downloading the response280body until you access the :attr:`Response.content <requests.Response.content>`281attribute with the ``stream`` parameter::282283 tarball_url = 'https://github.com/kennethreitz/requests/tarball/master'283 tarball_url = 'https://github.com/requests/requests/tarball/master'284 r = requests.get(tarball_url, stream=True)285286At this point only the response headers have been downloaded and the connection287remains open, hence allowing us to make content retrieval conditional::
353 unmodified lines
641from GitHub. Suppose we wanted commit ``a050faf`` on Requests. We would get it642like so::643644 >>> import requests645 >>> r = requests.get('https://api.github.com/repos/kennethreitz/requests/git/commits/a050faf084662f3a352dd1a941f2c7c9f886d4ad')645 >>> r = requests.get('https://api.github.com/repos/requests/requests/git/commits/a050faf084662f3a352dd1a941f2c7c9f886d4ad')646647We should confirm that GitHub responded correctly. If it has, we want to work648out what type of content it is. Do this like so::649
46 unmodified lines
696we should probably avoid making ham-handed POSTS to it. Instead, let's play697with the Issues feature of GitHub.698699This documentation was added in response to700`Issue #482 <https://github.com/kennethreitz/requests/issues/482>`_. Given that700`Issue #482 <https://github.com/requests/requests/issues/482>`_. Given that701this issue already exists, we will use it as an example. Let's start by getting it.702703::704705 >>> r = requests.get('https://api.github.com/repos/kennethreitz/requests/issues/482')705 >>> r = requests.get('https://api.github.com/repos/requests/requests/issues/482')706 >>> r.status_code707 200708709 >>> issue = json.loads(r.text)
34 unmodified lines
744745::746747 >>> body = json.dumps({u"body": u"Sounds great! I'll get right on it!"})748 >>> url = u"https://api.github.com/repos/kennethreitz/requests/issues/482/comments"748 >>> url = u"https://api.github.com/repos/requests/requests/issues/482/comments"749750 >>> r = requests.post(url=url, data=body)751 >>> r.status_code752 404
25 unmodified lines
778 >>> print(content[u"id"])779 5804413780781 >>> body = json.dumps({u"body": u"Sounds great! I'll get right on it once I feed my cat."})782 >>> url = u"https://api.github.com/repos/kennethreitz/requests/issues/comments/5804413"782 >>> url = u"https://api.github.com/repos/requests/requests/issues/comments/5804413"783784 >>> r = requests.patch(url=url, data=body, auth=auth)785 >>> r.status_code786 200
206 unmodified lines
modified:docs/user/install.rst+1 added-1 removed
20 unmodified lines
21Get the Source Code22-------------------2324Requests is actively developed on GitHub, where the code is25`always available <https://github.com/kennethreitz/requests>`_.25`always available <https://github.com/requests/requests>`_.2627You can either clone the public repository::2829 $ git clone git://github.com/requests/requests.git
10 unmodified lines
modified:docs/index.rst+4 added-4 removed
15 unmodified lines
1617.. image:: https://img.shields.io/pypi/pyversions/requests.svg18 :target: https://pypi.python.org/pypi/requests1920.. image:: https://travis-ci.org/kennethreitz/requests.svg?branch=master21 :target: https://travis-ci.org/kennethreitz/requests20.. image:: https://travis-ci.org/requests/requests.svg?branch=master21 :target: https://travis-ci.org/requests/requests2223.. image:: https://codecov.io/github/kennethreitz/requests/coverage.svg?branch=master24 :target: https://codecov.io/github/kennethreitz/requests23.. image:: https://codecov.io/github/requests/requests/coverage.svg?branch=master24 :target: https://codecov.io/github/requests/requests25 :alt: codecov.io2627.. image:: https://img.shields.io/badge/Say%20Thanks!-🦉-1EAEDB.svg28 :target: https://saythanks.io/to/kennethreitz
146 unmodified lines
modified:requests/auth.py+1 added-1 removed
225 unmodified lines
226 :rtype: requests.Response227 """228229 # If response is not 4xx, do not auth230 # See https://github.com/kennethreitz/requests/issues/3772230 # See https://github.com/requests/requests/issues/3772231 if not 400 <= r.status_code < 500:232 self._thread_local.num_401_calls = 1233 return r234
59 unmodified lines
modified:requests/models.py+2 added-2 removed
11 unmodified lines
12import sys1314# Import encoding now, to avoid implicit import later.15# Implicit import within threads may cause LookupError when standard library is in a ZIP,16# such as in Embedded Python. See https://github.com/kennethreitz/requests/issues/3578.16# such as in Embedded Python. See https://github.com/requests/requests/issues/3578.17import encodings.idna1819from urllib3.fields import RequestField20from urllib3.filepost import encode_multipart_formdata
326 unmodified lines
347 #: Accept objects that have string representations.348 #: We're unable to blindly call unicode/str functions349 #: as this will include the bytestring indicator (b'')350 #: on python 3.x.351 #: https://github.com/kennethreitz/requests/pull/2238351 #: https://github.com/requests/requests/pull/2238352 if isinstance(url, bytes):353 url = url.decode('utf8')354 else:355 url = unicode(url) if is_py2 else str(url)
587 unmodified lines
modified:requests/sessions.py+2 added-28 removed
11 unmodified lines
12import time13from collections import Mapping14from datetime import timedelta1516from urllib3._collections import RecentlyUsedContainer1716from .auth import _basic_auth_str17from .compat import cookielib, is_py3, OrderedDict, urljoin, urlparse18from .cookies import (19 cookiejar_from_dict, extract_cookies_to_jar, RequestsCookieJar, merge_cookies)
16 unmodified lines
3637# formerly defined here, reexposed here for backward compatibility38from .models import REDIRECT_STATI3942REDIRECT_CACHE_SIZE = 10004340# Preferred clock, based on which one is more accurate on a given system.41if platform.system() == 'Windows':42 try: # Python 3.3+43 preferred_clock = time.perf_counter
109 unmodified lines
153 else:154 url = requote_uri(url)155156 prepared_request.url = to_native_string(url)161 # Cache the url, unless it redirects to itself.162 if resp.is_permanent_redirect and req.url != prepared_request.url:163 self.redirect_cache[req.url] = prepared_request.url157158 self.rebuild_method(prepared_request, resp)159167 # https://github.com/kennethreitz/requests/issues/1084160 # https://github.com/requests/requests/issues/1084161 if resp.status_code not in (codes.temporary_redirect, codes.permanent_redirect):169 # https://github.com/kennethreitz/requests/issues/3490162 # https://github.com/requests/requests/issues/3490163 purged_headers = ('Content-Length', 'Content-Type', 'Transfer-Encoding')164 for header in purged_headers:165 prepared_request.headers.pop(header, None)166 prepared_request.body = None
218 unmodified lines
385 self.adapters = OrderedDict()386 self.mount('https://', HTTPAdapter())387 self.mount('http://', HTTPAdapter())388396 # Only store 1000 redirects to prevent using infinite memory397 self.redirect_cache = RecentlyUsedContainer(REDIRECT_CACHE_SIZE)398389 def __enter__(self):390 return self391392 def __exit__(self, *args):
219 unmodified lines
612 allow_redirects = kwargs.pop('allow_redirects', True)613 stream = kwargs.get('stream')614 hooks = request.hooks615626 # Resolve URL in redirect cache, if available.627 if allow_redirects:628 checked_urls = set()629 while request.url in self.redirect_cache:630 checked_urls.add(request.url)631 new_url = self.redirect_cache.get(request.url)632 if new_url in checked_urls:633 break634 request.url = new_url635616 # Get the appropriate adapter to use617 adapter = self.get_adapter(url=request.url)618619 # Start time (approximately) of the request
104 unmodified lines
724 self.adapters[key] = self.adapters.pop(key)725726 def __getstate__(self):727 state = dict((attr, getattr(self, attr, None)) for attr in self.__attrs__)748 state['redirect_cache'] = dict(self.redirect_cache)728 return state729730 def __setstate__(self, state):752 redirect_cache = state.pop('redirect_cache', {})731 for attr, value in state.items():732 setattr(self, attr, value)733756 self.redirect_cache = RecentlyUsedContainer(REDIRECT_CACHE_SIZE)757 for redirect, to in redirect_cache.items():758 self.redirect_cache[redirect] = to734760735def session():736 """737 Returns a :class:`Session` for context-management.738
4 unmodified lines
modified:requests/utils.py+1 added-1 removed
169 unmodified lines
170 loc = os.path.expanduser('~/{0}'.format(f))171 except KeyError:172 # os.path.expanduser can fail when $HOME is undefined and173 # getpwuid fails. See http://bugs.python.org/issue20164 &174 # https://github.com/kennethreitz/requests/issues/1846174 # https://github.com/requests/requests/issues/1846175 return176177 if os.path.exists(loc):178 netrc_path = loc
725 unmodified lines
modified:tests/test_lowlevel.py+2 added-2 removed
26 unmodified lines
27def test_digestauth_401_count_reset_on_redirect():28 """Ensure we correctly reset num_401_calls after a successful digest auth,29 followed by a 302 redirect to another digest auth prompt.3031 See https://github.com/kennethreitz/requests/issues/1979.31 See https://github.com/requests/requests/issues/1979.32 """33 text_401 = (b'HTTP/1.1 401 UNAUTHORIZED\r\n'34 b'Content-Length: 0\r\n'35 b'WWW-Authenticate: Digest nonce="6bf5d6e4da1ce66918800195d6b9130d"'
101 unmodified lines
137138def test_digestauth_only_on_4xx():139 """Ensure we only send digestauth on 4xx challenges.140141 See https://github.com/kennethreitz/requests/issues/3772.141 See https://github.com/requests/requests/issues/3772.142 """143 text_200_chal = (b'HTTP/1.1 200 OK\r\n'144 b'Content-Length: 0\r\n'145 b'WWW-Authenticate: Digest nonce="6bf5d6e4da1ce66918800195d6b9130d"'
92 unmodified lines
modified:tests/test_requests.py+2 added-2 removed
453 unmodified lines
454455 @pytest.mark.parametrize('key', ('User-agent', 'user-agent'))456 def test_user_agent_transfers(self, httpbin, key):457458 heads = {key: 'Mozilla/5.0 (github.com/kennethreitz/requests)'}458 heads = {key: 'Mozilla/5.0 (github.com/requests/requests)'}459460 r = requests.get(httpbin('user-agent'), headers=heads)461 assert heads[key] in r.text462
1611 unmodified lines
2074 except ConnectTimeout:2075 pass20762077 def test_encoded_methods(self, httpbin):2078 """See: https://github.com/kennethreitz/requests/issues/2316"""2078 """See: https://github.com/requests/requests/issues/2316"""2079 r = requests.request(b'GET', httpbin('get'))2080 assert r.ok20812082
290 unmodified lines
modified:tests/test_utils.py+1 added-1 removed
365 unmodified lines
366 'http://example.com/fiz?buz=%25ppicture',367 ),368 ))369def test_requote_uri_with_unquoted_percents(uri, expected):370 """See: https://github.com/kennethreitz/requests/issues/2356"""370 """See: https://github.com/requests/requests/issues/2356"""371 assert requote_uri(uri) == expected372373374@pytest.mark.parametrize(
280 unmodified lines
modified:HISTORY.rst+8 added-8 removed
598 unmodified lines
599**Bugfixes**600601- Unicode URL improvements for Python 2.602- Re-order JSON param for backwards compat.603- Automatically defrag authentication schemes from host/pass URIs. (`#2249 <https://github.com/kennethreitz/requests/issues/2249>`_)603- Automatically defrag authentication schemes from host/pass URIs. (`#2249 <https://github.com/requests/requests/issues/2249>`_)6046056062.4.2 (2014-10-05)607++++++++++++++++++608609**Improvements**610611- FINALLY! Add json parameter for uploads! (`#2258 <https://github.com/kennethreitz/requests/pull/2258>`_)612- Support for bytestring URLs on Python 3.x (`#2238 <https://github.com/kennethreitz/requests/pull/2238>`_)611- FINALLY! Add json parameter for uploads! (`#2258 <https://github.com/requests/requests/pull/2258>`_)612- Support for bytestring URLs on Python 3.x (`#2238 <https://github.com/requests/requests/pull/2238>`_)613614**Bugfixes**615616- Avoid getting stuck in a loop (`#2244 <https://github.com/kennethreitz/requests/pull/2244>`_)617- Multiple calls to iter* fail with unhelpful error. (`#2240 <https://github.com/kennethreitz/requests/issues/2240>`_, `#2241 <https://github.com/kennethreitz/requests/issues/2241>`_)616- Avoid getting stuck in a loop (`#2244 <https://github.com/requests/requests/pull/2244>`_)617- Multiple calls to iter* fail with unhelpful error. (`#2240 <https://github.com/requests/requests/issues/2240>`_, `#2241 <https://github.com/requests/requests/issues/2241>`_)618619**Documentation**620621- Correct redirection introduction (`#2245 <https://github.com/kennethreitz/requests/pull/2245/>`_)622- Added example of how to send multiple files in one request. (`#2227 <https://github.com/kennethreitz/requests/pull/2227/>`_)623- Clarify how to pass a custom set of CAs (`#2248 <https://github.com/kennethreitz/requests/pull/2248/>`_)621- Correct redirection introduction (`#2245 <https://github.com/requests/requests/pull/2245/>`_)622- Added example of how to send multiple files in one request. (`#2227 <https://github.com/requests/requests/pull/2227/>`_)623- Clarify how to pass a custom set of CAs (`#2248 <https://github.com/requests/requests/pull/2248/>`_)6246256266272.4.1 (2014-09-09)
819 unmodified lines
modified:README.rst+12 added-12 removed
8 unmodified lines
910.. image:: https://img.shields.io/pypi/pyversions/requests.svg11 :target: https://pypi.python.org/pypi/requests1213.. image:: https://travis-ci.org/kennethreitz/requests.svg?branch=master14 :target: https://travis-ci.org/kennethreitz/requests13.. image:: https://travis-ci.org/requests/requests.svg?branch=master14 :target: https://travis-ci.org/requests/requests1516.. image:: https://codecov.io/github/kennethreitz/requests/coverage.svg?branch=master17 :target: https://codecov.io/github/kennethreitz/requests16.. image:: https://codecov.io/github/requests/requests/coverage.svg?branch=master17 :target: https://codecov.io/github/requests/requests18 :alt: codecov.io19 20.. image:: https://img.shields.io/github/contributors/kennethreitz/requests.svg21 :target: https://github.com/kennethreitz/requests/graphs/contributors22 1920.. image:: https://img.shields.io/github/contributors/requests/requests.svg21 :target: https://github.com/requests/requests/graphs/contributors2223.. image:: https://img.shields.io/badge/Say%20Thanks-!-1EAEDB.svg24 :target: https://saythanks.io/to/kennethreitz2526
22 unmodified lines
49 {u'disk_usage': 368627, u'private_gists': 484, ...}5051See `the similar code, sans Requests <https://gist.github.com/973705>`_.5253.. image:: https://raw.githubusercontent.com/kennethreitz/requests/master/docs/_static/requests-logo-small.png53.. image:: https://raw.githubusercontent.com/requests/requests/master/docs/_static/requests-logo-small.png54 :target: http://docs.python-requests.org/555657Requests allows you to send *organic, grass-fed* HTTP/1.1 requests, without the
53 unmodified lines
111#. Fork `the repository`_ on GitHub to start making your changes to the **master** branch (or branch off of it).112#. Write a test which shows that the bug was fixed or that the feature works as expected.113#. Send a pull request and bug the maintainer until it gets merged and published. :) Make sure to add yourself to AUTHORS_.114115.. _`the repository`: http://github.com/kennethreitz/requests116.. _AUTHORS: https://github.com/kennethreitz/requests/blob/master/AUTHORS.rst117.. _Contributor Friendly: https://github.com/kennethreitz/requests/issues?direction=desc&labels=Contributor+Friendly&page=1&sort=updated&state=open115.. _`the repository`: http://github.com/requests/requests116.. _AUTHORS: https://github.com/requests/requests/blob/master/AUTHORS.rst117.. _Contributor Friendly: https://github.com/requests/requests/issues?direction=desc&labels=Contributor+Friendly&page=1&sort=updated&state=open