Skip to content
Myr

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

9 files+38 added−39 removed

modified:requests/auth.py+5 added-4 removed
34 unmodified lines
3536 def __call__(self, r):37 raise NotImplementedError('Auth hooks must be callable.')383940class HTTPBasicAuth(AuthBase):41 """Attaches HTTP Basic Authentication to the given Request object."""42 def __init__(self, username, password):43 self.username = username
85 unmodified lines
129 self.last_nonce = nonce130131 # 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"' % algorithm
6 unmodified lines
144145 def handle_401(self, r):146 """Takes the given response and tries digest-auth, if needed."""147147 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', '')150151 if 'digest' in s_auth.lower() and num_401_calls < 2:152
3 unmodified lines
156 # 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 160161 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)164165 return _r166166 setattr(self, 'num_401_calls', 1) 167 setattr(self, 'num_401_calls', 1)168 return r169170 def __call__(self, r):171 # If we have a saved nonce, skip the 401
4 unmodified lines
modified:requests/certs.py+1 added
12 unmodified lines
13"""1415import os.path161718def where():19 """Return the preferred certificate bundle."""20 # vendored bundle inside Requests21 return os.path.join(os.path.dirname(__file__), 'cacert.pem')
3 unmodified lines
modified:requests/compat.py-1 removed
96 unmodified lines
97 basestring = basestring98 numeric_types = (int, long, float)99100101101elif 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 cookielib
9 unmodified lines
modified:requests/hooks.py+2 added
14 unmodified lines
151617HOOKS = ['response']181920def default_hooks():21 hooks = {}22 for event in HOOKS:23 hooks[event] = []24 return hooks2526# TODO: response is the only one272829def dispatch_hook(key, hooks, hook_data):30 """Dispatches a hook dictionary on a given piece of data."""3132 hooks = hooks or dict()
13 unmodified lines
modified:requests/models.py+2 added-4 removed
186 unmodified lines
187 auth=None,188 cookies=None,189 hooks=None):190191191 # 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 headers
332 unmodified lines
527 """528529 pending = None530532 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):533534 if pending is not None:535 chunk = pending + chunk536 lines = chunk.splitlines()
121 unmodified lines
modified:requests/sessions.py+12 added-14 removed
118 unmodified lines
119 except KeyError:120 pass121122 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 )136137 i += 1138 yield resp
109 unmodified lines
248 # Curl compatibility.249 if not verify and verify is not False:250 verify = os.environ.get('CURL_CA_BUNDLE')251252252 # 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 lines
258 stream = merge_kwargs(stream, self.stream)259 verify = merge_kwargs(verify, self.verify)260 cert = merge_kwargs(cert, self.cert)261263262 # Create the Request.263 req = Request()264 req.method = method.upper()265 req.url = url
141 unmodified lines
modified:requests/structures.py+2 added
9 unmodified lines
1011import os12from itertools import islice131415class IteratorProxy(object):16 """docstring for IteratorProxy"""17 def __init__(self, i):18 self.i = i
12 unmodified lines
3132 def read(self, n):33 return "".join(islice(self.i, None, n))343536class CaseInsensitiveDict(dict):37 """Case-insensitive Dictionary3839 For example, ``headers['content-encoding']`` will return the
52 unmodified lines
modified:requests/utils.py+10 added-10 removed
28 unmodified lines
29NETRC_FILES = ('.netrc', '_netrc')3031DEFAULT_CA_BUNDLE_PATH = certs.where()323334def dict_to_sequence(d):35 """Returns an internal sequence dictionary update."""3637 if hasattr(d, 'items'):38 d = d.items()3940 return d414243def 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_size505152def get_netrc_auth(url):53 """Returns the Requests tuple auth for a given url from netrc."""5455 try:
410 unmodified lines
466467 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 Guess
8 unmodified lines
485 except IOError:486 p_system = 'Unknown'487 p_release = 'Unknown'488488 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 ])492493494def default_headers():495 return {496 'User-Agent': default_user_agent(),497 'Accept-Encoding': ', '.join(('gzip', 'deflate', 'compress')),
23 unmodified lines
521 link["url"] = url.strip("<> '\"")522523 for param in params.split(";"):524 try:525 key,value = param.split("=")525 key, value = param.split("=")526 except ValueError:527 break528529 link[key.strip(replace_chars)] = value.strip(replace_chars)
53 unmodified lines
modified:test_requests.py+4 added-6 removed
16 unmodified lines
17 import io as StringIO1819HTTPBIN = os.environ.get('HTTPBIN_URL', 'http://httpbin.org/')202122def httpbin(*suffix):23 """Returns url for HTTPBIN resource."""24 return HTTPBIN + '/'.join(suffix)252627class RequestsTestCase(unittest.TestCase):2829 _multiprocess_can_split_ = True30
27 unmodified lines
58 pr = req.prepare()59 assert pr.url == req.url60 assert pr.body == 'life=42'616062 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)676768 def test_path_is_not_double_encoded(self):69 request = requests.Request('GET', "http://0.0.0.0/get/test case").prepare()7071 self.assertEqual(request.path_url, "/get/test%20case")
40 unmodified lines
112113 def test_user_agent_transfers(self):114115 heads = {116 'User-agent':117 'Mozilla/5.0 (github.com/kennethreitz/requests)'116 'User-agent': 'Mozilla/5.0 (github.com/kennethreitz/requests)'117 }118119 r = requests.get(httpbin('user-agent'), headers=heads)120 self.assertTrue(heads['User-agent'] in r.text)121122 heads = {124 'user-agent':125 'Mozilla/5.0 (github.com/kennethreitz/requests)'123 'user-agent': 'Mozilla/5.0 (github.com/kennethreitz/requests)'124 }125126 r = requests.get(httpbin('user-agent'), headers=heads)127 self.assertTrue(heads['user-agent'] in r.text)
198 unmodified lines