From: Bob Halley Date: Thu, 20 Aug 2020 12:17:30 +0000 (-0700) Subject: add effective origin to origin_information() X-Git-Tag: v2.1.0rc1~61 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e2888f116e0c98748f63044e9801acd0d18defd5;p=thirdparty%2Fdnspython.git add effective origin to origin_information() --- diff --git a/dns/transaction.py b/dns/transaction.py index c6c2f0f7..c1645c27 100644 --- a/dns/transaction.py +++ b/dns/transaction.py @@ -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 diff --git a/dns/zone.py b/dns/zone.py index 427184eb..c9c1c201 100644 --- a/dns/zone.py +++ b/dns/zone.py @@ -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 diff --git a/dns/zonefile.py b/dns/zonefile.py index df2d01ca..92e2f0cf 100644 --- a/dns/zonefile.py +++ b/dns/zonefile.py @@ -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