Fix python3 tests.
authorIan Cordasco <graffatcolmingov@gmail.com>
Sat, 18 Aug 2012 18:41:13 +0000 (14:41 -0400)
committerIan Cordasco <graffatcolmingov@gmail.com>
Sat, 18 Aug 2012 18:41:13 +0000 (14:41 -0400)
I wasn't thorough enough with how I dealt with headers. Most of the header
logic in the Request object utilizes dictionary properties which will not work
with a key/value list.

I'll dig more into this, but I know the rest of the features are more
important so I'll take my time on this and send a separate pull request.

requests/sessions.py
tests/test_requests.py

index cd6daa6..cd05490 100644 (file)
@@ -72,7 +72,8 @@ class Session(object):
         verify=True,
         cert=None):
 
-        self.headers = to_key_val_list(headers or [])
+        #self.headers = to_key_val_list(headers or [])
+        self.headers = headers or {}
         self.auth = auth
         self.timeout = timeout
         self.proxies = to_key_val_list(proxies or [])
@@ -160,7 +161,7 @@ class Session(object):
         # Default empty dicts for dict params.
         data = [] if data is None else data
         files = [] if files is None else files
-        headers = [] if headers is None else headers
+        headers = {} if headers is None else headers
         params = [] if params is None else params
         hooks = {} if hooks is None else hooks
         prefetch = prefetch if prefetch is not None else self.prefetch
@@ -171,10 +172,10 @@ class Session(object):
 
         # Expand header values.
         if headers:
-            expanded = []
-            for k, v in to_key_val_list(headers):
-                expanded.append((k, header_expand(v)))
-            headers = expanded
+            #e = [(k, header_expand(v)) for k, v in to_key_val_list(headers)]
+            #headers = e
+            for k, v in list(headers.items()) or {}:
+                headers[k] = header_expand(v)
 
         args = dict(
             method=method,
index b7dba36..29ea980 100755 (executable)
@@ -977,7 +977,7 @@ class RequestsTestSuite(TestSetup, TestBaseMixin, unittest.TestCase):
             # Don't choke on headers with none in the value.
             requests.get(httpbin('headers'), headers={'Foo': None})
         except TypeError:
-            self.fail()
+            self.fail('Not able to have none in header values')
 
     def test_danger_mode_redirects(self):
         s = requests.session()