Merge pull request #887 from rvoicilas/develop
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Small changes to make the code more PEP8 compliant
authored by Kenneth Reitz · committed by Kenneth Reitz · parents 2363243, 820dfb0 · Browse files · 11 files·+30 added−22 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
11 files+30 added−22 removed
- tests:+19 added−11 removed
- other:+11 added−11 removed
Provenance
- Commit
c631627- Tree
59d012f- Author
Kenneth Reitz <me@kennethreitz.com>- Committer
Kenneth Reitz <me@kennethreitz.com>- Parent 1
2363243- Parent 2
820dfb0
11 files changed+30 added−22 removed
modified:requests/auth.py+1 added-1 removed
92 unmodified lines93 # be empty (cant add paras to body if multipart) and we wish94 # to preserve body.95 r.url, r.headers, _ = self.client.sign(96 unicode(r.full_url), unicode(r.method), None, r.headers)97- elif decoded_body != None and contenttype in (CONTENT_TYPE_FORM_URLENCODED, ''):97+ elif decoded_body is not None and contenttype in (CONTENT_TYPE_FORM_URLENCODED, ''):98 # Normal signing99 if not contenttype:100 r.headers['Content-Type'] = CONTENT_TYPE_FORM_URLENCODED101 r.url, r.headers, r.data = self.client.sign(281 unmodified linesmodified:requests/compat.py+1 added-1 removed
113 unmodified lines114 115 builtin_str = str116 str = str117 bytes = bytes118- basestring = (str,bytes)118+ basestring = (str, bytes)119 numeric_types = (int, float)modified:requests/cookies.py+4 added-6 removed
233 unmodified lines234 """Takes as an argument an optional domain and path and returns a plain old235 Python dict of name-value pairs of cookies that meet the requirements."""236 dictionary = {}237 for cookie in iter(self):238- if (domain == None or cookie.domain == domain) and (path == None238+ if (domain is None or cookie.domain == domain) and (path is None239 or cookie.path == path):240 dictionary[cookie.name] = cookie.value241 return dictionary242 35 unmodified lines278 for cookie in iter(self):279 if cookie.name == name:280 if domain is None or cookie.domain == domain:281 if path is None or cookie.path == path:282- if toReturn != None: # if there are multiple cookies that meet passed in criteria282+ if toReturn is not None: # if there are multiple cookies that meet passed in criteria283 raise CookieConflictError('There are multiple cookies with name, %r' % (name))284 toReturn = cookie.value # we will eventually return this as long as no cookie conflict285 286 if toReturn:36 unmodified lines323 discard=True,324 comment=None,325 comment_url=None,326 rest={'HttpOnly': None},327- rfc2109=False,328- )327+ rfc2109=False,)328 329 badargs = set(kwargs) - set(result)330 if badargs:331 err = 'create_cookie() got unexpected keyword arguments: %s'26 unmodified lines358 discard=False,359 comment=morsel['comment'],360 comment_url=bool(morsel['comment']),361 rest={'HttpOnly': morsel['httponly']},363- rfc2109=False,364- )362+ rfc2109=False,)363 return c364 365 366 def cookiejar_from_dict(cookie_dict, cookiejar=None):11 unmodified linesmodified:requests/hooks.py-1 removed
43 unmodified lines44 _hook_data = hook(hook_data)45 if _hook_data is not None:46 hook_data = _hook_data47 48-48 return hook_datamodified:requests/models.py+1 added-1 removed
109 unmodified lines110 111 # Dictionary mapping protocol to the URL of the proxy (e.g. {'http': 'foo.bar:3128'})112 self.proxies = dict(proxies or [])113 114- for proxy_type,uri_ref in list(self.proxies.items()):114+ for proxy_type, uri_ref in list(self.proxies.items()):115 if not uri_ref:116 del self.proxies[proxy_type]117 118 # If no proxies are given, allow configuration by environment variables774 unmodified linesmodified:requests/utils.py+4 added-1 removed
376 unmodified lines377 rv = decoder.decode('', final=True)378 if rv:379 yield rv380 381+382 def iter_slices(string, slice_length):383 """Iterate over slices of a string."""384 pos = 0385 while pos < len(string):385- yield string[pos:pos+slice_length]386+ yield string[pos:pos + slice_length]387 pos += slice_length388 389+390 def get_unicode_from_response(r):391 """Returns the requested content back in unicode.392 393 :param r: Response object to get unicode content from.150 unmodified lines544 '%s/%s' % (_implementation, _implementation_version),545 '%s/%s' % (platform.system(), platform.release()),546 ])547 548+549 def parse_header_links(value):550 """Return a dict of parsed link headers proxies.551 552 i.e. Link: <http:/.../front.jpeg>; rel=front; type="image/jpeg",<http://.../back.jpeg>; rel=back;type="image/jpeg"28 unmodified linesmodified:tests/informal/test_leaked_connections.py+5 added-1 removed
2 unmodified lines3 it verifies that Requests does not leak connections when4 the body of the request is not read.5 """6 7-import gc, os, subprocess, requests, sys7+import gc8+import os9+import requests10+import subprocess11+import sys12 13 14 def main():15 gc.disable()16 unmodified linesmodified:tests/test_proxies.py+7 added-5 removed
1 #!/usr/bin/env python2 # -*- coding: utf-8 -*-3 4-import sys, os, unittest4+import os5+import sys6+import unittest7 8 # Path hack.9 sys.path.insert(0, os.path.abspath('..'))10 import requests4 unmodified lines15 16 smoke_url = "https://github.com"17 18 def test_empty_https_proxy(self):17- proxy = {"https" : "" }18- result = requests.get(self.smoke_url, verify=False, proxies = proxy)19+ proxy = {"https": ""}20+ result = requests.get(self.smoke_url, verify=False, proxies=proxy)21 self.assertEqual(result.status_code, 200)22 23 def test_empty_http_proxy(self):22- proxy = {"http" : "" }23- result = requests.get(self.smoke_url, proxies = proxy)24+ proxy = {"http": ""}25+ result = requests.get(self.smoke_url, proxies=proxy)26 self.assertEqual(result.status_code, 200)27 28 if __name__ == '__main__':29 unittest.main()modified:tests/test_requests_ext.py+2 added-1 removed
1 #!/usr/bin/env python2 # -*- coding: utf-8 -*-3 4 # Path hack.5-import sys, os5+import os6+import sys7 sys.path.insert(0, os.path.abspath('..'))8 9 import unittest10 114 unmodified linesmodified:tests/test_requests_https.py+2 added-2 removed
1 #!/usr/bin/env python2 # -*- coding: utf-8 -*-3 4-import sys, os5-import json4+import os5+import sys6 import unittest7 8 # Path hack.9 sys.path.insert(0, os.path.abspath('..'))23 unmodified linesmodified:tests/test_requests.py+3 added-2 removed
49 unmodified lines50 # c = envoy.connect('httpbin %s' % (PORT))51 # time.sleep(1)52 _httpbin = True53 54+55 class TestBaseMixin(object):56 57 def assertCookieHas(self, cookie, **kwargs):58 """Assert that a cookie has various specified properties."""1 unmodified line60 cookie_attr = getattr(cookie, attr)61 message = 'Failed comparison for %s: %s != %s' % (attr, cookie_attr, expected_value)62 self.assertEqual(cookie_attr, expected_value, message)63 64+65 class RequestsTestSuite(TestSetup, TestBaseMixin, unittest.TestCase):66 """Requests test cases."""67 68 def test_entry_points(self):835 unmodified lines904 905 def test_connection_error_with_safe_mode(self):906 config = {'safe_mode': True}907 r = get('http://localhost:1/nope', allow_redirects=False, config=config)906- assert r.content == None908+ assert r.content is None909 910 # def test_invalid_content(self):911 # # WARNING: if you're using a terrible DNS provider (comcast),912 # # this will fail.126 unmodified lines1039 s = requests.session()1040 s.config['danger_mode'] = True1041 s.get(httpbin('redirect', '4'))1042 1041-1043 def test_empty_response(self):1044 r = requests.get(httpbin('status', '404'))1045 r.text1046 138 unmodified lines