]> git.llucax.com Git - software/pymin.git/commitdiff
Add validation to DnsHandler (refs #20)
authorLeandro Lucarella <llucax@gmail.com>
Thu, 26 Jun 2008 00:37:17 +0000 (21:37 -0300)
committerLeandro Lucarella <llucax@gmail.com>
Sat, 28 Jun 2008 04:54:01 +0000 (01:54 -0300)
services/dns/host.py
services/dns/mx.py
services/dns/ns.py
services/dns/zone.py

index 20ce0d5a5444161e9d0184e9f832556d629263bb..fecd7c60a0f7c4f00b60d485eb45cada678e0650 100644 (file)
@@ -1,20 +1,16 @@
 # vim: set encoding=utf-8 et sw=4 sts=4 :
 
-# TODO documentation, validation
+# TODO documentation
 
-from pymin.seqtools import Sequence
+from pymin.validation import Item, Field, HostName, IPAddress
 from pymin.service.util import DictComposedSubHandler
 
 __all__ = ('HostHandler',)
 
-class Host(Sequence):
-    def __init__(self, name, ip):
-        self.name = name
-        self.ip = ip
-    def update(self, ip=None):
-        if ip is not None: self.ip = ip
-    def as_tuple(self):
-        return (self.name, self.ip)
+
+class Host(Item):
+    name = Field(HostName(not_empty=True))
+    ip = Field(IPAddress(not_empty=True))
 
 class HostHandler(DictComposedSubHandler):
     handler_help = u"Manage DNS hosts"
index ec7fc82a5463e8aafa2e16a36cf7848c19210c95..fa2c0cfde48f67233ac3ce9f00b8624a52545284 100644 (file)
@@ -1,21 +1,16 @@
 # vim: set encoding=utf-8 et sw=4 sts=4 :
 
-# TODO documentation, validation
+# TODO documentation
 
-from pymin.seqtools import Sequence
+from pymin.validation import Item, Field, FullyQualifiedHostName, UInt16
 from pymin.service.util import DictComposedSubHandler
 
 __all__ = ('MailExchangeHandler',)
 
 
-class MailExchange(Sequence):
-    def __init__(self, mx, prio):
-        self.mx = mx
-        self.prio = prio
-    def update(self, prio=None):
-        if prio is not None: self.prio = prio
-    def as_tuple(self):
-        return (self.mx, self.prio)
+class MailExchange(Item):
+    mx = Field(FullyQualifiedHostName(not_empty=True))
+    prio = Field(UInt16(not_empty=True))
 
 class MailExchangeHandler(DictComposedSubHandler):
     handler_help = u"Manage DNS mail exchangers (MX)"
index f5b63ac05e34f8baf22f9f399adac348547ac4ad..510ec31c11f81e619ab3a2b281e4693809bda91d 100644 (file)
@@ -1,18 +1,15 @@
 # vim: set encoding=utf-8 et sw=4 sts=4 :
 
-# TODO documentation, validation
+# TODO documentation
 
-from pymin.seqtools import Sequence
+from pymin.validation import Item, Field, FullyQualifiedHostName
 from pymin.service.util import DictComposedSubHandler
 
 __all__ = ('NameServerHandler',)
 
 
-class NameServer(Sequence):
-    def __init__(self, name):
-        self.name = name
-    def as_tuple(self):
-        return (self.name,)
+class NameServer(Item):
+    name = Field(FullyQualifiedHostName(not_empty=True))
 
 class NameServerHandler(DictComposedSubHandler):
     handler_help = u"Manage DNS name servers (NS)"
index f91fcc7594bba0956d357e8345b67ed9d54a1a2a..2e333828fb3e02650027b65edcc408e1ffcad27d 100644 (file)
@@ -1,24 +1,23 @@
 # vim: set encoding=utf-8 et sw=4 sts=4 :
 
-# TODO documentation, validation
+# TODO documentation
 
-from pymin.seqtools import Sequence
+from pymin.validation import Item, Field, FullyQualifiedHostName
 from pymin.service.util import DictSubHandler
 
 __all__ = ('DnsHandler',)
 
 
-class Zone(Sequence):
-    def __init__(self, name):
-        self.name = name
+class Zone(Item):
+    name = Field(FullyQualifiedHostName(not_empty=True))
+    def __init__(self, *args, **kwargs):
+        Item.__init__(self, *args, **kwargs)
         self.hosts = dict()
         self.mxs = dict()
         self.nss = dict()
         self._add = False
         self._update = False
         self._delete = False
-    def as_tuple(self):
-        return (self.name, self.hosts, self.mxs, self.nss)
 
 class ZoneHandler(DictSubHandler):
     handler_help = u"Manage DNS zones"