update requests to v2.9.1-dev

This commit is contained in:
Alan Hamlett 2016-03-06 12:34:13 -08:00
parent 9981601a0a
commit b6bd75a0e8
5 changed files with 37 additions and 11 deletions

View file

@ -46,7 +46,7 @@ __version__ = '2.9.1'
__build__ = 0x020901 __build__ = 0x020901
__author__ = 'Kenneth Reitz' __author__ = 'Kenneth Reitz'
__license__ = 'Apache 2.0' __license__ = 'Apache 2.0'
__copyright__ = 'Copyright 2015 Kenneth Reitz' __copyright__ = 'Copyright 2016 Kenneth Reitz'
# Attempt to enable urllib3's SNI support, if possible # Attempt to enable urllib3's SNI support, if possible
try: try:

View file

@ -65,7 +65,7 @@ class HTTPAdapter(BaseAdapter):
:param pool_connections: The number of urllib3 connection pools to cache. :param pool_connections: The number of urllib3 connection pools to cache.
:param pool_maxsize: The maximum number of connections to save in the pool. :param pool_maxsize: The maximum number of connections to save in the pool.
:param int max_retries: The maximum number of retries each connection :param max_retries: The maximum number of retries each connection
should attempt. Note, this applies only to failed DNS lookups, socket should attempt. Note, this applies only to failed DNS lookups, socket
connections and connection timeouts, never to requests where data has connections and connection timeouts, never to requests where data has
made it to the server. By default, Requests does not retry failed made it to the server. By default, Requests does not retry failed

View file

@ -47,6 +47,15 @@ class HTTPBasicAuth(AuthBase):
self.username = username self.username = username
self.password = password self.password = password
def __eq__(self, other):
return all([
self.username == getattr(other, 'username', None),
self.password == getattr(other, 'password', None)
])
def __ne__(self, other):
return not self == other
def __call__(self, r): def __call__(self, r):
r.headers['Authorization'] = _basic_auth_str(self.username, self.password) r.headers['Authorization'] = _basic_auth_str(self.username, self.password)
return r return r
@ -221,3 +230,12 @@ class HTTPDigestAuth(AuthBase):
self._thread_local.num_401_calls = 1 self._thread_local.num_401_calls = 1
return r return r
def __eq__(self, other):
return all([
self.username == getattr(other, 'username', None),
self.password == getattr(other, 'password', None)
])
def __ne__(self, other):
return not self == other

View file

@ -277,6 +277,12 @@ class RequestsCookieJar(cookielib.CookieJar, collections.MutableMapping):
dictionary[cookie.name] = cookie.value dictionary[cookie.name] = cookie.value
return dictionary return dictionary
def __contains__(self, name):
try:
return super(RequestsCookieJar, self).__contains__(name)
except CookieConflictError:
return True
def __getitem__(self, name): def __getitem__(self, name):
"""Dict-like __getitem__() for compatibility with client code. Throws """Dict-like __getitem__() for compatibility with client code. Throws
exception if there are more than one cookie with name. In that case, exception if there are more than one cookie with name. In that case,

View file

@ -110,7 +110,7 @@ class SessionRedirectMixin(object):
resp.raw.read(decode_content=False) resp.raw.read(decode_content=False)
if i >= self.max_redirects: if i >= self.max_redirects:
raise TooManyRedirects('Exceeded %s redirects.' % self.max_redirects) raise TooManyRedirects('Exceeded %s redirects.' % self.max_redirects, response=resp)
# Release the connection back into the pool. # Release the connection back into the pool.
resp.close() resp.close()
@ -553,19 +553,21 @@ class Session(SessionRedirectMixin):
if not isinstance(request, PreparedRequest): if not isinstance(request, PreparedRequest):
raise ValueError('You can only send PreparedRequests.') raise ValueError('You can only send PreparedRequests.')
checked_urls = set()
while request.url in self.redirect_cache:
checked_urls.add(request.url)
new_url = self.redirect_cache.get(request.url)
if new_url in checked_urls:
break
request.url = new_url
# Set up variables needed for resolve_redirects and dispatching of hooks # Set up variables needed for resolve_redirects and dispatching of hooks
allow_redirects = kwargs.pop('allow_redirects', True) allow_redirects = kwargs.pop('allow_redirects', True)
stream = kwargs.get('stream') stream = kwargs.get('stream')
hooks = request.hooks hooks = request.hooks
# Resolve URL in redirect cache, if available.
if allow_redirects:
checked_urls = set()
while request.url in self.redirect_cache:
checked_urls.add(request.url)
new_url = self.redirect_cache.get(request.url)
if new_url in checked_urls:
break
request.url = new_url
# Get the appropriate adapter to use # Get the appropriate adapter to use
adapter = self.get_adapter(url=request.url) adapter = self.get_adapter(url=request.url)