mirror of
https://github.com/kennethreitz/requests.git
synced 2026-06-05 22:50:18 +00:00
params now accepts a k/v list.
Also added test for params accepting k/v lists.
This commit is contained in:
+11
-2
@@ -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,
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user