From: Bob Halley Date: Sun, 29 Jan 2017 14:53:01 +0000 (-0800) Subject: dns.query.xfr() now raises on a non-zero rcode. X-Git-Tag: v1.16.0~43 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4f26a2c7af86474a3800c616aa26f2f419dd28c5;p=thirdparty%2Fdnspython.git dns.query.xfr() now raises on a non-zero rcode. [ISSUE #231] --- diff --git a/dns/query.py b/dns/query.py index 5087c95a..f1f656ea 100644 --- a/dns/query.py +++ b/dns/query.py @@ -28,6 +28,7 @@ import dns.exception import dns.inet import dns.name import dns.message +import dns.rcode import dns.rdataclass import dns.rdatatype from ._compat import long, string_types @@ -49,6 +50,15 @@ class BadResponse(dns.exception.FormError): """A DNS query response does not respond to the question asked.""" +class TransferError(dns.exception.DNSException): + """A zone transfer response got a non-zero rcode.""" + + def __init__(self, rcode): + message = 'Zone transfer error: %s' % dns.rcode.to_text(rcode) + super(TransferError, self).__init__(message) + self.rcode = rcode + + def _compute_expiration(timeout): if timeout is None: return None @@ -531,6 +541,8 @@ def xfr(where, zone, rdtype=dns.rdatatype.AXFR, rdclass=dns.rdataclass.IN, *keyalgorithm*, a ``dns.name.Name`` or ``text``, the TSIG algorithm to use. + Raises on errors, and so does the generator. + Returns a generator of ``dns.message.Message`` objects. """ @@ -594,6 +606,9 @@ def xfr(where, zone, rdtype=dns.rdatatype.AXFR, rdclass=dns.rdataclass.IN, xfr=True, origin=origin, tsig_ctx=tsig_ctx, multi=True, first=first, one_rr_per_rrset=is_ixfr) + rcode = r.rcode() + if rcode != dns.rcode.NOERROR: + raise TransferError(rcode) tsig_ctx = r.tsig_ctx first = False answer_index = 0 diff --git a/doc/exceptions.rst b/doc/exceptions.rst index fdf0edd1..b7054822 100644 --- a/doc/exceptions.rst +++ b/doc/exceptions.rst @@ -51,6 +51,7 @@ dns.query Exceptions .. autoexception:: dns.query.BadResponse .. autoexception:: dns.query.UnexpectedSource +.. autoexception:: dns.query.TransferError dns.rcode Exceptions