Skip to content
Myr

Merge pull request #1267 from sigmavirus24/master

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

One last pull request before 1.2 ideally

authored by Kenneth Reitz · committed by Kenneth Reitz · parents 6a2eea8, 325ea7b · Browse files · 4 files+84 added−8 removed
This commit

State

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

Diff stats

4 files+84 added−8 removed

  • other:+84 added−8 removed

4 files+84 added−8 removed

modified:requests/models.py+5 added-3 removed
347 unmodified lines
348 not isinstance(data, dict)349 ])350351 try:352 length = str(super_len(data))352 length = super_len(data)353 except (TypeError, AttributeError):354 length = False355356 if is_stream:
2 unmodified lines
359 if files:360 raise NotImplementedError('Streamed bodies and files are mutually exclusive.')361362 if length:363 self.headers['Content-Length'] = length363 self.headers['Content-Length'] = str(length)364 else:365 self.headers['Transfer-Encoding'] = 'chunked'366 # Check if file, fo, generator, iterator.367 # If not, run through normal process.
23 unmodified lines
391 body.seek(0, 2)392 self.headers['Content-Length'] = str(body.tell())393 body.seek(0, 0)394 elif body is not None:395 l = super_len(body)396 if l:395 self.headers['Content-Length'] = str(len(body))397 self.headers['Content-Length'] = str(l)398 elif self.method not in ('GET', 'HEAD'):399 self.headers['Content-Length'] = '0'400401 def prepare_auth(self, auth, url=''):
272 unmodified lines
modified:requests/sessions.py+43 added-4 removed
132 unmodified lines
133 method = 'GET'134135 prepared_request.method = method136137 if resp.status_code is not codes.temporary:137 # https://github.com/kennethreitz/requests/issues/1084138 if resp.status_code not in (codes.temporary, codes.resume):139 if 'Content-Length' in prepared_request.headers:140 del prepared_request.headers['Content-Length']141142 prepared_request.body = None
108 unmodified lines
251 hooks=None,252 stream=None,253 verify=None,254 cert=None):255 """Constructs a :class:`Request <Request>`, prepares it and sends it.256 Returns :class:`Response <Response>` object.257258 :param method: method for the new :class:`Request` object.259 :param url: URL for the new :class:`Request` object.260 :param params: (optional) Dictionary or bytes to be sent in the query261 string for the :class:`Request`.262 :param data: (optional) Dictionary or bytes to send in the body of the263 :class:`Request`.264 :param headers: (optional) Dictionary of HTTP Headers to send with the265 :class:`Request`.266 :param cookies: (optional) Dict or CookieJar object to send with the267 :class:`Request`.268 :param files: (optional) Dictionary of 'filename': file-like-objects269 for multipart encoding upload.270 :param auth: (optional) Auth tuple or callable to enable271 Basic/Digest/Custom HTTP Auth.272 :param timeout: (optional) Float describing the timeout of the273 request.274 :param allow_redirects: (optional) Boolean. Set to True by default.275 :param proxies: (optional) Dictionary mapping protocol to the URL of276 the proxy.277 :param return_response: (optional) If False, an un-sent Request object278 will returned.279 :param config: (optional) A configuration dictionary. See280 ``request.defaults`` for allowed keys and their default values.281 :param prefetch: (optional) whether to immediately download the response282 content. Defaults to ``True``.283 :param verify: (optional) if ``True``, the SSL cert will be verified.284 A CA_BUNDLE path can also be provided.285 :param cert: (optional) if String, path to ssl client cert file (.pem).286 If Tuple, ('cert', 'key') pair.287 """288289 cookies = cookies or {}290 proxies = proxies or {}291292 # Bootstrap CookieJar.
56 unmodified lines
349 'verify': verify,350 'cert': cert,351 'proxies': proxies,352 'allow_redirects': allow_redirects,319 'req': req,353 }354 resp = self.send(prep, **send_kwargs)355356 # Persist cookies.
71 unmodified lines
428 return self.request('DELETE', url, **kwargs)429430 def send(self, request, **kwargs):431 """Send a given PreparedRequest."""432 # Set defaults that the hooks can utilize to ensure they always have433 # the correct parameters to reproduce the previous request.434 kwargs.setdefault('stream', self.stream)435 kwargs.setdefault('verify', self.verify)436 kwargs.setdefault('cert', self.cert)437 kwargs.setdefault('proxies', self.proxies438439 # It's possible that users might accidentally send a Request object.440 # Guard against that specific failure case.441 if getattr(request, 'prepare', None):442 raise ValueError('You can only send PreparedRequests.')443444 # Set up variables needed for resolve_redirects and dispatching of445 # hooks446 allow_redirects = kwargs.pop('allow_redirects', True)407 req = kwargs.pop('req', None)408 stream = kwargs.get('stream', False)447 stream = kwargs.get('stream')448 timeout = kwargs.get('timeout')449 verify = kwargs.get('verify')450 cert = kwargs.get('cert')451 proxies = kwargs.get('proxies')
64 unmodified lines
modified:HISTORY.rst+28 added
1 unmodified line
23History4-------561.2.0 (2013-03-xx)7++++++++++++++++++89- Fixed cookies on sessions and on requests10- Significantly change how hooks are dispatched - hooks now receive all the 11 arguments specified by the user when making a request so hooks can make a 12 secondary request with the same parameters. This is especially necessary for 13 authentication handler authors14- certifi support was removed15- Fixed bug where using OAuth 1 with body ``signature_type`` sent no data16- Major proxy work thanks to @Lukasa including parsing of proxy authentication 17 from the proxy url18- Fix DigestAuth handling too many 401s19- Update vendored urllib3 to include SSL bug fixes20- Allow keyword arguments to be passed to ``json.loads()`` via the 21 ``Response.json()`` method22- Don't send ``Content-Length`` header by default on ``GET`` or ``HEAD`` 23 requests24- Add ``elapsed`` attribute to ``Response`` objects to time how long a request 25 took.26- Fix ``RequestsCookieJar``27- Sessions and Adapters are now picklable, i.e., can be used with the 28 mutiprocessing library29- Update charade to version 1.0.33031The change in how hooks are dispatched will likely cause a great deal of 32issues.33341.1.0 (2013-01-10)35++++++++++++++++++3637- CHUNKED REQUESTS
601 unmodified lines
modified:test_requests.py+8 added-1 removed
293 unmodified lines
294 'text/py-content-type')})295 self.assertEqual(r.status_code, 200)296 self.assertTrue(b"text/py-content-type" in r.request.body)297298 def test_hook_receives_request_arguments(self):299 def hook(resp, **kwargs):300 assert resp is not None301 assert kwargs != {}302303 requests.Request('GET', HTTPBIN, hooks={'response': hook})304305 def test_prepared_request_hook(self):299 def hook(resp):306 def hook(resp, **kwargs):307 resp.hook_working = True308 return resp309310 req = requests.Request('GET', HTTPBIN, hooks={'response': hook})
94 unmodified lines