From: Bob Halley Date: Sun, 8 May 2016 18:41:21 +0000 (-0700) Subject: Allow zone origin to be specified as a string. X-Git-Tag: v1.13.0~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d0ec95ab7ef777657dcd7e3ab92583646b021dc1;p=thirdparty%2Fdnspython.git Allow zone origin to be specified as a string. --- diff --git a/dns/zone.py b/dns/zone.py index 2b7826c3..6d2b5df8 100644 --- a/dns/zone.py +++ b/dns/zone.py @@ -90,8 +90,15 @@ class Zone(object): @param rdclass: The zone's rdata class; the default is class IN. @type rdclass: int""" - self.rdclass = rdclass + if isinstance(origin, string_types): + origin = dns.name.from_text(origin) + elif not isinstance(origin, dns.name.Name): + raise ValueError("origin parameter must be convertable to a " + "DNS name") + if not origin.is_absolute(): + raise ValueError("origin parameter must be an absolute name") self.origin = origin + self.rdclass = rdclass self.nodes = {} self.relativize = relativize diff --git a/tests/test_zone.py b/tests/test_zone.py index 9ae23b7c..9e3fd2cd 100644 --- a/tests/test_zone.py +++ b/tests/test_zone.py @@ -422,5 +422,16 @@ class ZoneTestCase(unittest.TestCase): rds = n.get_rdataset(dns.rdataclass.IN, dns.rdatatype.A) self.failUnless(rds.ttl == 0) + def testZoneOrigin(self): + z = dns.zone.Zone('example.') + self.failUnless(z.origin == dns.name.from_text('example.')) + def bad1(): + o = dns.name.from_text('example', None) + z = dns.zone.Zone(o) + self.failUnlessRaises(ValueError, bad1) + def bad2(): + z = dns.zone.Zone(1.0) + self.failUnlessRaises(ValueError, bad2) + if __name__ == '__main__': unittest.main()