From 478d49027fe920e334ae8eacd1182ede39f8b5f7 Mon Sep 17 00:00:00 2001 From: Ian Cordasco Date: Wed, 27 Mar 2013 23:17:34 -0400 Subject: [PATCH] Add correct defaults in Session.send() Resolves #1258 Also fixed the tests to reflect the necessary changes. --- requests/sessions.py | 8 +++++--- test_requests.py | 9 ++++++++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/requests/sessions.py b/requests/sessions.py index fe0a84e1..ab56464b 100644 --- a/requests/sessions.py +++ b/requests/sessions.py @@ -316,7 +316,6 @@ class Session(SessionRedirectMixin): 'cert': cert, 'proxies': proxies, 'allow_redirects': allow_redirects, - 'req': req, } resp = self.send(prep, **send_kwargs) @@ -398,14 +397,17 @@ class Session(SessionRedirectMixin): """Send a given PreparedRequest.""" # It's possible that users might accidentally send a Request object. # Guard against that specific failure case. + kwargs.setdefault('stream', False) + kwargs.setdefault('verify', True) + kwargs.setdefault('proxies', {}) + if getattr(request, 'prepare', None): raise ValueError('You can only send PreparedRequests.') # Set up variables needed for resolve_redirects and dispatching of # hooks allow_redirects = kwargs.pop('allow_redirects', True) - req = kwargs.pop('req', None) - stream = kwargs.get('stream', False) + stream = kwargs.get('stream') timeout = kwargs.get('timeout') verify = kwargs.get('verify') cert = kwargs.get('cert') diff --git a/test_requests.py b/test_requests.py index 64003cfc..93b81236 100644 --- a/test_requests.py +++ b/test_requests.py @@ -295,8 +295,15 @@ class RequestsTestCase(unittest.TestCase): self.assertEqual(r.status_code, 200) self.assertTrue(b"text/py-content-type" in r.request.body) + def test_hook_receives_request_arguments(self): + def hook(resp, **kwargs): + assert resp is not None + assert kwargs != {} + + requests.Request('GET', HTTPBIN, hooks={'response': hook}) + def test_prepared_request_hook(self): - def hook(resp): + def hook(resp, **kwargs): resp.hook_working = True return resp