Merge commit 'v0.8.6'
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 · parents 19a2a6c, c910b95 · Browse files · 7 files·+73 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
7 files+73 added−17 removed
- other:+73 added−17 removed
Provenance
- Commit
70fbd27- Tree
ff7d40b- Author
Kenneth Reitz <me@kennethreitz.com>- Committer
Kenneth Reitz <me@kennethreitz.com>- Parent 1
19a2a6c- Parent 2
c910b95
7 files changed+73 added−17 removed
modified:requests/packages/urllib3/connectionpool.py+30 added-9 removed
208 unmodified lines209 210 if timeout is _Default:211 timeout = self.timeout212 213+ conn.timeout = timeout # This only does anything in Py26+214+215 conn.request(method, url, **httplib_request_kw)216 conn.sock.settimeout(timeout)217 httplib_response = conn.getresponse()218 26 unmodified lines245 246 More commonly, it's appropriate to use a convenience method provided247 by :class:`.RequestMethods`, such as :meth:`.request`.248 249+ .. note::250+251+ `release_conn` will only behave as expected if252+ `preload_content=False` because we want to make253+ `preload_content=False` the default behaviour someday soon without254+ breaking backwards compatibility.255+256 :param method:257 HTTP request method (such as GET, POST, PUT, etc.)258 259 :param body:27 unmodified lines287 connection is available within the time period.288 289 :param release_conn:290 If False, then the urlopen call will not release the connection282- back into the pool once a response is received. This is useful if283- you're not preloading the response's content immediately. You will284- need to call ``r.release_conn()`` on the response ``r`` to return285- the connection back into the pool. If None, it takes the value of291+ back into the pool once a response is received (but will release if292+ you read the entire contents of the response such as when293+ `preload_content=True`). This is useful if you're not preloading294+ the response's content immediately. You will need to call295+ ``r.release_conn()`` on the response ``r`` to return the connection296+ back into the pool. If None, it takes the value of297 ``response_kw.get('preload_content', True)``.298 299 :param \**response_kw:300 Additional parameters are passed to4 unmodified lines305 306 if retries < 0:307 raise MaxRetryError("Max retries exceeded for url: %s" % url)308 309+ if timeout is _Default:310+ timeout = self.timeout311+312 if release_conn is None:313 release_conn = response_kw.get('preload_content', True)314 315 # Check host33 unmodified lines349 # The connection will be put back into the pool when350 # ``response.release_conn()`` is called (implicitly by351 # ``response.read()``)352 339- except (SocketTimeout, Empty), e:340- # Timed out either by socket or queue341- raise TimeoutError("Request timed out after %s seconds" %342- self.timeout)353+ except (Empty), e:354+ # Timed out by queue355+ raise TimeoutError("Request timed out. (pool_timeout=%s)" %356+ pool_timeout)357 358+ except (SocketTimeout), e:359+ # Timed out by socket360+ raise TimeoutError("Request timed out. (timeout=%s)" %361+ timeout)362+363 except (BaseSSLError), e:364 # SSL certificate error365 raise SSLError(e)366 139 unmodified lines506 # This code is actually similar to urlparse.urlsplit, but much507 # simplified for our needs.508 port = None509 scheme = 'http'491- if '//' in url:510+ if '://' in url:511 scheme, url = url.split('://', 1)512 if '/' in url:513 url, _path = url.split('/', 1)514+ if '@' in url:515+ _auth, url = url.split('@', 1)516 if ':' in url:517 url, port = url.split(':', 1)518 port = int(port)519 return scheme, url, port27 unmodified linesmodified:requests/__init__.py+2 added-2 removed
13 unmodified lines14 15 """16 17 __title__ = 'requests'18-__version__ = '0.8.5'19-__build__ = 0x00080518+__version__ = '0.8.6'19+__build__ = 0x00080620 __author__ = 'Kenneth Reitz'21 __license__ = 'ISC'22 __copyright__ = 'Copyright 2011 Kenneth Reitz'23 11 unmodified linesmodified:requests/auth.py+16 added-4 removed
14 unmodified lines15 16 from .utils import randombytes, parse_dict_header17 18 19+20+def _basic_auth_str(username, password):21+ """Returns a Basic Auth string."""22+ return 'Basic %s' % b64encode('%s:%s' % (username, password))23+24+25 class AuthBase(object):26 """Base class that all auth implementations derive from"""27 28 def __call__(self, r):6 unmodified lines35 self.username = str(username)36 self.password = str(password)37 38 def __call__(self, r):33- auth_s = b64encode('%s:%s' % (self.username, self.password))34- r.headers['Authorization'] = ('Basic %s' % auth_s)39+ r.headers['Authorization'] = _basic_auth_str(self.username, self.password)40 return r41 42 43+class HTTPProxyAuth(HTTPBasicAuth):44+ """Attaches HTTP Proxy Authenetication to a given Request object."""45+ def __call__(self, r):46+ r.headers['Proxy-Authorization'] = _basic_auth_str(self.username, self.password)47+ return r48+49+50 class HTTPDigestAuth(AuthBase):51 """Attaches HTTP Digest Authentication to the given Request object."""52 def __init__(self, username, password):53 self.username = username33 unmodified lines87 entdig = None88 p_parsed = urlparse(r.request.url)89 path = p_parsed.path + p_parsed.query90 79- A1 = "%s:%s:%s" % (self.username, realm, self.password)80- A2 = "%s:%s" % (r.request.method, path)91+ A1 = '%s:%s:%s' % (self.username, realm, self.password)92+ A2 = '%s:%s' % (r.request.method, path)93 94 if qop == 'auth':95 if nonce == last_nonce:96 nonce_count += 140 unmodified linesmodified:requests/models.py+7 added-1 removed
15 unmodified lines16 from .hooks import dispatch_hook17 from .structures import CaseInsensitiveDict18 from .status_codes import codes19 from .packages import oreos20-from .auth import HTTPBasicAuth20+from .auth import HTTPBasicAuth, HTTPProxyAuth21 from .packages.urllib3.exceptions import MaxRetryError22 from .packages.urllib3.exceptions import SSLError as _SSLError23 from .packages.urllib3.exceptions import HTTPError as _HTTPError24 from .packages.urllib3 import connectionpool, poolmanager381 unmodified lines406 proxy = self.proxies.get(_p.scheme)407 408 if proxy:409 conn = poolmanager.proxy_from_url(proxy)410+ _proxy = urlparse(proxy)411+ if '@' in _proxy.netloc:412+ auth, url = _proxy.netloc.split('@', 1)413+ self.proxy_auth = HTTPProxyAuth(*auth.split(':', 1))414+ r = self.proxy_auth(self)415+ self.__dict__.update(r.__dict__)416 else:417 # Check to see if keep_alive is allowed.418 if self.config.get('keep_alive'):419 conn = self._poolmanager.connection_from_url(url)270 unmodified linesmodified:AUTHORS.rst+2 added-1 removed
62 unmodified lines63 - Rolando Espinoza La fuente64 - Robert Gieseke65 - Idan Gazit66 - Ed Summers67-- Chris Van Horne67+- Chris Van Horne68+- Christopher Davismodified:HISTORY.rst+7 added
1 History2 -------3 4+0.8.6 (2011-12-18)5+++++++++++++++++++6+7+* Socket timeout fixes.8+* Proxy Authorization support.9+10+11 0.8.5 (2011-12-14)12 ++++++++++++++++++13 14 * Response.iter_lines!280 unmodified linesmodified:Makefile+9 added
11 unmodified lines12 13 site:14 cd docs; make dirhtml15 16+pyc:17+ find . -name "*.pyc" -exec rm '{}' ';'18+19+deps:20+ rm -fr requests/packages/urllib321+ git clone https://github.com/shazow/urllib3.git22+ mv urllib3/urllib3 requests/packages/23+ rm -fr urllib324+25 docs: site