pvl.dns.zone: better warnings for pvl.dns.zone.SOA.parse with missing parameters
authorTero Marttila <terom@paivola.fi>
Tue, 17 Dec 2013 00:42:31 +0200
changeset 294 29720bbc5379
parent 293 6351acf3eb3b
child 295 8c6d4565576f
pvl.dns.zone: better warnings for pvl.dns.zone.SOA.parse with missing parameters
bin/pvl.dns-zone
pvl/dns/zone.py
--- a/bin/pvl.dns-zone	Mon Dec 16 23:16:32 2013 +0200
+++ b/bin/pvl.dns-zone	Tue Dec 17 00:42:31 2013 +0200
@@ -170,7 +170,11 @@
     for line, rr in zone :
         if rr and rr.type == 'SOA' :
             # XXX: as SOA record..
-            soa = pvl.dns.zone.SOA.parse(line)
+            try :
+                soa = pvl.dns.zone.SOA.parse(line)
+            except TypeError as error :
+                log.exception("%s: unable to parse SOA: %s", rr.name, rr)
+                sys.exit(2)
 
             yield line, pvl.dns.zone.SOA(
                     soa.master, soa.contact,
--- a/pvl/dns/zone.py	Mon Dec 16 23:16:32 2013 +0200
+++ b/pvl/dns/zone.py	Tue Dec 17 00:42:31 2013 +0200
@@ -299,10 +299,10 @@
         return cls.build(line, name, ttl, _cls, type, data, **opts)
     
     @classmethod
-    def build (_cls, line, name, ttl, cls, type, data, **opts) :
-        return _cls(name, type, data,
+    def build (cls, line, name, ttl, _cls, type, data, **opts) :
+        return cls(name, type, data,
             ttl     = ttl,
-            cls     = cls,
+            cls     = _cls,
             line    = line,
             **opts
         )
@@ -330,7 +330,7 @@
     def MX (cls, name, priority, mx, **opts) :
         return cls(str(name), 'MX', [int(priority), str(mx)], **opts)
 
-    def __init__ (self, name, type, data, origin=None, ttl=None, cls=None, line=None, comment=None) :
+    def __init__ (self, name, type, data, ttl=None, cls=None, line=None, origin=None, comment=None) :
         self.name = name
         self.type = type
         self.data = data
@@ -338,9 +338,8 @@
         self.ttl = ttl
         self.cls = cls
         
+        self.line = line
         self.origin = origin
-        self.line = line
-
         self.comment = comment
 
     def __unicode__ (self) :
@@ -369,10 +368,10 @@
 
 class SOA (ZoneRecord) :
     @classmethod
-    def build (_cls, line, name, ttl, cls, type, data, **opts) :
+    def build (cls, line, name, ttl, _cls, type, data, **opts) :
         assert name == '@'
 
-        return _cls(*data,
+        return cls(*data,
             ttl     = ttl,
             cls     = cls,
             line    = line,