From: Jakob Schlyter Date: Mon, 21 Feb 2022 18:35:34 +0000 (+0100) Subject: allow txn argument as suggested by @rthalley X-Git-Tag: v2.3.0rc1~121^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9d22b061f86a5e26e4b53ca4e0021305c36f1ad6;p=thirdparty%2Fdnspython.git allow txn argument as suggested by @rthalley --- diff --git a/dns/zone.py b/dns/zone.py index c8f576a0..6a154ced 100644 --- a/dns/zone.py +++ b/dns/zone.py @@ -713,7 +713,7 @@ class Zone(dns.transaction.TransactionManager): if self.get_rdataset(name, dns.rdatatype.NS) is None: raise NoNS - def get_soa(self): + def get_soa(self, txn=None): """Get the zone SOA RR. Raises ``dns.zone.NoSOA`` if there is no SOA RRset. @@ -724,7 +724,10 @@ class Zone(dns.transaction.TransactionManager): origin_name = dns.name.empty else: origin_name = self.origin - soa = self.get_rdataset(origin_name, dns.rdatatype.SOA) + if txn: + soa = txn.get(origin_name, dns.rdatatype.SOA) + else: + soa = self.get_rdataset(origin_name, dns.rdatatype.SOA) if soa is None: raise NoSOA return soa[0] diff --git a/tests/test_zone.py b/tests/test_zone.py index 6ef669b6..88b1e58e 100644 --- a/tests/test_zone.py +++ b/tests/test_zone.py @@ -1069,6 +1069,15 @@ class VersionedZoneTestCase(unittest.TestCase): self.assertTrue(soa.rdtype, dns.rdatatype.SOA) self.assertEqual(soa.serial, 1) + def testGetSoaTxn(self): + z = dns.zone.from_text(example_text, 'example.', relativize=True, + zone_factory=dns.versioned.Zone) + with z.reader(serial=1) as txn: + soa = z.get_soa(txn) + self.assertTrue(soa.rdtype, dns.rdatatype.SOA) + self.assertEqual(soa.serial, 1) + + def testGetSoaEmptyZone(self): z = dns.zone.Zone('example.') with self.assertRaises(dns.zone.NoSOA):