it`s more pep8 now
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by oczkers · committed by oczkers · parent ac5e680 · Browse files · 9 files·+38 added−39 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
9 files+38 added−39 removed
- other:+38 added−39 removed
Provenance
- Commit
40a060c- Tree
82a3428- Author
oczkers <oczkers@gmail.com>- Committer
oczkers <oczkers@gmail.com>- Parent
ac5e680
9 files changed+38 added−39 removed
modified:requests/auth.py+5 added-4 removed
34 unmodified lines35 36 def __call__(self, r):37 raise NotImplementedError('Auth hooks must be callable.')38 39+40 class HTTPBasicAuth(AuthBase):41 """Attaches HTTP Basic Authentication to the given Request object."""42 def __init__(self, username, password):43 self.username = username85 unmodified lines129 self.last_nonce = nonce130 131 # XXX should the partial digests be encoded too?132 base = 'username="%s", realm="%s", nonce="%s", uri="%s", ' \132- 'response="%s"' % (self.username, realm, nonce, path, respdig)133+ 'response="%s"' % (self.username, realm, nonce, path, respdig)134 if opaque:135 base += ', opaque="%s"' % opaque136 if algorithm:137 base += ', algorithm="%s"' % algorithm6 unmodified lines144 145 def handle_401(self, r):146 """Takes the given response and tries digest-auth, if needed."""147 147- num_401_calls = getattr(self, 'num_401_calls', 1)148+ num_401_calls = getattr(self, 'num_401_calls', 1)149 s_auth = r.headers.get('www-authenticate', '')150 151 if 'digest' in s_auth.lower() and num_401_calls < 2:152 3 unmodified lines156 # Consume content and release the original connection157 # to allow our new request to reuse the same one.158 r.content159 r.raw.release_conn()159- 160+161 r.request.headers['Authorization'] = self.build_digest_header(r.request.method, r.request.url)162 _r = r.connection.send(r.request)163 _r.history.append(r)164 165 return _r166 166- setattr(self, 'num_401_calls', 1) 167+ setattr(self, 'num_401_calls', 1)168 return r169 170 def __call__(self, r):171 # If we have a saved nonce, skip the 4014 unmodified linesmodified:requests/certs.py+1 added
12 unmodified lines13 """14 15 import os.path16 17+18 def where():19 """Return the preferred certificate bundle."""20 # vendored bundle inside Requests21 return os.path.join(os.path.dirname(__file__), 'cacert.pem')3 unmodified linesmodified:requests/compat.py-1 removed
96 unmodified lines97 basestring = basestring98 numeric_types = (int, long, float)99 100 101-101 elif is_py3:102 from urllib.parse import urlparse, urlunparse, urljoin, urlsplit, urlencode, quote, unquote, quote_plus, unquote_plus, urldefrag103 from urllib.request import parse_http_list104 from http import cookiejar as cookielib9 unmodified linesmodified:requests/hooks.py+2 added
14 unmodified lines15 16 17 HOOKS = ['response']18 19+20 def default_hooks():21 hooks = {}22 for event in HOOKS:23 hooks[event] = []24 return hooks25 26 # TODO: response is the only one27 28+29 def dispatch_hook(key, hooks, hook_data):30 """Dispatches a hook dictionary on a given piece of data."""31 32 hooks = hooks or dict()13 unmodified linesmodified:requests/models.py+2 added-4 removed
186 unmodified lines187 auth=None,188 cookies=None,189 hooks=None):190 191-191 # Default empty dicts for dict params.192 data = [] if data is None else data193 files = [] if files is None else files194 headers = {} if headers is None else headers332 unmodified lines527 """528 529 pending = None530 532- for chunk in self.iter_content(533- chunk_size=chunk_size,534- decode_unicode=decode_unicode):531+ for chunk in self.iter_content(chunk_size=chunk_size,532+ decode_unicode=decode_unicode):533 534 if pending is not None:535 chunk = pending + chunk536 lines = chunk.splitlines()121 unmodified linesmodified:requests/sessions.py+12 added-14 removed
118 unmodified lines119 except KeyError:120 pass121 122 resp = self.request(123- url=url,124- method=method,125- headers=headers,126- auth=req.auth,127- cookies=req.cookies,128- allow_redirects=False,129- stream=stream,130- timeout=timeout,131- verify=verify,132- cert=cert,133- proxies=proxies,134- hooks=req.hooks,123+ url=url,124+ method=method,125+ headers=headers,126+ auth=req.auth,127+ cookies=req.cookies,128+ allow_redirects=False,129+ stream=stream,130+ timeout=timeout,131+ verify=verify,132+ cert=cert,133+ proxies=proxies,134+ hooks=req.hooks,135 )136 137 i += 1138 yield resp109 unmodified lines248 # Curl compatibility.249 if not verify and verify is not False:250 verify = os.environ.get('CURL_CA_BUNDLE')251 252-252 # Merge all the kwargs.253 params = merge_kwargs(params, self.params)254 headers = merge_kwargs(headers, self.headers)255 auth = merge_kwargs(auth, self.auth)2 unmodified lines258 stream = merge_kwargs(stream, self.stream)259 verify = merge_kwargs(verify, self.verify)260 cert = merge_kwargs(cert, self.cert)261 263-262 # Create the Request.263 req = Request()264 req.method = method.upper()265 req.url = url141 unmodified linesmodified:requests/structures.py+2 added
9 unmodified lines10 11 import os12 from itertools import islice13 14+15 class IteratorProxy(object):16 """docstring for IteratorProxy"""17 def __init__(self, i):18 self.i = i12 unmodified lines31 32 def read(self, n):33 return "".join(islice(self.i, None, n))34 35+36 class CaseInsensitiveDict(dict):37 """Case-insensitive Dictionary38 39 For example, ``headers['content-encoding']`` will return the52 unmodified linesmodified:requests/utils.py+10 added-10 removed
28 unmodified lines29 NETRC_FILES = ('.netrc', '_netrc')30 31 DEFAULT_CA_BUNDLE_PATH = certs.where()32 33+34 def dict_to_sequence(d):35 """Returns an internal sequence dictionary update."""36 37 if hasattr(d, 'items'):38 d = d.items()39 40 return d41 42+43 def super_len(o):44 if hasattr(o, '__len__'):45 return len(o)46 if hasattr(o, 'len'):47 return o.len48 if hasattr(o, 'fileno'):49 return os.fstat(o.fileno()).st_size50 51+52 def get_netrc_auth(url):53 """Returns the Requests tuple auth for a given url from netrc."""54 55 try:410 unmodified lines466 467 if _implementation == 'CPython':468 _implementation_version = platform.python_version()469 elif _implementation == 'PyPy':467- _implementation_version = '%s.%s.%s' % (468- sys.pypy_version_info.major,470+ _implementation_version = '%s.%s.%s' % (sys.pypy_version_info.major,471 sys.pypy_version_info.minor,470- sys.pypy_version_info.micro471- )472+ sys.pypy_version_info.micro)473 if sys.pypy_version_info.releaselevel != 'final':474 _implementation_version = ''.join([_implementation_version, sys.pypy_version_info.releaselevel])475 elif _implementation == 'Jython':476 _implementation_version = platform.python_version() # Complete Guess8 unmodified lines485 except IOError:486 p_system = 'Unknown'487 p_release = 'Unknown'488 488- return " ".join([489- 'python-requests/%s' % __version__,490- '%s/%s' % (_implementation, _implementation_version),491- '%s/%s' % (p_system, p_release),489+ return " ".join(['python-requests/%s' % __version__,490+ '%s/%s' % (_implementation, _implementation_version),491+ '%s/%s' % (p_system, p_release)])492- ])492 493+494 def default_headers():495 return {496 'User-Agent': default_user_agent(),497 'Accept-Encoding': ', '.join(('gzip', 'deflate', 'compress')),23 unmodified lines521 link["url"] = url.strip("<> '\"")522 523 for param in params.split(";"):524 try:525- key,value = param.split("=")525+ key, value = param.split("=")526 except ValueError:527 break528 529 link[key.strip(replace_chars)] = value.strip(replace_chars)53 unmodified linesmodified:test_requests.py+4 added-6 removed
16 unmodified lines17 import io as StringIO18 19 HTTPBIN = os.environ.get('HTTPBIN_URL', 'http://httpbin.org/')20 21+22 def httpbin(*suffix):23 """Returns url for HTTPBIN resource."""24 return HTTPBIN + '/'.join(suffix)25 26+27 class RequestsTestCase(unittest.TestCase):28 29 _multiprocess_can_split_ = True30 27 unmodified lines58 pr = req.prepare()59 assert pr.url == req.url60 assert pr.body == 'life=42'61 60-62 def test_no_content_length(self):63 get_req = requests.Request('GET', httpbin('get')).prepare()64 self.assertTrue('Content-Length' not in get_req.headers)65 head_req = requests.Request('HEAD', httpbin('head')).prepare()66 self.assertTrue('Content-Length' not in head_req.headers)67 67-68 def test_path_is_not_double_encoded(self):69 request = requests.Request('GET', "http://0.0.0.0/get/test case").prepare()70 71 self.assertEqual(request.path_url, "/get/test%20case")40 unmodified lines112 113 def test_user_agent_transfers(self):114 115 heads = {116- 'User-agent':117- 'Mozilla/5.0 (github.com/kennethreitz/requests)'116+ 'User-agent': 'Mozilla/5.0 (github.com/kennethreitz/requests)'117 }118 119 r = requests.get(httpbin('user-agent'), headers=heads)120 self.assertTrue(heads['User-agent'] in r.text)121 122 heads = {124- 'user-agent':125- 'Mozilla/5.0 (github.com/kennethreitz/requests)'123+ 'user-agent': 'Mozilla/5.0 (github.com/kennethreitz/requests)'124 }125 126 r = requests.get(httpbin('user-agent'), headers=heads)127 self.assertTrue(heads['user-agent'] in r.text)198 unmodified lines