Skip to content
Myr

Merge pull request #1138 from clee/master

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

Time each request

authored by Kenneth Reitz · committed by Kenneth Reitz · parents ac5e680, 3183008 · Browse files · 3 files+14 added−0 removed
This commit

State

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

Diff stats

3 files+14 added−0 removed

  • other:+14 added−0 removed

3 files+14 added−0 removed

modified:requests/adapters.py+4 added
7 unmodified lines
8and maintain connections.9"""1011import socket12import datetime1314from .models import Response15from .packages.urllib3.poolmanager import PoolManager, ProxyManager16from .packages.urllib3.response import HTTPResponse
138 unmodified lines
155 self.cert_verify(conn, request.url, verify, cert)156 url = self.request_url(request, proxies)157158 chunked = not (request.body is None or 'Content-Length' in request.headers)159 start = datetime.datetime.utcnow()160161 try:162 if not chunked:163 resp = conn.urlopen(
35 unmodified lines
199 connection=low_conn,200 preload_content=False,201 decode_content=False202 )203 finish = datetime.datetime.utcnow()204205 except socket.error as sockerr:206 raise ConnectionError(sockerr)207
8 unmodified lines
216 else:217 raise Timeout('Request timed out.')218219 r = self.build_response(request, resp)220 r.elapsed = finish - start221222 if not stream:223 r.content224
1 unmodified line
modified:requests/models.py+5 added
7 unmodified lines
8"""910import collections11import logging12import datetime1314from io import BytesIO15from .hooks import default_hooks16from .structures import CaseInsensitiveDict
454 unmodified lines
471472 #: A CookieJar of Cookies the server sent back.473 self.cookies = cookiejar_from_dict({})474475 #: The amount of time elapsed between sending the request476 #: and the arrival of the response (as a timedelta)477 self.elapsed = datetime.timedelta(0)478479 def __repr__(self):480 return '<Response [%s]>' % (self.status_code)481482 def __bool__(self):
182 unmodified lines
modified:test_requests.py+5 added
321 unmodified lines
322 self.assertEqual(cookie.secure, secure)323 self.assertEqual(cookie.domain, domain)324 self.assertEqual(cookie._rest['HttpOnly'], rest['HttpOnly'])325326 def test_time_elapsed_blank(self):327 r = requests.get(httpbin('get'))328 self.assertTrue(r.elapsed.total_seconds() > 0.0)329330331if __name__ == '__main__':332 unittest.main()