]> git.llucax.com Git - software/pymin.git/commitdiff
Move common validation code to new pymin.validation module (refs #20)
authorLeandro Lucarella <llucax@gmail.com>
Sun, 22 Jun 2008 02:17:27 +0000 (23:17 -0300)
committerLeandro Lucarella <llucax@gmail.com>
Sat, 28 Jun 2008 04:54:00 +0000 (01:54 -0300)
This module includes all the validators from formencode plus some custom
validators specific to pymin.

pymin/validation.py [new file with mode: 0644]
services/firewall/rule.py

diff --git a/pymin/validation.py b/pymin/validation.py
new file mode 100644 (file)
index 0000000..a9baf22
--- /dev/null
@@ -0,0 +1,14 @@
+# vim: set encoding=utf-8 et sw=4 sts=4 :
+
+from formencode import Invalid
+from formencode.validators import *
+from formencode.compound import *
+
+from pymin.item import Item
+from pymin.validatedclass import Field
+
+class UpOneOf(OneOf):
+    "Same as :class:`OneOf` but values are uppercased before validation."
+    def validate_python(self, value, state):
+        return OneOf.validate_python(self, value.upper(), state)
+
index c774582d0db629265753eff0ce039fbf5ac22ca5..b9f09a43297d6b6281a0d3c0a6fb367601a77b03 100644 (file)
@@ -1,20 +1,11 @@
 # vim: set encoding=utf-8 et sw=4 sts=4 :
 
-from formencode import Invalid
-from formencode.validators import OneOf, CIDR, Int
-
-from pymin.item import Item
-from pymin.validatedclass import Field
+from pymin.validation import Item, Field, UpOneOf, CIDR, Int, Invalid
 from pymin.service.util import ListSubHandler
 
 __all__ = ('FirewallHandler',)
 
 
-class UpOneOf(OneOf):
-    def validate_python(self, value, state):
-        value = value.upper()
-        return OneOf.validate_python(self, value, state)
-
 class Rule(Item):
     r"""Rule(chain, target[, src[, dst[, ...]]]) -> Rule instance.