]> git.ipfire.org Git - thirdparty/dnspython.git/commitdiff
Return timeout duration as part of str(Timeout).
authorPetr Spacek <pspacek@redhat.com>
Thu, 19 Mar 2015 17:02:08 +0000 (18:02 +0100)
committerPetr Viktorin <pviktori@redhat.com>
Thu, 21 May 2015 12:25:12 +0000 (14:25 +0200)
dns/exception.py
dns/resolver.py

index 4f7df346a0b4085916453818d71c9b4b72689ef1..cbcdb57c82cd61bb2de1332b120df5d86ecfed72 100644 (file)
@@ -110,3 +110,5 @@ class TooBig(DNSException):
 
 class Timeout(DNSException):
     """The DNS operation timed out."""
+    supp_kwargs = set(['timeout'])
+    fmt = "%s after {timeout} seconds" % __doc__[:-1]
index 387bd500660923f5715c8777217b9138bdecbb83..31f44fe1066d385b2d1077fa3fc18e69128a1fa3 100644 (file)
@@ -742,18 +742,18 @@ class Resolver(object):
 
     def _compute_timeout(self, start):
         now = time.time()
-        if now < start:
-            if start - now > 1:
+        duration = now - start
+        if duration < 0:
+            if duration < -1:
                 # Time going backwards is bad.  Just give up.
-                raise Timeout
+                raise Timeout(timeout=duration)
             else:
                 # Time went backwards, but only a little.  This can
                 # happen, e.g. under vmware with older linux kernels.
                 # Pretend it didn't happen.
                 now = start
-        duration = now - start
         if duration >= self.lifetime:
-            raise Timeout
+            raise Timeout(timeout=duration)
         return min(self.lifetime - duration, self.timeout)
 
     def query(self, qname, rdtype=dns.rdatatype.A, rdclass=dns.rdataclass.IN,