Use timedelta and change attribute name back to elapsed
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Chris Lee · committed by Chris Lee · parent d4aaef1 · Browse files · 3 files·+10 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
3 files+10 added−8 removed
- other:+10 added−8 removed
Provenance
- Commit
3183008- Tree
f597aec- Author
Chris Lee <clee@mg8.org>- Committer
Chris Lee <clee@mg8.org>- Parent
d4aaef1
3 files changed+10 added−8 removed
modified:requests/adapters.py+4 added-4 removed
7 unmodified lines8 and maintain connections.9 """10 11 import socket12-import time12+import datetime13 14 from .models import Response15 from .packages.urllib3.poolmanager import PoolManager, ProxyManager16 from .packages.urllib3.response import HTTPResponse138 unmodified lines155 self.cert_verify(conn, request.url, verify, cert)156 url = self.request_url(request, proxies)157 158 chunked = not (request.body is None or 'Content-Length' in request.headers)159- start = time.time()159+ start = datetime.datetime.utcnow()160 161 try:162 if not chunked:163 resp = conn.urlopen(35 unmodified lines199 connection=low_conn,200 preload_content=False,201 decode_content=False202 )203- finish = time.time()203+ finish = datetime.datetime.utcnow()204 205 except socket.error as sockerr:206 raise ConnectionError(sockerr)207 8 unmodified lines216 else:217 raise Timeout('Request timed out.')218 219 r = self.build_response(request, resp)220- r.time_taken = finish - start220+ r.elapsed = finish - start221 222 if not stream:223 r.content224 1 unmodified linemodified:requests/models.py+4 added-2 removed
7 unmodified lines8 """9 10 import collections11 import logging12+import datetime13 14 from io import BytesIO15 from .hooks import default_hooks16 from .structures import CaseInsensitiveDict454 unmodified lines471 472 #: A CookieJar of Cookies the server sent back.473 self.cookies = cookiejar_from_dict({})474 474- #: The amount of time taken for the response to arrive (in seconds).475- self.time_taken = 0.0475+ #: The amount of time elapsed between sending the request476+ #: and the arrival of the response (as a timedelta)477+ self.elapsed = datetime.timedelta(0)478 479 def __repr__(self):480 return '<Response [%s]>' % (self.status_code)481 183 unmodified linesmodified:test_requests.py+2 added-2 removed
321 unmodified lines322 self.assertEqual(cookie.secure, secure)323 self.assertEqual(cookie.domain, domain)324 self.assertEqual(cookie._rest['HttpOnly'], rest['HttpOnly'])325 326- def test_time_taken_blank(self):326+ def test_time_elapsed_blank(self):327 r = requests.get(httpbin('get'))328- self.assertTrue(r.time_taken > 0.0)328+ self.assertTrue(r.elapsed.total_seconds() > 0.0)329 330 331 if __name__ == '__main__':332 unittest.main()