Skip to content
Myr

Merge branch 'netrc' into develop

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 6f57352, 8c87371 · Browse files · 5 files+48 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

5 files+48 added−4 removed

  • other:+48 added−4 removed

5 files+48 added−4 removed

modified:docs/index.rst+1 added
70 unmodified lines
71- Automatic Decompression72- Unicode Response Bodies73- Multipart File Uploads74- Connection Timeouts75- ``.netrc`` support767778User Guide79----------
52 unmodified lines
modified:requests/models.py+5 added-1 removed
25 unmodified lines
26 ConnectionError, HTTPError, RequestException, Timeout, TooManyRedirects,27 URLRequired, SSLError)28from .utils import (29 get_encoding_from_headers, stream_untransfer, guess_filename, requote_uri,30 dict_from_string, stream_decode_response_unicode)30 dict_from_string, stream_decode_response_unicode, get_netrc_auth)31from .compat import (32 urlparse, urlunparse, urljoin, urlsplit, urlencode, str, bytes,33 SimpleCookie, is_py2)34
399 unmodified lines
434 # Add content-type if it wasn't explicitly provided.435 if (content_type) and (not 'content-type' in self.headers):436 self.headers['Content-Type'] = content_type437438 # Use .netrc auth if none was provided.439 if not self.auth:440 self.auth = get_netrc_auth(url)441442 if self.auth:443 if isinstance(self.auth, tuple) and len(self.auth) == 2:444 # special-case basic HTTP auth445 self.auth = HTTPBasicAuth(*self.auth)
348 unmodified lines
modified:requests/sessions.py+1 added-1 removed
38 unmodified lines
39 kwargs = default_kwarg.copy()40 kwargs.update(local_kwarg)4142 # Remove keys that are set to None.43 for (k,v) in list(local_kwarg.items()):43 for (k, v) in list(local_kwarg.items()):44 if v is None:45 del kwargs[k]4647 return kwargs
250 unmodified lines
modified:requests/utils.py+36 added-2 removed
9 unmodified lines
10"""1112import cgi13import codecs14import os15import random16import re17import zlib18from netrc import netrc, NetrcParseError1920from .compat import parse_http_list as _parse_list_header19from .compat import quote, cookielib, SimpleCookie, is_py221from .compat import quote, cookielib, SimpleCookie, is_py2, urlparse22from .compat import basestring, bytes232425NETRC_FILES = ('.netrc', '_netrc')262728def get_netrc_auth(url):29 """Returns the Requests tuple auth for a given url from netrc."""3031 locations = (os.path.expanduser('~/{0}'.format(f)) for f in NETRC_FILES)32 netrc_path = None3334 for loc in locations:35 if os.path.exists(loc) and not netrc_path:36 netrc_path = loc3738 # Abort early if there isn't one.39 if netrc_path is None:40 return netrc_path4142 ri = urlparse(url)4344 # Strip port numbers from netloc45 host = ri.netloc.split(':')[0]4647 try:48 _netrc = netrc(netrc_path).authenticators(host)49 if _netrc:50 # Return with login / password51 login_i = (0 if _netrc[0] else 1)52 return (_netrc[login_i], _netrc[2])53 except NetrcParseError:54 pass555657def dict_from_string(s):58 """Returns a MultiDict with Cookies."""5960 cookies = dict()
121 unmodified lines
182 if isinstance(headers, dict):183 headers = list(headers.items())184 elif isinstance(headers, basestring):185 return headers152 elif isinstance(headers, unicode):186 elif isinstance(headers, str):187 # As discussed in https://github.com/kennethreitz/requests/issues/400188 # latin-1 is the most conservative encoding used on the web. Anyone189 # who needs more can encode to a byte-string before calling190 return headers.encode("latin-1")
266 unmodified lines
modified:HISTORY.rst+5 added
1History2-------340.10.4 (2012-02-20)5+++++++++++++++++++67* Honor netrc.890.10.3 (2012-02-20)10+++++++++++++++++++1112* HEAD requests don't follow redirects anymore.
378 unmodified lines