keepalive: use getattr to avoid AttributeErrors when vcr is in use
authorAugie Fackler <augie@google.com>
Fri, 19 Oct 2018 11:45:51 -0400
changeset 40379 41506e3b04ee
parent 40378 b015f30a91fb
child 40380 1ce4fe0603a6
keepalive: use getattr to avoid AttributeErrors when vcr is in use Fixes test-phabricator.t. Differential Revision: https://phab.mercurial-scm.org/D5160
mercurial/keepalive.py
--- a/mercurial/keepalive.py	Fri Oct 19 11:45:25 2018 -0400
+++ b/mercurial/keepalive.py	Fri Oct 19 11:45:51 2018 -0400
@@ -315,7 +315,7 @@
         return r
 
     def _start_transaction(self, h, req):
-        oldbytescount = h.sentbytescount
+        oldbytescount = getattr(h, 'sentbytescount', 0)
 
         # What follows mostly reimplements HTTPConnection.request()
         # except it adds self.parent.addheaders in the mix and sends headers
@@ -353,11 +353,12 @@
 
         # This will fail to record events in case of I/O failure. That's OK.
         self.requestscount += 1
-        self.sentbytescount += h.sentbytescount - oldbytescount
+        self.sentbytescount += getattr(h, 'sentbytescount', 0) - oldbytescount
 
         try:
             self.parent.requestscount += 1
-            self.parent.sentbytescount += h.sentbytescount - oldbytescount
+            self.parent.sentbytescount += (
+                getattr(h, 'sentbytescount', 0) - oldbytescount)
         except AttributeError:
             pass