Merge branch 'master' into master
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by David Poole · committed by GitHub · parents 1e46cbb, 24092b1 · Browse files · 7 files·+56 added−25 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
7 files+56 added−25 removed
- tests:+6 added−1 removed
- other:+50 added−24 removed
Provenance
- Commit
efacb9e- Tree
7eb30d5- Author
David Poole <testcluster@gmail.com>- Committer
GitHub <noreply@github.com>- Parent 1
1e46cbb- Parent 2
24092b1
7 files changed+56 added−25 removed
modified:docs/user/quickstart.rst+1 added
279 unmodified lines280 >>> payload = {'some': 'data'}281 282 >>> r = requests.post(url, json=payload)283 284+Note, the ``json`` parameter is ignored if either ``data`` or ``files`` is passed.285 286 POST a Multipart-Encoded File287 -----------------------------288 268 unmodified linesmodified:docs/api.rst+1 added-11 removed
107 unmodified lines108 ------------------109 110 .. autoclass:: requests.codes111 112-::112+.. automodule:: requests.status_codes113 114- >>> requests.codes['temporary_redirect']115- 307114 117- >>> requests.codes.teapot118- 418119-120- >>> requests.codes['\o/']121- 200122-123-124-115 Migrating to 1.x116 ----------------117 118 This section details the main differences between 0.x and 1.x and is meant142 unmodified linesmodified:requests/models.py+2 added-2 removed
684 unmodified lines685 return self.iter_content(128)686 687 @property688 def ok(self):689- """Returns True if :attr:`status_code` is less than 400.689+ """Returns True if :attr:`status_code` is less than 400, False if not.690 691 This attribute checks if the status code of the response is between692 400 and 600 to see if there was a client error or a server error. If693- the status code, is between 200 and 400, this will return True. This693+ the status code is between 200 and 400, this will return True. This694 is **not** a check to see if the response code is ``200 OK``.695 """696 try:697 self.raise_for_status()251 unmodified linesmodified:requests/status_codes.py+33 added-5 removed
1 # -*- coding: utf-8 -*-2 3+"""4+The ``codes`` object defines a mapping from common names for HTTP statuses5+to their numerical codes, accessible either as attributes or as dictionary6+items.7+8+>>> requests.codes['temporary_redirect']9+30710+>>> requests.codes.teapot11+41812+>>> requests.codes['\o/']13+20014+15+Some codes have multiple names, and both upper- and lower-case versions of16+the names are allowed. For example, ``codes.ok``, ``codes.OK``, and17+``codes.okay`` all correspond to the HTTP status code 200.18+"""19+20 from .structures import LookupDict21 22 _codes = {23 76 unmodified lines100 }101 102 codes = LookupDict(name='status_codes')103 104+def _init():87-for code, titles in _codes.items():88- for title in titles:89- setattr(codes, title, code)90- if not title.startswith(('\\', '/')):91- setattr(codes, title.upper(), code)105+ for code, titles in _codes.items():106+ for title in titles:107+ setattr(codes, title, code)108+ if not title.startswith(('\\', '/')):109+ setattr(codes, title.upper(), code)110+111+ def doc(code):112+ names = ', '.join('``%s``' % n for n in _codes[code])113+ return '* %d: %s' % (code, names)114+115+ global __doc__116+ __doc__ = (__doc__ + '\n' +117+ '\n'.join(doc(code) for code in sorted(_codes)))118+119+_init()modified:requests/utils.py+12 added-6 removed
43 unmodified lines44 if sys.platform == 'win32':45 # provide a proxy_bypass version on Windows without DNS lookups46 47 def proxy_bypass_registry(host):48- if is_py3:49- import winreg50- else:51- import _winreg as winreg48 try:49+ if is_py3:50+ import winreg51+ else:52+ import _winreg as winreg53+ except ImportError:54+ return False55+56+ try:57 internetSettings = winreg.OpenKey(winreg.HKEY_CURRENT_USER,58 r'Software\Microsoft\Windows\CurrentVersion\Internet Settings')59+ # ProxyEnable could be REG_SZ or REG_DWORD, normalizing it55- proxyEnable = winreg.QueryValueEx(internetSettings,56- 'ProxyEnable')[0]60+ proxyEnable = int(winreg.QueryValueEx(internetSettings,61+ 'ProxyEnable')[0])62+ # ProxyOverride is almost always a string63 proxyOverride = winreg.QueryValueEx(internetSettings,64 'ProxyOverride')[0]65 except OSError:66 return False882 unmodified linesmodified:tests/test_utils.py+6 added-1 removed
3 unmodified lines4 import copy5 import filecmp6 from io import BytesIO7 import zipfile8+from collections import deque9 10 import pytest11 from requests import compat12 from requests.cookies import RequestsCookieJar653 unmodified lines666 def Close(self):667 pass668 669 ie_settings = RegHandle()670+ proxyEnableValues = deque([1, "1"])671 672 def OpenKey(key, subkey):673 return ie_settings674 675 def QueryValueEx(key, value_name):676 if key is ie_settings:677 if value_name == 'ProxyEnable':676- return [1]678+ # this could be a string (REG_SZ) or a 32-bit number (REG_DWORD)679+ proxyEnableValues.rotate()680+ return [proxyEnableValues[0]]681 elif value_name == 'ProxyOverride':682 return [override]683 684 monkeypatch.setenv('http_proxy', '')2 unmodified lines687 monkeypatch.setenv('no_proxy', '')688 monkeypatch.setenv('NO_PROXY', '')689 monkeypatch.setattr(winreg, 'OpenKey', OpenKey)690 monkeypatch.setattr(winreg, 'QueryValueEx', QueryValueEx)691+ assert should_bypass_proxies(url, None) == expected692 693 694 @pytest.mark.parametrize(695 'env_name, value', (22 unmodified linesmodified:HISTORY.rst+1 added
14 unmodified lines15 16 - Parsing empty ``Link`` headers with ``parse_header_links()`` no longer return one bogus entry17 - Fixed issue where loading the default certificate bundle from a zip archive18 would raise an ``IOError``19+- Fixed issue with unexpected ``ImportError`` on windows system which do not support ``winreg`` module20 21 22 2.18.4 (2017-08-15)23 +++++++++++++++++++1520 unmodified lines