]> git.ipfire.org Git - thirdparty/dnspython.git/commitdiff
Allow zone origin to be specified as a string.
authorBob Halley <halley@dnspython.org>
Sun, 8 May 2016 18:41:21 +0000 (11:41 -0700)
committerBob Halley <halley@dnspython.org>
Sun, 8 May 2016 18:41:21 +0000 (11:41 -0700)
dns/zone.py
tests/test_zone.py

index 2b7826c357ade44be5a9fae6f2027f9bfd1ef02a..6d2b5df870ade959cc0614d5c083691e840d6184 100644 (file)
@@ -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
 
index 9ae23b7c685110efdce7ab6534ff31a2382467d1..9e3fd2cdb9b3a0a01bf58c94beb6fce7848c5b01 100644 (file)
@@ -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()