]> git.ipfire.org Git - thirdparty/dnspython.git/commitdiff
add effective origin to origin_information()
authorBob Halley <halley@dnspython.org>
Thu, 20 Aug 2020 12:17:30 +0000 (05:17 -0700)
committerBob Halley <halley@dnspython.org>
Thu, 20 Aug 2020 12:17:30 +0000 (05:17 -0700)
dns/transaction.py
dns/zone.py
dns/zonefile.py

index c6c2f0f7908a09c47bf930f1ea643d3db4512798..c1645c270d0f8a04ba6e281e0dd8099ef1c62f30 100644 (file)
@@ -28,12 +28,20 @@ class TransactionManager:
         raise NotImplementedError  # pragma: no cover
 
     def origin_information(self):
-        """Returns an (origin: ``dns.name.Name``, relativize: ``bool``) tuple
-        giving the absolute name of the default origin for any
-        relative domain names, and whether names should be relativized
-        to that origin.
+        """Returns a tuple
+
+            (absolute_origin, relativize, effective_origin)
 
-        If the returned name is `None`, then no origin information is
+        giving the absolute name of the default origin for any
+        relative domain names, the "effective origin", and whether
+        names should be relativized.  The "effective origin" is the
+        absolute origin if relativize is False, and the empty name if
+        relativize is true.  (The effective origin is provided even
+        though it can be computed from the absolute_origin and
+        relativize setting because it avoids a lot of code
+        duplication.)
+
+        If the returned names are `None`, then no origin information is
         available.
 
         This information is used by code working with transactions to
index 427184ebad6fda527a71fbb735357fd1ba8740c3..c9c1c20193fca28a1804ddbd5ae4fbec832939bb 100644 (file)
@@ -642,6 +642,8 @@ class Zone(dns.transaction.TransactionManager):
         if self.get_rdataset(name, dns.rdatatype.NS) is None:
             raise NoNS
 
+    # TransactionManager methods
+
     def reader(self):
         return Transaction(self, False, True)
 
@@ -649,7 +651,11 @@ class Zone(dns.transaction.TransactionManager):
         return Transaction(self, replacement, False)
 
     def origin_information(self):
-        return (self.origin, self.relativize)
+        if self.relativize:
+            effective = dns.name.empty
+        else:
+            effective = self.origin
+        return (self.origin, self.relativize, effective)
 
     def get_class(self):
         return self.rdclass
index df2d01cace56fbd85cbc95d06baa40caa2812c3b..92e2f0cf0005ae1d2e8562b7fd82b6bd9597387b 100644 (file)
@@ -44,7 +44,8 @@ class Reader:
 
     def __init__(self, tok, rdclass, txn, allow_include=False):
         self.tok = tok
-        (self.zone_origin, self.relativize) = txn.manager.origin_information()
+        (self.zone_origin, self.relativize, _) = \
+            txn.manager.origin_information()
         self.current_origin = self.zone_origin
         self.last_ttl = 0
         self.last_ttl_known = False