From: Petr Spacek Date: Thu, 19 Mar 2015 17:02:08 +0000 (+0100) Subject: Return timeout duration as part of str(Timeout). X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=33f4ef8257950891690af5b648c4e58b4850e0df;p=thirdparty%2Fdnspython.git Return timeout duration as part of str(Timeout). --- diff --git a/dns/exception.py b/dns/exception.py index 4f7df346..cbcdb57c 100644 --- a/dns/exception.py +++ b/dns/exception.py @@ -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] diff --git a/dns/resolver.py b/dns/resolver.py index 387bd500..31f44fe1 100644 --- a/dns/resolver.py +++ b/dns/resolver.py @@ -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,