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
Provenance
- Commit
2eb7e3c- Tree
d3f7911- Author
Ian Cordasco <graffatcolmingov@gmail.com>- Committer
Ian Cordasco <graffatcolmingov@gmail.com>- Parent
f54a4e3
3 files changed+25 added−4 removed
modified:requests/adapters.py+7 added-3 removed
24 unmodified lines25 from .packages.urllib3.exceptions import ProxyError as _ProxyError26 from .packages.urllib3.exceptions import ProtocolError27 from .packages.urllib3.exceptions import ReadTimeoutError28 from .packages.urllib3.exceptions import SSLError as _SSLError29+from .packages.urllib3.exceptions import ResponseError30 from .cookies import extract_cookies_to_jar31 from .exceptions import (ConnectionError, ConnectTimeout, ReadTimeout, SSLError,31- ProxyError)32+ ProxyError, RetryError)33 from .auth import _basic_auth_str34 35 DEFAULT_POOLBLOCK = False36 DEFAULT_POOLSIZE = 1036-DEFAULT_RETRIES = object()37+DEFAULT_RETRIES = 038 39 40 class BaseAdapter(object):41 """The Base Transport Adapter"""37 unmodified lines79 80 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 lines415 except MaxRetryError as e:416 if isinstance(e.reason, ConnectTimeoutError):417 raise ConnectTimeout(e, request=request)418 419+ if isinstance(e.reason, ResponseError):420+ raise RetryError(e, request=request)421+422 raise ConnectionError(e, request=request)423 424 except _ProxyError as e:425 raise ProxyError(e)10 unmodified linesmodified:requests/exceptions.py+5 added
88 unmodified lines89 90 class ContentDecodingError(RequestException, BaseHTTPError):91 """Failed to decode response content"""92 93+94 class StreamConsumedError(RequestException, TypeError):95 """The content for this response was already consumed"""96+97+98+class RetryError(RequestException):99+ """Custom retries logic failed"""modified:test_requests.py+13 added-1 removed
18 unmodified lines19 Morsel, cookielib, getproxies, str, urljoin, urlparse, is_py3, builtin_str)20 from requests.cookies import cookiejar_from_dict, morsel_to_cookie21 from requests.exceptions import (ConnectionError, ConnectTimeout,22 InvalidSchema, InvalidURL, MissingSchema,23- ReadTimeout, Timeout)23+ ReadTimeout, Timeout, RetryError)24 from requests.models import PreparedRequest25 from requests.structures import CaseInsensitiveDict26 from requests.sessions import SessionRedirectMixin27 from requests.models import urlencode1491 unmodified lines1519 cookies={'foo': 'bar'}1520 )1521 assert_copy(p, p.copy())1522 1523+1524 def test_prepare_unicode_url():1525 p = PreparedRequest()1526 p.prepare(1527 method='GET',1 unmodified line1529 hooks=[]1530 )1531 assert_copy(p, p.copy())1532 1533+1534+def 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+ )))1540+1541+ with pytest.raises(RetryError):1542+ s.get('https://httpbin.org/status/500')1543+1544 if __name__ == '__main__':1545 unittest.main()