updated urllib3
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Kenneth Reitz · committed by Kenneth Reitz · parent f5f2ddf · Browse files · 11 files·+31 added−17 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
11 files+31 added−17 removed
- other:+31 added−17 removed
Provenance
- Commit
69e7e94- Tree
fda6d6d- Author
Kenneth Reitz <me@kennethreitz.com>- Committer
Kenneth Reitz <me@kennethreitz.com>- Parent
f5f2ddf
11 files changed+31 added−17 removed
modified:requests/packages/urllib3/contrib/__init__.py
modified:requests/packages/urllib3/contrib/ntlmpool.py
modified:requests/packages/urllib3/__init__.py+1 added-1 removed
8 unmodified lines9 """10 11 __author__ = 'Andrey Petrov (andrey.petrov@shazow.net)'12 __license__ = 'MIT'13-__version__ = '1.0.1'13+__version__ = '1.0.2'14 15 16 from .connectionpool import (17 HTTPConnectionPool,31 unmodified linesmodified:requests/packages/urllib3/_collections.py+28 added-14 removed
2 unmodified lines3 #4 # This module is part of urllib3 and is released under5 # the MIT License: http://www.opensource.org/licenses/mit-license.php6 7-from collections import MutableMapping, deque7+from collections import deque, MutableMapping8 9+from threading import RLock10 11 __all__ = ['RecentlyUsedContainer']12 13 10 unmodified lines24 Provides a dict-like that maintains up to ``maxsize`` keys while throwing25 away the least-recently-used keys beyond ``maxsize``.26 """27 27- # TODO: Make this threadsafe. _prune_invalidated_entries should be the28- # only real pain-point for this.29-28 # If len(self.access_log) exceeds self._maxsize * CLEANUP_FACTOR, then we29 # will attempt to cleanup the invalidated entries in the access_log30 # datastructure during the next 'get' operation.31 CLEANUP_FACTOR = 104 unmodified lines36 self._container = {}37 38 # We use a deque to to store our keys ordered by the last access.39 self.access_log = deque()40+ self.access_log_lock = RLock()41 42 # We look up the access log entry by the key to invalidate it so we can43 # insert a new authorative entry at the head without having to dig and44 # find the old entry for removal immediately.1 unmodified line46 47 # Trigger a heap cleanup when we get past this size48 self.access_log_limit = maxsize * self.CLEANUP_FACTOR49 51- def _push_entry(self, key):52- "Push entry onto our access log, invalidate the old entry if exists."53- # Invalidate old entry if it exists50+ def _invalidate_entry(self, key):51+ "If exists: Invalidate old entry and return it."52 old_entry = self.access_lookup.get(key)53 if old_entry:54 old_entry.is_valid = False55 58- new_entry = AccessEntry(key)56+ return old_entry57 58+ def _push_entry(self, key):59+ "Push entry onto our access log, invalidate the old entry if exists."60+ self._invalidate_entry(key)61+62+ new_entry = AccessEntry(key)63 self.access_lookup[key] = new_entry64+65+ self.access_log_lock.acquire()66 self.access_log.appendleft(new_entry)67+ self.access_log_lock.release()68 69 def _prune_entries(self, num):70 "Pop entries from our access log until we popped ``num`` valid ones."71 while num > 0:72+ self.access_log_lock.acquire()73 p = self.access_log.pop()74+ self.access_log_lock.release()75 76 if not p.is_valid:77 continue # Invalidated entry, skip78 71- del self._container[p.key]72- del self.access_lookup[p.key]79+ self._container.pop(p.key, None)80+ self.access_lookup.pop(p.key, None)81 num -= 182 83 def _prune_invalidated_entries(self):84 "Rebuild our access_log without the invalidated entries."85+ self.access_log_lock.acquire()86 self.access_log = deque(e for e in self.access_log if e.is_valid)87+ self.access_log_lock.release()88 89 def _get_ordered_access_keys(self):80- # Used for testing81- return [e.key for e in self.access_log if e.is_valid]90+ "Return ordered access keys for inspection. Used for testing."91+ self.access_log_lock.acquire()92+ r = [e.key for e in self.access_log if e.is_valid]93+ self.access_log_lock.release()94 95+ return r96+97 def __getitem__(self, key):98 item = self._container.get(key)99 100 if not item:87- return101+ raise KeyError(key)102 103 # Insert new entry with new high priority, also implicitly invalidates104 # the old entry.105 self._push_entry(key)15 unmodified lines121 122 def __delitem__(self, key):123 self._invalidate_entry(key)124 del self._container[key]111- del self._access_lookup[key]125+ del self.access_lookup[key]126 127 def __len__(self):128 return self._container.__len__()129 5 unmodified linesmodified:requests/packages/urllib3/connectionpool.py
modified:requests/packages/urllib3/exceptions.py
modified:requests/packages/urllib3/filepost.py
modified:requests/packages/urllib3/poolmanager.py+1 added-1 removed
106 unmodified lines107 conn = self.connection_from_url(url)108 return conn.urlopen(method, url, assert_same_host=False, **kw)109 110 111-class ProxyManager(object):111+class ProxyManager(RequestMethods):112 """113 Given a ConnectionPool to a proxy, the ProxyManager's ``urlopen`` method114 will make requests to any url through the defined proxy.115 """13 unmodified linesmodified:requests/packages/urllib3/request.py
modified:requests/packages/urllib3/response.py
modified:requests/packages/__init__.py+1 added-1 removed
1 from __future__ import absolute_import2 3-from . import poster3+from . import urllib3