Making the code more PEP8 compliant
authorRadu Voicilas <radu.voicilas@gmail.com>
Mon, 8 Oct 2012 21:41:42 +0000 (00:41 +0300)
committerRadu Voicilas <radu.voicilas@gmail.com>
Mon, 8 Oct 2012 21:42:49 +0000 (00:42 +0300)
requests/auth.py
requests/compat.py
requests/cookies.py
requests/hooks.py
requests/models.py
requests/utils.py
tests/informal/test_leaked_connections.py
tests/test_proxies.py
tests/test_requests.py
tests/test_requests_ext.py
tests/test_requests_https.py

index 6c5264e46095f11be7a1f0fb36d4cc02119d430f..65568f527780b299f291b3ebd0c066615c02a1dc 100644 (file)
@@ -94,7 +94,7 @@ class OAuth1(AuthBase):
             # to preserve body.
             r.url, r.headers, _ = self.client.sign(
                 unicode(r.full_url), unicode(r.method), None, r.headers)
-        elif decoded_body != None and contenttype in (CONTENT_TYPE_FORM_URLENCODED, ''):
+        elif decoded_body is not None and contenttype in (CONTENT_TYPE_FORM_URLENCODED, ''):
             # Normal signing
             if not contenttype:
                 r.headers['Content-Type'] = CONTENT_TYPE_FORM_URLENCODED
index 351b7c6e03070523b963d9adc71ef2b89a0fa574..69dd25c5b736b6145dd7ce1a55a49d46d392bfcf 100644 (file)
@@ -115,5 +115,5 @@ elif is_py3:
     builtin_str = str
     str = str
     bytes = bytes
-    basestring = (str,bytes)
+    basestring = (str, bytes)
     numeric_types = (int, float)
index 241ca6798adeeac828a01c599ebe04e25da27856..c3c2debb7a5cafb0978e03988b7813536f3c8dcc 100644 (file)
@@ -235,7 +235,7 @@ class RequestsCookieJar(cookielib.CookieJar, collections.MutableMapping):
         Python dict of name-value pairs of cookies that meet the requirements."""
         dictionary = {}
         for cookie in iter(self):
-            if (domain == None or cookie.domain == domain) and (path == None
+            if (domain is None or cookie.domain == domain) and (path is None
                                                 or cookie.path == path):
                 dictionary[cookie.name] = cookie.value
         return dictionary
@@ -279,7 +279,7 @@ class RequestsCookieJar(cookielib.CookieJar, collections.MutableMapping):
             if cookie.name == name:
                 if domain is None or cookie.domain == domain:
                     if path is None or cookie.path == path:
-                        if toReturn != None:  # if there are multiple cookies that meet passed in criteria
+                        if toReturn is not None:  # if there are multiple cookies that meet passed in criteria
                             raise CookieConflictError('There are multiple cookies with name, %r' % (name))
                         toReturn = cookie.value  # we will eventually return this as long as no cookie conflict
 
@@ -324,8 +324,7 @@ def create_cookie(name, value, **kwargs):
         comment=None,
         comment_url=None,
         rest={'HttpOnly': None},
-        rfc2109=False,
-        )
+        rfc2109=False,)
 
     badargs = set(kwargs) - set(result)
     if badargs:
@@ -360,8 +359,7 @@ def morsel_to_cookie(morsel):
         comment=morsel['comment'],
         comment_url=bool(morsel['comment']),
         rest={'HttpOnly': morsel['httponly']},
-        rfc2109=False,
-        )
+        rfc2109=False,)
     return c
 
 
index 9e0ce3462e9536bb3f9478407b378b1aff596a6c..9a35fb169c6fa8dfc8b3cd97285ffdc24f94855d 100644 (file)
@@ -45,5 +45,4 @@ def dispatch_hook(key, hooks, hook_data):
             if _hook_data is not None:
                 hook_data = _hook_data
 
-
     return hook_data
index 78311491cd1d873896235d2dd0a618a54882a441..f02cec33dadfeffd73378c6c7441f44619a35384 100644 (file)
@@ -111,7 +111,7 @@ class Request(object):
         # Dictionary mapping protocol to the URL of the proxy (e.g. {'http': 'foo.bar:3128'})
         self.proxies = dict(proxies or [])
 
-        for proxy_type,uri_ref in list(self.proxies.items()):
+        for proxy_type, uri_ref in list(self.proxies.items()):
             if not uri_ref:
                 del self.proxies[proxy_type]
 
index 63b281a25ccf66a71fc08adeee75bdb205220ddf..7c895c4b98a5dee42303d8e33b360e821f621226 100644 (file)
@@ -378,13 +378,15 @@ def stream_decode_response_unicode(iterator, r):
     if rv:
         yield rv
 
+
 def iter_slices(string, slice_length):
     """Iterate over slices of a string."""
     pos = 0
     while pos < len(string):
-        yield string[pos:pos+slice_length]
+        yield string[pos:pos + slice_length]
         pos += slice_length
 
+
 def get_unicode_from_response(r):
     """Returns the requested content back in unicode.
 
@@ -543,6 +545,7 @@ def default_user_agent():
             '%s/%s' % (platform.system(), platform.release()),
         ])
 
+
 def parse_header_links(value):
     """Return a dict of parsed link headers proxies.
 
index 438a6ceea5e17366f979425959efc0cf0a5b41cd..37d964cf802704a5837a7555883af5af42eb84b8 100644 (file)
@@ -4,7 +4,11 @@ it verifies that Requests does not leak connections when
 the body of the request is not read.
 """
 
-import gc, os, subprocess, requests, sys
+import gc
+import os
+import requests
+import subprocess
+import sys
 
 
 def main():
index 8ab124b24a0c81b66da79f5d0c38fad973364684..5aa5bf3635c6d4fe951ec70534d56ffd2144319c 100644 (file)
@@ -1,7 +1,9 @@
 #!/usr/bin/env python
 # -*- coding: utf-8 -*-
 
-import sys, os, unittest
+import os
+import sys
+import unittest
 
 # Path hack.
 sys.path.insert(0, os.path.abspath('..'))
@@ -14,13 +16,13 @@ class HTTPSProxyTest(unittest.TestCase):
     smoke_url = "https://github.com"
 
     def test_empty_https_proxy(self):
-        proxy = {"https" : "" }
-        result = requests.get(self.smoke_url, verify=False, proxies = proxy)
+        proxy = {"https": ""}
+        result = requests.get(self.smoke_url, verify=False, proxies=proxy)
         self.assertEqual(result.status_code, 200)
 
     def test_empty_http_proxy(self):
-        proxy = {"http" : "" }
-        result = requests.get(self.smoke_url, proxies = proxy)
+        proxy = {"http": ""}
+        result = requests.get(self.smoke_url, proxies=proxy)
         self.assertEqual(result.status_code, 200)
 
 if __name__ == '__main__':
index 3d6f49c29392a9036274b1761b892c8ef9ca1a57..9ed4ad037f40f105fb082e6bfb59d6826d84a723 100755 (executable)
@@ -51,6 +51,7 @@ class TestSetup(object):
             # time.sleep(1)
             _httpbin = True
 
+
 class TestBaseMixin(object):
 
     def assertCookieHas(self, cookie, **kwargs):
@@ -60,6 +61,7 @@ class TestBaseMixin(object):
             message = 'Failed comparison for %s: %s != %s' % (attr, cookie_attr, expected_value)
             self.assertEqual(cookie_attr, expected_value, message)
 
+
 class RequestsTestSuite(TestSetup, TestBaseMixin, unittest.TestCase):
     """Requests test cases."""
 
@@ -903,7 +905,7 @@ class RequestsTestSuite(TestSetup, TestBaseMixin, unittest.TestCase):
     def test_connection_error_with_safe_mode(self):
         config = {'safe_mode': True}
         r = get('http://localhost:1/nope', allow_redirects=False, config=config)
-        assert r.content == None
+        assert r.content is None
 
     # def test_invalid_content(self):
     #     # WARNING: if you're using a terrible DNS provider (comcast),
@@ -1038,7 +1040,6 @@ class RequestsTestSuite(TestSetup, TestBaseMixin, unittest.TestCase):
         s.config['danger_mode'] = True
         s.get(httpbin('redirect', '4'))
 
-
     def test_empty_response(self):
         r = requests.get(httpbin('status', '404'))
         r.text
index 208803a771673d888bbd08f57d1767da60fe3242..e3cdd04e52f83cb4860923d7b909e67c8232545f 100644 (file)
@@ -2,7 +2,8 @@
 # -*- coding: utf-8 -*-
 
 # Path hack.
-import sys, os
+import os
+import sys
 sys.path.insert(0, os.path.abspath('..'))
 
 import unittest
index 1691a8c03f4af3e295eca60fda0d132f99871e30..2da09824af81e5ecf08f0d8115fa2fe3f0fea0bb 100755 (executable)
@@ -1,8 +1,8 @@
 #!/usr/bin/env python
 # -*- coding: utf-8 -*-
 
-import sys, os
-import json
+import os
+import sys
 import unittest
 
 # Path hack.