]> git.ipfire.org Git - thirdparty/dnspython.git/commitdiff
dns.query.xfr() now raises on a non-zero rcode.
authorBob Halley <halley@dnspython.org>
Sun, 29 Jan 2017 14:53:01 +0000 (06:53 -0800)
committerBob Halley <halley@dnspython.org>
Sun, 29 Jan 2017 14:53:01 +0000 (06:53 -0800)
[ISSUE #231]

dns/query.py
doc/exceptions.rst

index 5087c95af8145c9944a29befa8bbe6b8478b569e..f1f656eab2761e0b7d92edc1cbd7de059396bc41 100644 (file)
@@ -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
index fdf0edd1012f6c5f2692646e366983142a9e18b0..b7054822d002452602b59810030d207aab167a4c 100644 (file)
@@ -51,6 +51,7 @@ dns.query Exceptions
 
 .. autoexception:: dns.query.BadResponse
 .. autoexception:: dns.query.UnexpectedSource
+.. autoexception:: dns.query.TransferError
 
 
 dns.rcode Exceptions