Skip to content

Commit 78bb675

Browse files
committed
update bundled requests to v2.15.1
1 parent 54a2304 commit 78bb675

74 files changed

Lines changed: 6167 additions & 4962 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CHANGELOG.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ Changelog
5353
attributes on ``Resource`` object to allow more fine-grained resource setup
5454
- ``return_raw`` parameter on ``engine.request()`` and ``engine.process_response()`` methods has been removed
5555
in favor of ``return_raw_response`` attribute on engine object
56+
- Updated bundled requests library to v2.15.1
5657

5758
**Bugfixes**:
5859

redminelib/packages/requests/__init__.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# /
77

88
"""
9-
Requests HTTP library
9+
Requests HTTP Library
1010
~~~~~~~~~~~~~~~~~~~~~
1111
1212
Requests is an HTTP library, written in Python, for human beings. Basic GET
@@ -36,16 +36,13 @@
3636
The other HTTP methods are supported - see `requests.api`. Full documentation
3737
is at <http://python-requests.org>.
3838
39-
:copyright: (c) 2016 by Kenneth Reitz.
39+
:copyright: (c) 2017 by Kenneth Reitz.
4040
:license: Apache 2.0, see LICENSE for more details.
4141
"""
4242

43-
__title__ = 'requests'
44-
__version__ = '2.13.0'
45-
__build__ = 0x021300
46-
__author__ = 'Kenneth Reitz'
47-
__license__ = 'Apache 2.0'
48-
__copyright__ = 'Copyright 2016 Kenneth Reitz'
43+
from .__version__ import __title__, __description__, __url__, __version__
44+
from .__version__ import __build__, __author__, __author_email__, __license__
45+
from .__version__ import __copyright__, __cake__
4946

5047
# Attempt to enable urllib3's SNI support, if possible
5148
try:
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# -*- coding: utf-8 -*-
2+
3+
# .-. .-. .-. . . .-. .-. .-. .-.
4+
# |( |- |.| | | |- `-. | `-.
5+
# ' ' `-' `-`.`-' `-' `-' ' `-'
6+
7+
__title__ = 'requests'
8+
__description__ = 'Python HTTP for Humans.'
9+
__url__ = 'http://python-requests.org'
10+
__version__ = '2.15.1'
11+
__build__ = 0x021501
12+
__author__ = 'Kenneth Reitz'
13+
__author_email__ = 'me@kennethreitz.org'
14+
__license__ = 'Apache 2.0'
15+
__copyright__ = 'Copyright 2017 Kenneth Reitz'
16+
__cake__ = u'✨ 🍰 ✨'

redminelib/packages/requests/adapters.py

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from .compat import urlparse, basestring
2020
from .utils import (DEFAULT_CA_BUNDLE_PATH, get_encoding_from_headers,
2121
prepend_scheme_if_needed, get_auth_from_url, urldefragauth,
22-
select_proxy, to_native_string)
22+
select_proxy)
2323
from .structures import CaseInsensitiveDict
2424
from .packages.urllib3.exceptions import ClosedPoolError
2525
from .packages.urllib3.exceptions import ConnectTimeoutError
@@ -64,7 +64,9 @@ def send(self, request, stream=False, timeout=None, verify=True,
6464
data before giving up, as a float, or a :ref:`(connect timeout,
6565
read timeout) <timeouts>` tuple.
6666
:type timeout: float or tuple
67-
:param verify: (optional) Whether to verify SSL certificates.
67+
:param verify: (optional) Either a boolean, in which case it controls whether we verify
68+
the server's TLS certificate, or a string, in which case it must be a path
69+
to a CA bundle to use
6870
:param cert: (optional) Any user-provided SSL certificate to be trusted.
6971
:param proxies: (optional) The proxies dictionary to apply to the request.
7072
"""
@@ -202,7 +204,9 @@ def cert_verify(self, conn, url, verify, cert):
202204
203205
:param conn: The urllib3 connection object associated with the cert.
204206
:param url: The requested URL.
205-
:param verify: Whether we should actually verify the certificate.
207+
:param verify: Either a boolean, in which case it controls whether we verify
208+
the server's TLS certificate, or a string, in which case it must be a path
209+
to a CA bundle to use
206210
:param cert: The SSL certificate to verify.
207211
"""
208212
if url.lower().startswith('https') and verify:
@@ -216,8 +220,9 @@ def cert_verify(self, conn, url, verify, cert):
216220
if not cert_loc:
217221
cert_loc = DEFAULT_CA_BUNDLE_PATH
218222

219-
if not cert_loc:
220-
raise Exception("Could not find a suitable SSL CA certificate bundle.")
223+
if not cert_loc or not os.path.exists(cert_loc):
224+
raise IOError("Could not find a suitable TLS CA certificate bundle, "
225+
"invalid path: {0}".format(cert_loc))
221226

222227
conn.cert_reqs = 'CERT_REQUIRED'
223228

@@ -236,6 +241,13 @@ def cert_verify(self, conn, url, verify, cert):
236241
conn.key_file = cert[1]
237242
else:
238243
conn.cert_file = cert
244+
conn.key_file = None
245+
if conn.cert_file and not os.path.exists(conn.cert_file):
246+
raise IOError("Could not find the TLS certificate file, "
247+
"invalid path: {0}".format(conn.cert_file))
248+
if conn.key_file and not os.path.exists(conn.key_file):
249+
raise IOError("Could not find the TLS key file, "
250+
"invalid path: {0}".format(conn.key_file))
239251

240252
def build_response(self, req, resp):
241253
"""Builds a :class:`Response <requests.Response>` object from a urllib3
@@ -380,8 +392,10 @@ def send(self, request, stream=False, timeout=None, verify=True, cert=None, prox
380392
:param timeout: (optional) How long to wait for the server to send
381393
data before giving up, as a float, or a :ref:`(connect timeout,
382394
read timeout) <timeouts>` tuple.
383-
:type timeout: float or tuple
384-
:param verify: (optional) Whether to verify SSL certificates.
395+
:type timeout: float or tuple or urllib3 Timeout object
396+
:param verify: (optional) Either a boolean, in which case it controls whether
397+
we verify the server's TLS certificate, or a string, in which case it
398+
must be a path to a CA bundle to use
385399
:param cert: (optional) Any user-provided SSL certificate to be trusted.
386400
:param proxies: (optional) The proxies dictionary to apply to the request.
387401
:rtype: requests.Response
@@ -405,6 +419,8 @@ def send(self, request, stream=False, timeout=None, verify=True, cert=None, prox
405419
"timeout tuple, or a single float to set "
406420
"both timeouts to the same value".format(timeout))
407421
raise ValueError(err)
422+
elif isinstance(timeout, TimeoutSauce):
423+
pass
408424
else:
409425
timeout = TimeoutSauce(connect=timeout, read=timeout)
410426

redminelib/packages/requests/api.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def request(method, url, **kwargs):
1919
:param method: method for the new :class:`Request` object.
2020
:param url: URL for the new :class:`Request` object.
2121
:param params: (optional) Dictionary or bytes to be sent in the query string for the :class:`Request`.
22-
:param data: (optional) Dictionary, bytes, or file-like object to send in the body of the :class:`Request`.
22+
:param data: (optional) Dictionary or list of tuples ``[(key, value)]`` (will be form-encoded), bytes, or file-like object to send in the body of the :class:`Request`.
2323
:param json: (optional) json data to send in the body of the :class:`Request`.
2424
:param headers: (optional) Dictionary of HTTP Headers to send with the :class:`Request`.
2525
:param cookies: (optional) Dict or CookieJar object to send with the :class:`Request`.
@@ -29,14 +29,16 @@ def request(method, url, **kwargs):
2929
defining the content type of the given file and ``custom_headers`` a dict-like object containing additional headers
3030
to add for the file.
3131
:param auth: (optional) Auth tuple to enable Basic/Digest/Custom HTTP Auth.
32-
:param timeout: (optional) How long to wait for the server to send data
32+
:param timeout: (optional) How many seconds to wait for the server to send data
3333
before giving up, as a float, or a :ref:`(connect timeout, read
3434
timeout) <timeouts>` tuple.
3535
:type timeout: float or tuple
3636
:param allow_redirects: (optional) Boolean. Enable/disable GET/OPTIONS/POST/PUT/PATCH/DELETE/HEAD redirection. Defaults to ``True``.
3737
:type allow_redirects: bool
3838
:param proxies: (optional) Dictionary mapping protocol to the URL of the proxy.
39-
:param verify: (optional) whether the SSL cert will be verified. A CA_BUNDLE path can also be provided. Defaults to ``True``.
39+
:param verify: (optional) Either a boolean, in which case it controls whether we verify
40+
the server's TLS certificate, or a string, in which case it must be a path
41+
to a CA bundle to use. Defaults to ``True``.
4042
:param stream: (optional) if ``False``, the response content will be immediately downloaded.
4143
:param cert: (optional) if String, path to ssl client cert file (.pem). If Tuple, ('cert', 'key') pair.
4244
:return: :class:`Response <Response>` object
@@ -57,7 +59,7 @@ def request(method, url, **kwargs):
5759

5860

5961
def get(url, params=None, **kwargs):
60-
"""Sends a GET request.
62+
r"""Sends a GET request.
6163
6264
:param url: URL for the new :class:`Request` object.
6365
:param params: (optional) Dictionary or bytes to be sent in the query string for the :class:`Request`.
@@ -71,7 +73,7 @@ def get(url, params=None, **kwargs):
7173

7274

7375
def options(url, **kwargs):
74-
"""Sends a OPTIONS request.
76+
r"""Sends a OPTIONS request.
7577
7678
:param url: URL for the new :class:`Request` object.
7779
:param \*\*kwargs: Optional arguments that ``request`` takes.
@@ -84,7 +86,7 @@ def options(url, **kwargs):
8486

8587

8688
def head(url, **kwargs):
87-
"""Sends a HEAD request.
89+
r"""Sends a HEAD request.
8890
8991
:param url: URL for the new :class:`Request` object.
9092
:param \*\*kwargs: Optional arguments that ``request`` takes.
@@ -97,10 +99,10 @@ def head(url, **kwargs):
9799

98100

99101
def post(url, data=None, json=None, **kwargs):
100-
"""Sends a POST request.
102+
r"""Sends a POST request.
101103
102104
:param url: URL for the new :class:`Request` object.
103-
:param data: (optional) Dictionary, bytes, or file-like object to send in the body of the :class:`Request`.
105+
:param data: (optional) Dictionary (will be form-encoded), bytes, or file-like object to send in the body of the :class:`Request`.
104106
:param json: (optional) json data to send in the body of the :class:`Request`.
105107
:param \*\*kwargs: Optional arguments that ``request`` takes.
106108
:return: :class:`Response <Response>` object
@@ -111,10 +113,10 @@ def post(url, data=None, json=None, **kwargs):
111113

112114

113115
def put(url, data=None, **kwargs):
114-
"""Sends a PUT request.
116+
r"""Sends a PUT request.
115117
116118
:param url: URL for the new :class:`Request` object.
117-
:param data: (optional) Dictionary, bytes, or file-like object to send in the body of the :class:`Request`.
119+
:param data: (optional) Dictionary (will be form-encoded), bytes, or file-like object to send in the body of the :class:`Request`.
118120
:param json: (optional) json data to send in the body of the :class:`Request`.
119121
:param \*\*kwargs: Optional arguments that ``request`` takes.
120122
:return: :class:`Response <Response>` object
@@ -125,10 +127,10 @@ def put(url, data=None, **kwargs):
125127

126128

127129
def patch(url, data=None, **kwargs):
128-
"""Sends a PATCH request.
130+
r"""Sends a PATCH request.
129131
130132
:param url: URL for the new :class:`Request` object.
131-
:param data: (optional) Dictionary, bytes, or file-like object to send in the body of the :class:`Request`.
133+
:param data: (optional) Dictionary (will be form-encoded), bytes, or file-like object to send in the body of the :class:`Request`.
132134
:param json: (optional) json data to send in the body of the :class:`Request`.
133135
:param \*\*kwargs: Optional arguments that ``request`` takes.
134136
:return: :class:`Response <Response>` object
@@ -139,7 +141,7 @@ def patch(url, data=None, **kwargs):
139141

140142

141143
def delete(url, **kwargs):
142-
"""Sends a DELETE request.
144+
r"""Sends a DELETE request.
143145
144146
:param url: URL for the new :class:`Request` object.
145147
:param \*\*kwargs: Optional arguments that ``request`` takes.

redminelib/packages/requests/auth.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
from .cookies import extract_cookies_to_jar
2121
from ._internal_utils import to_native_string
2222
from .utils import parse_dict_header
23-
from .status_codes import codes
2423

2524
CONTENT_TYPE_FORM_URLENCODED = 'application/x-www-form-urlencoded'
2625
CONTENT_TYPE_MULTI_PART = 'multipart/form-data'
@@ -227,6 +226,12 @@ def handle_401(self, r, **kwargs):
227226
:rtype: requests.Response
228227
"""
229228

229+
# If response is not 4xx, do not auth
230+
# See https://github.com/kennethreitz/requests/issues/3772
231+
if not 400 <= r.status_code < 500:
232+
self._thread_local.num_401_calls = 1
233+
return r
234+
230235
if self._thread_local.pos is not None:
231236
# Rewind the file position indicator of the body to where
232237
# it was to resend the request.

0 commit comments

Comments
 (0)