it`s more pep8 now
authoroczkers <oczkers@gmail.com>
Sun, 27 Jan 2013 01:04:12 +0000 (02:04 +0100)
committeroczkers <oczkers@gmail.com>
Sun, 27 Jan 2013 01:04:12 +0000 (02:04 +0100)
requests/auth.py
requests/certs.py
requests/compat.py
requests/hooks.py
requests/models.py
requests/sessions.py
requests/structures.py
requests/utils.py
test_requests.py

index b241806..1f8d659 100644 (file)
@@ -36,6 +36,7 @@ class AuthBase(object):
     def __call__(self, r):
         raise NotImplementedError('Auth hooks must be callable.')
 
+
 class HTTPBasicAuth(AuthBase):
     """Attaches HTTP Basic Authentication to the given Request object."""
     def __init__(self, username, password):
@@ -129,7 +130,7 @@ class HTTPDigestAuth(AuthBase):
 
         # XXX should the partial digests be encoded too?
         base = 'username="%s", realm="%s", nonce="%s", uri="%s", ' \
-           'response="%s"' % (self.username, realm, nonce, path, respdig)
+               'response="%s"' % (self.username, realm, nonce, path, respdig)
         if opaque:
             base += ', opaque="%s"' % opaque
         if algorithm:
@@ -144,7 +145,7 @@ class HTTPDigestAuth(AuthBase):
     def handle_401(self, r):
         """Takes the given response and tries digest-auth, if needed."""
 
-        num_401_calls =  getattr(self, 'num_401_calls', 1)
+        num_401_calls = getattr(self, 'num_401_calls', 1)
         s_auth = r.headers.get('www-authenticate', '')
 
         if 'digest' in s_auth.lower() and num_401_calls < 2:
@@ -156,14 +157,14 @@ class HTTPDigestAuth(AuthBase):
             # to allow our new request to reuse the same one.
             r.content
             r.raw.release_conn()
-            
+
             r.request.headers['Authorization'] = self.build_digest_header(r.request.method, r.request.url)
             _r = r.connection.send(r.request)
             _r.history.append(r)
 
             return _r
 
-        setattr(self, 'num_401_calls', 1)  
+        setattr(self, 'num_401_calls', 1)
         return r
 
     def __call__(self, r):
index 752460c..bc00826 100644 (file)
@@ -14,6 +14,7 @@ packaged CA bundle.
 
 import os.path
 
+
 def where():
     """Return the preferred certificate bundle."""
     # vendored bundle inside Requests
index 5bd4fcb..bcf94b0 100644 (file)
@@ -98,7 +98,6 @@ if is_py2:
     numeric_types = (int, long, float)
 
 
-
 elif is_py3:
     from urllib.parse import urlparse, urlunparse, urljoin, urlsplit, urlencode, quote, unquote, quote_plus, unquote_plus, urldefrag
     from urllib.request import parse_http_list
index 6135033..8c661c6 100644 (file)
@@ -16,6 +16,7 @@ Available hooks:
 
 HOOKS = ['response']
 
+
 def default_hooks():
     hooks = {}
     for event in HOOKS:
@@ -24,6 +25,7 @@ def default_hooks():
 
 # TODO: response is the only one
 
+
 def dispatch_hook(key, hooks, hook_data):
     """Dispatches a hook dictionary on a given piece of data."""
 
index d86b80a..0044079 100644 (file)
@@ -188,7 +188,6 @@ class Request(RequestHooksMixin):
         cookies=None,
         hooks=None):
 
-
         # Default empty dicts for dict params.
         data = [] if data is None else data
         files = [] if files is None else files
@@ -529,9 +528,8 @@ class Response(object):
 
         pending = None
 
-        for chunk in self.iter_content(
-            chunk_size=chunk_size,
-            decode_unicode=decode_unicode):
+        for chunk in self.iter_content(chunk_size=chunk_size,
+                                       decode_unicode=decode_unicode):
 
             if pending is not None:
                 chunk = pending + chunk
index 2687cb6..e607adf 100644 (file)
@@ -120,18 +120,18 @@ class SessionRedirectMixin(object):
                 pass
 
             resp = self.request(
-                    url=url,
-                    method=method,
-                    headers=headers,
-                    auth=req.auth,
-                    cookies=req.cookies,
-                    allow_redirects=False,
-                    stream=stream,
-                    timeout=timeout,
-                    verify=verify,
-                    cert=cert,
-                    proxies=proxies,
-                    hooks=req.hooks,
+                url=url,
+                method=method,
+                headers=headers,
+                auth=req.auth,
+                cookies=req.cookies,
+                allow_redirects=False,
+                stream=stream,
+                timeout=timeout,
+                verify=verify,
+                cert=cert,
+                proxies=proxies,
+                hooks=req.hooks,
             )
 
             i += 1
@@ -249,7 +249,6 @@ class Session(SessionRedirectMixin):
             if not verify and verify is not False:
                 verify = os.environ.get('CURL_CA_BUNDLE')
 
-
         # Merge all the kwargs.
         params = merge_kwargs(params, self.params)
         headers = merge_kwargs(headers, self.headers)
@@ -260,7 +259,6 @@ class Session(SessionRedirectMixin):
         verify = merge_kwargs(verify, self.verify)
         cert = merge_kwargs(cert, self.cert)
 
-
         # Create the Request.
         req = Request()
         req.method = method.upper()
index 6c2e0b2..05f5ac1 100644 (file)
@@ -11,6 +11,7 @@ Data structures that power Requests.
 import os
 from itertools import islice
 
+
 class IteratorProxy(object):
     """docstring for IteratorProxy"""
     def __init__(self, i):
@@ -31,6 +32,7 @@ class IteratorProxy(object):
     def read(self, n):
         return "".join(islice(self.i, None, n))
 
+
 class CaseInsensitiveDict(dict):
     """Case-insensitive Dictionary
 
index 34d92d2..3bdfe31 100644 (file)
@@ -30,6 +30,7 @@ NETRC_FILES = ('.netrc', '_netrc')
 
 DEFAULT_CA_BUNDLE_PATH = certs.where()
 
+
 def dict_to_sequence(d):
     """Returns an internal sequence dictionary update."""
 
@@ -38,6 +39,7 @@ def dict_to_sequence(d):
 
     return d
 
+
 def super_len(o):
     if hasattr(o, '__len__'):
         return len(o)
@@ -46,6 +48,7 @@ def super_len(o):
     if hasattr(o, 'fileno'):
         return os.fstat(o.fileno()).st_size
 
+
 def get_netrc_auth(url):
     """Returns the Requests tuple auth for a given url from netrc."""
 
@@ -464,11 +467,9 @@ def default_user_agent():
     if _implementation == 'CPython':
         _implementation_version = platform.python_version()
     elif _implementation == 'PyPy':
-        _implementation_version = '%s.%s.%s' % (
-                                                sys.pypy_version_info.major,
+        _implementation_version = '%s.%s.%s' % (sys.pypy_version_info.major,
                                                 sys.pypy_version_info.minor,
-                                                sys.pypy_version_info.micro
-                                            )
+                                                sys.pypy_version_info.micro)
         if sys.pypy_version_info.releaselevel != 'final':
             _implementation_version = ''.join([_implementation_version, sys.pypy_version_info.releaselevel])
     elif _implementation == 'Jython':
@@ -485,11 +486,10 @@ def default_user_agent():
         p_system = 'Unknown'
         p_release = 'Unknown'
 
-    return " ".join([
-            'python-requests/%s' % __version__,
-            '%s/%s' % (_implementation, _implementation_version),
-            '%s/%s' % (p_system, p_release),
-        ])
+    return " ".join(['python-requests/%s' % __version__,
+                     '%s/%s' % (_implementation, _implementation_version),
+                     '%s/%s' % (p_system, p_release)])
+
 
 def default_headers():
     return {
@@ -522,7 +522,7 @@ def parse_header_links(value):
 
         for param in params.split(";"):
             try:
-                key,value = param.split("=")
+                key, value = param.split("=")
             except ValueError:
                 break
 
index 6a4409b..1f399d9 100644 (file)
@@ -18,10 +18,12 @@ except ImportError:
 
 HTTPBIN = os.environ.get('HTTPBIN_URL', 'http://httpbin.org/')
 
+
 def httpbin(*suffix):
     """Returns url for HTTPBIN resource."""
     return HTTPBIN + '/'.join(suffix)
 
+
 class RequestsTestCase(unittest.TestCase):
 
     _multiprocess_can_split_ = True
@@ -57,14 +59,12 @@ class RequestsTestCase(unittest.TestCase):
         assert pr.url == req.url
         assert pr.body == 'life=42'
 
-
     def test_no_content_length(self):
         get_req = requests.Request('GET', httpbin('get')).prepare()
         self.assertTrue('Content-Length' not in get_req.headers)
         head_req = requests.Request('HEAD', httpbin('head')).prepare()
         self.assertTrue('Content-Length' not in head_req.headers)
 
-
     def test_path_is_not_double_encoded(self):
         request = requests.Request('GET', "http://0.0.0.0/get/test case").prepare()
 
@@ -113,16 +113,14 @@ class RequestsTestCase(unittest.TestCase):
     def test_user_agent_transfers(self):
 
         heads = {
-            'User-agent':
-                'Mozilla/5.0 (github.com/kennethreitz/requests)'
+            'User-agent': 'Mozilla/5.0 (github.com/kennethreitz/requests)'
         }
 
         r = requests.get(httpbin('user-agent'), headers=heads)
         self.assertTrue(heads['User-agent'] in r.text)
 
         heads = {
-            'user-agent':
-                'Mozilla/5.0 (github.com/kennethreitz/requests)'
+            'user-agent': 'Mozilla/5.0 (github.com/kennethreitz/requests)'
         }
 
         r = requests.get(httpbin('user-agent'), headers=heads)