Skip to content
Myr

Merge remote-tracking branch 'upstream/master'

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

authored by mlcrazy · committed by mlcrazy · parents edcc894, b3d138e · Browse files · 9 files+57 added−30 removed
This commit

State

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

Diff stats

9 files+57 added−30 removed

  • tests:+6 added−0 removed
  • other:+51 added−30 removed

9 files+57 added−30 removed

modified:docs/user/advanced.rst+2 added-6 removed
299 unmodified lines
300release the connection back to the pool unless you consume all the data or call301:meth:`Response.close <requests.Response.close>`. This can lead to302inefficiency with connections. If you find yourself partially reading request303bodies (or not reading them at all) while using ``stream=True``, you should304consider using ``contextlib.closing`` (`documented here`_), like this::304make the request within a ``with`` statement to ensure it's always closed::305306 from contextlib import closing307308 with closing(requests.get('http://httpbin.org/get', stream=True)) as r:306 with requests.get('http://httpbin.org/get', stream=True) as r:307 # Do things with the response here.308311.. _`documented here`: http://docs.python.org/2/library/contextlib.html#contextlib.closing312309.. _keep-alive:310311Keep-Alive312----------
676 unmodified lines
modified:requests/__init__.py+30 added-22 removed
38 unmodified lines
39:copyright: (c) 2017 by Kenneth Reitz.40:license: Apache 2.0, see LICENSE for more details.41"""4243# Check urllib3 for compatibility.43import urllib345urllib3_version = urllib3.__version__.split('.')46# Sometimes, urllib3 only reports its version as 16.1.47if len(urllib3_version) == 2:48 urllib3_version.append('0')49major, minor, patch = urllib3_version50major, minor, patch = int(major), int(minor), int(patch)51# urllib3 >= 1.21.1, < 1.2252try:44import chardet45import warnings46from .exceptions import RequestsDependencyWarning474849def check_compatibility(urllib3_version, chardet_version):50 urllib3_version = urllib3_version.split('.')51 assert urllib3_version != ['dev'] # Verify urllib3 isn't installed from git.5253 # Sometimes, urllib3 only reports its version as 16.1.54 if len(urllib3_version) == 2:55 urllib3_version.append('0')5657 # Check urllib3 for compatibility.58 major, minor, patch = urllib3_version # noqa: F81159 major, minor, patch = int(major), int(minor), int(patch)60 # urllib3 >= 1.21.1, < 1.2261 assert major == 162 assert minor >= 2163 assert minor <= 2256except AssertionError:57 raise RuntimeError('Requests dependency \'urllib3\' must be version >= 1.21.1, < 1.22!')645960# Check chardet for compatibility.61import chardet62major, minor, patch = chardet.__version__.split('.')[:3]63major, minor, patch = int(major), int(minor), int(patch)64# chardet >= 3.0.2, < 3.1.065 # Check chardet for compatibility.66 major, minor, patch = chardet_version.split('.')[:3]67 major, minor, patch = int(major), int(minor), int(patch)68 # chardet >= 3.0.2, < 3.1.065try:69 assert major == 370 assert minor < 171 assert patch >= 269except AssertionError:70 raise RuntimeError('Requests dependency \'chardet\' must be version >= 3.0.2, < 3.1.0!')727374# Check imported dependencies for compatibility.75try:76 check_compatibility(urllib3.__version__, chardet.__version__)77except (AssertionError, ValueError):78 warnings.warn("urllib3 ({0}) or chardet ({1}) doesn't match a supported "79 "version!".format(urllib3.__version__, chardet.__version__),80 RequestsDependencyWarning)8182# Attempt to enable urllib3's SNI support, if possible83try:84 from urllib3.contrib import pyopenssl85 pyopenssl.inject_into_urllib3()86except ImportError:87 pass8879import warnings8089# urllib3's DependencyWarnings should be silenced.90from urllib3.exceptions import DependencyWarning91warnings.simplefilter('ignore', DependencyWarning)92
29 unmodified lines
modified:requests/api.py+1 added-1 removed
71 unmodified lines
72 return request('get', url, params=params, **kwargs)737475def options(url, **kwargs):76 r"""Sends a OPTIONS request.76 r"""Sends an OPTIONS request.7778 :param url: URL for the new :class:`Request` object.79 :param \*\*kwargs: Optional arguments that ``request`` takes.80 :return: :class:`Response <Response>` object
72 unmodified lines
modified:requests/exceptions.py+5 added
113 unmodified lines
114115class FileModeWarning(RequestsWarning, DeprecationWarning):116 """A file was opened in text mode, but Requests determined its binary length."""117 pass118119120class RequestsDependencyWarning(RequestsWarning):121 """An imported dependency doesn't match the expected version range."""122 pass
modified:requests/models.py+6 added
632 unmodified lines
633 #: The :class:`PreparedRequest <PreparedRequest>` object to which this634 #: is a response.635 self.request = None636637 def __enter__(self):638 return self639640 def __exit__(self, *args):641 self.close()642643 def __getstate__(self):644 # Consume everything; accessing the content attribute makes645 # sure the content has been fully read.646 if not self._content_consumed:
304 unmodified lines
modified:tests/test_requests.py+6 added
1666 unmodified lines
1667 it = r.iter_lines()1668 next(it)1669 assert len(list(it)) == 316701671 def test_response_context_manager(self, httpbin):1672 with requests.get(httpbin('stream/4'), stream=True) as response:1673 assert isinstance(response, requests.Response)16741675 assert response.raw.closed16761677 def test_unconsumed_session_response_closes_connection(self, httpbin):1678 s = requests.session()16791680 with contextlib.closing(s.get(httpbin('stream/4'), stream=True)) as response:
698 unmodified lines
modified:.gitignore+1 added
3 unmodified lines
4nosetests.xml5junit-report.xml6pylint.txt7toy.py8.cache/9cover/10build/11docs/_build12requests.egg-info/
11 unmodified lines
modified:HISTORY.rst+5 added
4 unmodified lines
56dev7+++89**Improvements**1011- ``Response`` is now a context manager, so can be used directly in a `with` statement12 without first having to be wrapped by ``contextlib.closing()``.1314**Bugfixes**1516- Resolve installation failure if multiprocessing is not available17- Resolve tests crash if multiprocessing is not able to determine the number of CPU cores
1467 unmodified lines
modified:Makefile+1 added-1 removed
6 unmodified lines
7ci:8 py.test -n 8 --boxed --junitxml=report.xml910test-readme:11 python setup.py check -r -s11 @python setup.py check --restructuredtext --strict && ([ $$? -eq 0 ] && echo "README.rst and HISTORY.rst ok") || echo "Invalid markup in README.rst or HISTORY.rst!"1213flake8:14 flake8 --ignore=E501,F401,E128,E402,E731,F821 requests15
12 unmodified lines