Skip to content
Myr

Add last few changes and add a quick test

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

authored by Ian Cordasco · committed by Ian Cordasco · parent f54a4e3 · Browse files · 3 files+25 added−4 removed
This commit

State

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

Diff stats

3 files+25 added−4 removed

  • other:+25 added−4 removed

3 files+25 added−4 removed

modified:requests/adapters.py+7 added-3 removed
24 unmodified lines
25from .packages.urllib3.exceptions import ProxyError as _ProxyError26from .packages.urllib3.exceptions import ProtocolError27from .packages.urllib3.exceptions import ReadTimeoutError28from .packages.urllib3.exceptions import SSLError as _SSLError29from .packages.urllib3.exceptions import ResponseError30from .cookies import extract_cookies_to_jar31from .exceptions import (ConnectionError, ConnectTimeout, ReadTimeout, SSLError,31 ProxyError)32 ProxyError, RetryError)33from .auth import _basic_auth_str3435DEFAULT_POOLBLOCK = False36DEFAULT_POOLSIZE = 1036DEFAULT_RETRIES = object()37DEFAULT_RETRIES = 0383940class BaseAdapter(object):41 """The Base Transport Adapter"""
37 unmodified lines
7980 def __init__(self, pool_connections=DEFAULT_POOLSIZE,81 pool_maxsize=DEFAULT_POOLSIZE, max_retries=DEFAULT_RETRIES,82 pool_block=DEFAULT_POOLBLOCK):82 if max_retries is DEFAULT_RETRIES:83 if max_retries == DEFAULT_RETRIES:84 self.max_retries = Retry(0, read=False)85 else:86 self.max_retries = Retry.from_int(max_retries)87 self.config = {}
327 unmodified lines
415 except MaxRetryError as e:416 if isinstance(e.reason, ConnectTimeoutError):417 raise ConnectTimeout(e, request=request)418419 if isinstance(e.reason, ResponseError):420 raise RetryError(e, request=request)421422 raise ConnectionError(e, request=request)423424 except _ProxyError as e:425 raise ProxyError(e)
10 unmodified lines
modified:requests/exceptions.py+5 added
88 unmodified lines
8990class ContentDecodingError(RequestException, BaseHTTPError):91 """Failed to decode response content"""929394class StreamConsumedError(RequestException, TypeError):95 """The content for this response was already consumed"""969798class RetryError(RequestException):99 """Custom retries logic failed"""
modified:test_requests.py+13 added-1 removed
18 unmodified lines
19 Morsel, cookielib, getproxies, str, urljoin, urlparse, is_py3, builtin_str)20from requests.cookies import cookiejar_from_dict, morsel_to_cookie21from requests.exceptions import (ConnectionError, ConnectTimeout,22 InvalidSchema, InvalidURL, MissingSchema,23 ReadTimeout, Timeout)23 ReadTimeout, Timeout, RetryError)24from requests.models import PreparedRequest25from requests.structures import CaseInsensitiveDict26from requests.sessions import SessionRedirectMixin27from requests.models import urlencode
1491 unmodified lines
1519 cookies={'foo': 'bar'}1520 )1521 assert_copy(p, p.copy())152215231524def test_prepare_unicode_url():1525 p = PreparedRequest()1526 p.prepare(1527 method='GET',
1 unmodified line
1529 hooks=[]1530 )1531 assert_copy(p, p.copy())153215331534def test_urllib3_retries():1535 from requests.packages.urllib3.util import Retry1536 s = requests.Session()1537 s.mount('https://', HTTPAdapter(max_retries=Retry(1538 total=2, status_forcelist=[500]1539 )))15401541 with pytest.raises(RetryError):1542 s.get('https://httpbin.org/status/500')15431544if __name__ == '__main__':1545 unittest.main()