aboutsummaryrefslogtreecommitdiff
path: root/urllib3/poolmanager.py
diff options
context:
space:
mode:
authorSVN-Git Migration <python-modules-team@lists.alioth.debian.org>2015-10-08 13:19:42 -0700
committerSVN-Git Migration <python-modules-team@lists.alioth.debian.org>2015-10-08 13:19:42 -0700
commitc9df3d807f7134f58f4a84dc8b80e9dc98c62f3a (patch)
tree2c14ecbc5e10513419b15f690e7bddfdb2dab75e /urllib3/poolmanager.py
parentb6ab7bae87b22c6fae783e8850533219d3bf8a29 (diff)
downloadpython-urllib3-c9df3d807f7134f58f4a84dc8b80e9dc98c62f3a.tar
python-urllib3-c9df3d807f7134f58f4a84dc8b80e9dc98c62f3a.tar.gz
Imported Upstream version 1.10.4
Diffstat (limited to 'urllib3/poolmanager.py')
-rw-r--r--urllib3/poolmanager.py19
1 files changed, 17 insertions, 2 deletions
diff --git a/urllib3/poolmanager.py b/urllib3/poolmanager.py
index 515dc96..b8d1e74 100644
--- a/urllib3/poolmanager.py
+++ b/urllib3/poolmanager.py
@@ -8,7 +8,7 @@ except ImportError:
from ._collections import RecentlyUsedContainer
from .connectionpool import HTTPConnectionPool, HTTPSConnectionPool
from .connectionpool import port_by_scheme
-from .exceptions import LocationValueError
+from .exceptions import LocationValueError, MaxRetryError
from .request import RequestMethods
from .util.url import parse_url
from .util.retry import Retry
@@ -64,6 +64,14 @@ class PoolManager(RequestMethods):
self.pools = RecentlyUsedContainer(num_pools,
dispose_func=lambda p: p.close())
+ def __enter__(self):
+ return self
+
+ def __exit__(self, exc_type, exc_val, exc_tb):
+ self.clear()
+ # Return False to re-raise any potential exceptions
+ return False
+
def _new_pool(self, scheme, host, port):
"""
Create a new :class:`ConnectionPool` based on host, port and scheme.
@@ -167,7 +175,14 @@ class PoolManager(RequestMethods):
if not isinstance(retries, Retry):
retries = Retry.from_int(retries, redirect=redirect)
- kw['retries'] = retries.increment(method, redirect_location)
+ try:
+ retries = retries.increment(method, url, response=response, _pool=conn)
+ except MaxRetryError:
+ if retries.raise_on_redirect:
+ raise
+ return response
+
+ kw['retries'] = retries
kw['redirect'] = redirect
log.info("Redirecting %s -> %s" % (url, redirect_location))