Skip to content

Commit a7a81f0

Browse files
committed
update bundled requests to v2.13.0
1 parent 82b6b6e commit a7a81f0

52 files changed

Lines changed: 13556 additions & 1079 deletions

Some content is hidden

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

redminelib/packages/requests/__init__.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,16 @@
3636
The other HTTP methods are supported - see `requests.api`. Full documentation
3737
is at <http://python-requests.org>.
3838
39-
:copyright: (c) 2015 by Kenneth Reitz.
39+
:copyright: (c) 2016 by Kenneth Reitz.
4040
:license: Apache 2.0, see LICENSE for more details.
41-
4241
"""
4342

4443
__title__ = 'requests'
45-
__version__ = '2.9.1'
46-
__build__ = 0x020901
44+
__version__ = '2.13.0'
45+
__build__ = 0x021300
4746
__author__ = 'Kenneth Reitz'
4847
__license__ = 'Apache 2.0'
49-
__copyright__ = 'Copyright 2015 Kenneth Reitz'
48+
__copyright__ = 'Copyright 2016 Kenneth Reitz'
5049

5150
# Attempt to enable urllib3's SNI support, if possible
5251
try:
@@ -55,6 +54,12 @@
5554
except ImportError:
5655
pass
5756

57+
import warnings
58+
59+
# urllib3's DependencyWarnings should be silenced.
60+
from .packages.urllib3.exceptions import DependencyWarning
61+
warnings.simplefilter('ignore', DependencyWarning)
62+
5863
from . import utils
5964
from .models import Request, Response, PreparedRequest
6065
from .api import request, get, head, post, patch, put, delete, options
@@ -63,7 +68,7 @@
6368
from .exceptions import (
6469
RequestException, Timeout, URLRequired,
6570
TooManyRedirects, HTTPError, ConnectionError,
66-
FileModeWarning,
71+
FileModeWarning, ConnectTimeout, ReadTimeout
6772
)
6873

6974
# Set default logging handler to avoid "No handler found" warnings.
@@ -77,7 +82,5 @@ def emit(self, record):
7782

7883
logging.getLogger(__name__).addHandler(NullHandler())
7984

80-
import warnings
81-
8285
# FileModeWarnings go off per the default.
8386
warnings.simplefilter('default', FileModeWarning, append=True)
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# -*- coding: utf-8 -*-
2+
3+
"""
4+
requests._internal_utils
5+
~~~~~~~~~~~~~~
6+
7+
Provides utility functions that are consumed internally by Requests
8+
which depend on extremely few external helpers (such as compat)
9+
"""
10+
11+
from .compat import is_py2, builtin_str, str
12+
13+
14+
def to_native_string(string, encoding='ascii'):
15+
"""Given a string object, regardless of type, returns a representation of
16+
that string in the native string type, encoding and decoding where
17+
necessary. This assumes ASCII unless told otherwise.
18+
"""
19+
if isinstance(string, builtin_str):
20+
out = string
21+
else:
22+
if is_py2:
23+
out = string.encode(encoding)
24+
else:
25+
out = string.decode(encoding)
26+
27+
return out
28+
29+
30+
def unicode_is_ascii(u_string):
31+
"""Determine if unicode string only contains ASCII characters.
32+
33+
:param str u_string: unicode string to check. Must be unicode
34+
and not Python 2 `str`.
35+
:rtype: bool
36+
"""
37+
assert isinstance(u_string, str)
38+
try:
39+
u_string.encode('ascii')
40+
return True
41+
except UnicodeEncodeError:
42+
return False

redminelib/packages/requests/adapters.py

Lines changed: 63 additions & 13 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)
22+
select_proxy, to_native_string)
2323
from .structures import CaseInsensitiveDict
2424
from .packages.urllib3.exceptions import ClosedPoolError
2525
from .packages.urllib3.exceptions import ConnectTimeoutError
@@ -33,9 +33,15 @@
3333
from .packages.urllib3.exceptions import ResponseError
3434
from .cookies import extract_cookies_to_jar
3535
from .exceptions import (ConnectionError, ConnectTimeout, ReadTimeout, SSLError,
36-
ProxyError, RetryError)
36+
ProxyError, RetryError, InvalidSchema)
3737
from .auth import _basic_auth_str
3838

39+
try:
40+
from .packages.urllib3.contrib.socks import SOCKSProxyManager
41+
except ImportError:
42+
def SOCKSProxyManager(*args, **kwargs):
43+
raise InvalidSchema("Missing dependencies for SOCKS support.")
44+
3945
DEFAULT_POOLBLOCK = False
4046
DEFAULT_POOLSIZE = 10
4147
DEFAULT_RETRIES = 0
@@ -48,10 +54,24 @@ class BaseAdapter(object):
4854
def __init__(self):
4955
super(BaseAdapter, self).__init__()
5056

51-
def send(self):
57+
def send(self, request, stream=False, timeout=None, verify=True,
58+
cert=None, proxies=None):
59+
"""Sends PreparedRequest object. Returns Response object.
60+
61+
:param request: The :class:`PreparedRequest <PreparedRequest>` being sent.
62+
:param stream: (optional) Whether to stream the request content.
63+
:param timeout: (optional) How long to wait for the server to send
64+
data before giving up, as a float, or a :ref:`(connect timeout,
65+
read timeout) <timeouts>` tuple.
66+
:type timeout: float or tuple
67+
:param verify: (optional) Whether to verify SSL certificates.
68+
:param cert: (optional) Any user-provided SSL certificate to be trusted.
69+
:param proxies: (optional) The proxies dictionary to apply to the request.
70+
"""
5271
raise NotImplementedError
5372

5473
def close(self):
74+
"""Cleans up adapter specific items."""
5575
raise NotImplementedError
5676

5777

@@ -65,7 +85,7 @@ class HTTPAdapter(BaseAdapter):
6585
6686
:param pool_connections: The number of urllib3 connection pools to cache.
6787
:param pool_maxsize: The maximum number of connections to save in the pool.
68-
:param int max_retries: The maximum number of retries each connection
88+
:param max_retries: The maximum number of retries each connection
6989
should attempt. Note, this applies only to failed DNS lookups, socket
7090
connections and connection timeouts, never to requests where data has
7191
made it to the server. By default, Requests does not retry failed
@@ -148,18 +168,32 @@ def proxy_manager_for(self, proxy, **proxy_kwargs):
148168
:param proxy: The proxy to return a urllib3 ProxyManager for.
149169
:param proxy_kwargs: Extra keyword arguments used to configure the Proxy Manager.
150170
:returns: ProxyManager
171+
:rtype: requests.packages.urllib3.ProxyManager
151172
"""
152-
if not proxy in self.proxy_manager:
173+
if proxy in self.proxy_manager:
174+
manager = self.proxy_manager[proxy]
175+
elif proxy.lower().startswith('socks'):
176+
username, password = get_auth_from_url(proxy)
177+
manager = self.proxy_manager[proxy] = SOCKSProxyManager(
178+
proxy,
179+
username=username,
180+
password=password,
181+
num_pools=self._pool_connections,
182+
maxsize=self._pool_maxsize,
183+
block=self._pool_block,
184+
**proxy_kwargs
185+
)
186+
else:
153187
proxy_headers = self.proxy_headers(proxy)
154-
self.proxy_manager[proxy] = proxy_from_url(
188+
manager = self.proxy_manager[proxy] = proxy_from_url(
155189
proxy,
156190
proxy_headers=proxy_headers,
157191
num_pools=self._pool_connections,
158192
maxsize=self._pool_maxsize,
159193
block=self._pool_block,
160194
**proxy_kwargs)
161195

162-
return self.proxy_manager[proxy]
196+
return manager
163197

164198
def cert_verify(self, conn, url, verify, cert):
165199
"""Verify a SSL certificate. This method should not be called from user
@@ -211,6 +245,7 @@ def build_response(self, req, resp):
211245
212246
:param req: The :class:`PreparedRequest <PreparedRequest>` used to generate the response.
213247
:param resp: The urllib3 response object.
248+
:rtype: requests.Response
214249
"""
215250
response = Response()
216251

@@ -246,6 +281,7 @@ def get_connection(self, url, proxies=None):
246281
247282
:param url: The URL to connect to.
248283
:param proxies: (optional) A Requests-style dictionary of proxies used on this request.
284+
:rtype: requests.packages.urllib3.ConnectionPool
249285
"""
250286
proxy = select_proxy(url, proxies)
251287

@@ -264,10 +300,12 @@ def get_connection(self, url, proxies=None):
264300
def close(self):
265301
"""Disposes of any internal state.
266302
267-
Currently, this just closes the PoolManager, which closes pooled
268-
connections.
303+
Currently, this closes the PoolManager and any active ProxyManager,
304+
which closes any pooled connections.
269305
"""
270306
self.poolmanager.clear()
307+
for proxy in self.proxy_manager.values():
308+
proxy.clear()
271309

272310
def request_url(self, request, proxies):
273311
"""Obtain the url to use when making the final request.
@@ -281,13 +319,20 @@ def request_url(self, request, proxies):
281319
282320
:param request: The :class:`PreparedRequest <PreparedRequest>` being sent.
283321
:param proxies: A dictionary of schemes or schemes and hosts to proxy URLs.
322+
:rtype: str
284323
"""
285324
proxy = select_proxy(request.url, proxies)
286325
scheme = urlparse(request.url).scheme
287-
if proxy and scheme != 'https':
326+
327+
is_proxied_http_request = (proxy and scheme != 'https')
328+
using_socks_proxy = False
329+
if proxy:
330+
proxy_scheme = urlparse(proxy).scheme.lower()
331+
using_socks_proxy = proxy_scheme.startswith('socks')
332+
333+
url = request.path_url
334+
if is_proxied_http_request and not using_socks_proxy:
288335
url = urldefragauth(request.url)
289-
else:
290-
url = request.path_url
291336

292337
return url
293338

@@ -316,11 +361,12 @@ def proxy_headers(self, proxy):
316361
:class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.
317362
318363
:param proxies: The url of the proxy being used for this request.
364+
:rtype: dict
319365
"""
320366
headers = {}
321367
username, password = get_auth_from_url(proxy)
322368

323-
if username and password:
369+
if username:
324370
headers['Proxy-Authorization'] = _basic_auth_str(username,
325371
password)
326372

@@ -338,6 +384,7 @@ def send(self, request, stream=False, timeout=None, verify=True, cert=None, prox
338384
:param verify: (optional) Whether to verify SSL certificates.
339385
:param cert: (optional) Any user-provided SSL certificate to be trusted.
340386
:param proxies: (optional) The proxies dictionary to apply to the request.
387+
:rtype: requests.Response
341388
"""
342389

343390
conn = self.get_connection(request.url, proxies)
@@ -434,6 +481,9 @@ def send(self, request, stream=False, timeout=None, verify=True, cert=None, prox
434481
if isinstance(e.reason, ResponseError):
435482
raise RetryError(e, request=request)
436483

484+
if isinstance(e.reason, _ProxyError):
485+
raise ProxyError(e, request=request)
486+
437487
raise ConnectionError(e, request=request)
438488

439489
except ClosedPoolError as e:

redminelib/packages/requests/api.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
99
:copyright: (c) 2012 by Kenneth Reitz.
1010
:license: Apache2, see LICENSE for more details.
11-
1211
"""
1312

1413
from . import sessions
@@ -24,13 +23,17 @@ def request(method, url, **kwargs):
2423
:param json: (optional) json data to send in the body of the :class:`Request`.
2524
:param headers: (optional) Dictionary of HTTP Headers to send with the :class:`Request`.
2625
:param cookies: (optional) Dict or CookieJar object to send with the :class:`Request`.
27-
:param files: (optional) Dictionary of ``'name': file-like-objects`` (or ``{'name': ('filename', fileobj)}``) for multipart encoding upload.
26+
:param files: (optional) Dictionary of ``'name': file-like-objects`` (or ``{'name': file-tuple}``) for multipart encoding upload.
27+
``file-tuple`` can be a 2-tuple ``('filename', fileobj)``, 3-tuple ``('filename', fileobj, 'content_type')``
28+
or a 4-tuple ``('filename', fileobj, 'content_type', custom_headers)``, where ``'content-type'`` is a string
29+
defining the content type of the given file and ``custom_headers`` a dict-like object containing additional headers
30+
to add for the file.
2831
:param auth: (optional) Auth tuple to enable Basic/Digest/Custom HTTP Auth.
2932
:param timeout: (optional) How long to wait for the server to send data
3033
before giving up, as a float, or a :ref:`(connect timeout, read
3134
timeout) <timeouts>` tuple.
3235
:type timeout: float or tuple
33-
:param allow_redirects: (optional) Boolean. Set to True if POST/PUT/DELETE redirect following is allowed.
36+
:param allow_redirects: (optional) Boolean. Enable/disable GET/OPTIONS/POST/PUT/PATCH/DELETE/HEAD redirection. Defaults to ``True``.
3437
:type allow_redirects: bool
3538
:param proxies: (optional) Dictionary mapping protocol to the URL of the proxy.
3639
:param verify: (optional) whether the SSL cert will be verified. A CA_BUNDLE path can also be provided. Defaults to ``True``.
@@ -112,6 +115,7 @@ def put(url, data=None, **kwargs):
112115
113116
:param url: URL for the new :class:`Request` object.
114117
:param data: (optional) Dictionary, bytes, or file-like object to send in the body of the :class:`Request`.
118+
:param json: (optional) json data to send in the body of the :class:`Request`.
115119
:param \*\*kwargs: Optional arguments that ``request`` takes.
116120
:return: :class:`Response <Response>` object
117121
:rtype: requests.Response
@@ -125,6 +129,7 @@ def patch(url, data=None, **kwargs):
125129
126130
:param url: URL for the new :class:`Request` object.
127131
:param data: (optional) Dictionary, bytes, or file-like object to send in the body of the :class:`Request`.
132+
:param json: (optional) json data to send in the body of the :class:`Request`.
128133
:param \*\*kwargs: Optional arguments that ``request`` takes.
129134
:return: :class:`Response <Response>` object
130135
:rtype: requests.Response

0 commit comments

Comments
 (0)