diff options
| author | Petr Spacek <pspacek@redhat.com> | 2015-03-19 18:02:08 +0100 |
|---|---|---|
| committer | Petr Viktorin <pviktori@redhat.com> | 2015-05-21 14:25:12 +0200 |
| commit | 33f4ef8257950891690af5b648c4e58b4850e0df (patch) | |
| tree | 47088a5c758383aa83649f00fc4dc5e030b94e67 | |
| parent | 1a2566c274834aacba20f3f77ebd651e8a58ee88 (diff) | |
| download | dnspython-33f4ef8257950891690af5b648c4e58b4850e0df.tar.gz | |
Return timeout duration as part of str(Timeout).
| -rw-r--r-- | dns/exception.py | 2 | ||||
| -rw-r--r-- | dns/resolver.py | 10 |
2 files changed, 7 insertions, 5 deletions
diff --git a/dns/exception.py b/dns/exception.py index 4f7df34..cbcdb57 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 387bd50..31f44fe 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, |
