diff options
| author | Petr Spacek <pspacek@redhat.com> | 2015-01-15 17:44:49 +0100 |
|---|---|---|
| committer | Petr Spacek <pspacek@redhat.com> | 2015-02-12 12:38:31 +0100 |
| commit | d71da062bd346fd771568dcea78b2cbec898c520 (patch) | |
| tree | 7b1269cf1c30210ce2f904ac6494782bc5d53eb7 | |
| parent | c34f16726386fecd62507b8c1bfa23770c18e3ec (diff) | |
| download | dnspython-d71da062bd346fd771568dcea78b2cbec898c520.tar.gz | |
Extend NoAnswer exception with optional question.
The actual question will be printed as part of string representation of
NoAnswer exception instead of terse
"The response did not contain an answer to the question."
| -rw-r--r-- | dns/resolver.py | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/dns/resolver.py b/dns/resolver.py index d59f413..93fb36d 100644 --- a/dns/resolver.py +++ b/dns/resolver.py @@ -61,8 +61,19 @@ class YXDOMAIN(dns.exception.DNSException): Timeout = dns.exception.Timeout class NoAnswer(dns.exception.DNSException): - """The response did not contain an answer to the question.""" - pass + """The DNS response does not contain an answer to the question.""" + def __init__(self, question=None): + super(dns.exception.DNSException, self).__init__() + self.question = question + + def __str__(self): + message = self.__doc__ + if self.question: + message = message[0:-1] + for q in self.question: + message += ' %s' % q + return message + class NoNameservers(dns.exception.DNSException): """No non-broken nameservers are available to answer the query.""" @@ -139,11 +150,11 @@ class Answer(object): continue except KeyError: if raise_on_no_answer: - raise NoAnswer + raise NoAnswer(question=response.question) if raise_on_no_answer: - raise NoAnswer + raise NoAnswer(question=response.question) if rrset is None and raise_on_no_answer: - raise NoAnswer + raise NoAnswer(question=response.question) self.canonical_name = qname self.rrset = rrset if rrset is None: |
