# 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
builtin_str = str
str = str
bytes = bytes
- basestring = (str,bytes)
+ basestring = (str, bytes)
numeric_types = (int, float)
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
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
comment=None,
comment_url=None,
rest={'HttpOnly': None},
- rfc2109=False,
- )
+ rfc2109=False,)
badargs = set(kwargs) - set(result)
if badargs:
comment=morsel['comment'],
comment_url=bool(morsel['comment']),
rest={'HttpOnly': morsel['httponly']},
- rfc2109=False,
- )
+ rfc2109=False,)
return c
if _hook_data is not None:
hook_data = _hook_data
-
return hook_data
# 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]
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.
'%s/%s' % (platform.system(), platform.release()),
])
+
def parse_header_links(value):
"""Return a dict of parsed link headers proxies.
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():
#!/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('..'))
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__':
# time.sleep(1)
_httpbin = True
+
class TestBaseMixin(object):
def assertCookieHas(self, cookie, **kwargs):
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."""
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),
s.config['danger_mode'] = True
s.get(httpbin('redirect', '4'))
-
def test_empty_response(self):
r = requests.get(httpbin('status', '404'))
r.text
# -*- coding: utf-8 -*-
# Path hack.
-import sys, os
+import os
+import sys
sys.path.insert(0, os.path.abspath('..'))
import unittest
#!/usr/bin/env python
# -*- coding: utf-8 -*-
-import sys, os
-import json
+import os
+import sys
import unittest
# Path hack.