params now accepts a k/v list.
authorIan Cordasco <graffatcolmingov@gmail.com>
Sat, 4 Aug 2012 02:04:43 +0000 (22:04 -0400)
committerIan Cordasco <graffatcolmingov@gmail.com>
Sat, 4 Aug 2012 02:24:52 +0000 (22:24 -0400)
Also added test for params accepting k/v lists.

requests/sessions.py
tests/test_requests.py

index 3113c78..ee47a01 100644 (file)
@@ -18,6 +18,7 @@ from .hooks import dispatch_hook
 from .utils import header_expand
 from .packages.urllib3.poolmanager import PoolManager
 
+
 def merge_kwargs(local_kwarg, default_kwarg):
     """Merges kwarg dictionaries.
 
@@ -37,12 +38,21 @@ def merge_kwargs(local_kwarg, default_kwarg):
     if not hasattr(default_kwarg, 'items'):
         return local_kwarg
 
+    try:
+        dict(local_kwarg)
+    except ValueError:
+        raise ValueError('Unable to encode lists with elements that are not '
+                '2-tuples.')
+
+    if hasattr(local_kwarg, 'items'):
+        local_kwarg = list(local_kwarg.items())
+
     # Update new values.
     kwargs = default_kwarg.copy()
     kwargs.update(local_kwarg)
 
     # Remove keys that are set to None.
-    for (k, v) in list(local_kwarg.items()):
+    for (k, v) in local_kwarg:
         if v is None:
             del kwargs[k]
 
@@ -56,7 +66,6 @@ class Session(object):
         'headers', 'cookies', 'auth', 'timeout', 'proxies', 'hooks',
         'params', 'config', 'verify', 'cert', 'prefetch']
 
-
     def __init__(self,
         headers=None,
         cookies=None,
index 4e0d034..076ca6c 100755 (executable)
@@ -96,6 +96,11 @@ class RequestsTestSuite(TestSetup, TestBaseMixin, unittest.TestCase):
         self.assertEqual(request.full_url,
             "http://example.com/path?key=value&a=b#fragment")
 
+    def test_params_accepts_kv_list(self):
+        request = requests.Request('http://example.com/path',
+                params=[('a', 'b')])
+        self.assertEqual(request.full_url, 'http://example.com/path?a=b')
+
     def test_HTTP_200_OK_GET(self):
         r = get(httpbin('get'))
         self.assertEqual(r.status_code, 200)