Skip to content
Myr

params now accepts a k/v list.

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Also added test for params accepting k/v lists.

authored by Ian Cordasco · committed by Ian Cordasco · parent 644c6f9 · Browse files · 2 files+16 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+16 added−2 removed

  • tests:+5 added−0 removed
  • other:+11 added−2 removed

2 files+16 added−2 removed

modified:requests/sessions.py+11 added-2 removed
16 unmodified lines
17from .hooks import dispatch_hook18from .utils import header_expand19from .packages.urllib3.poolmanager import PoolManager202122def merge_kwargs(local_kwarg, default_kwarg):23 """Merges kwarg dictionaries.2425 If a local key in the dictionary is set to None, it will be removed.
11 unmodified lines
37 # Bypass if not a dictionary (e.g. timeout)38 if not hasattr(default_kwarg, 'items'):39 return local_kwarg4041 try:42 dict(local_kwarg)43 except ValueError:44 raise ValueError('Unable to encode lists with elements that are not '45 '2-tuples.')4647 if hasattr(local_kwarg, 'items'):48 local_kwarg = list(local_kwarg.items())4950 # Update new values.51 kwargs = default_kwarg.copy()52 kwargs.update(local_kwarg)5354 # Remove keys that are set to None.45 for (k, v) in list(local_kwarg.items()):55 for (k, v) in local_kwarg:56 if v is None:57 del kwargs[k]5859 return kwargs
5 unmodified lines
65 __attrs__ = [66 'headers', 'cookies', 'auth', 'timeout', 'proxies', 'hooks',67 'params', 'config', 'verify', 'cert', 'prefetch']685969 def __init__(self,70 headers=None,71 cookies=None,72 auth=None,
261 unmodified lines
modified:tests/test_requests.py+5 added
94 unmodified lines
95 "http://example.com/path?key=value#fragment", params={"a": "b"})96 self.assertEqual(request.full_url,97 "http://example.com/path?key=value&a=b#fragment")9899 def test_params_accepts_kv_list(self):100 request = requests.Request('http://example.com/path',101 params=[('a', 'b')])102 self.assertEqual(request.full_url, 'http://example.com/path?a=b')103104 def test_HTTP_200_OK_GET(self):105 r = get(httpbin('get'))106 self.assertEqual(r.status_code, 200)107
926 unmodified lines