From 73cc0c58e7d9cd821216be6ea47159dece5398d3 Mon Sep 17 00:00:00 2001 From: Leandro Lucarella Date: Sat, 21 Jun 2008 23:17:27 -0300 Subject: [PATCH] Move common validation code to new pymin.validation module (refs #20) This module includes all the validators from formencode plus some custom validators specific to pymin. --- pymin/validation.py | 14 ++++++++++++++ services/firewall/rule.py | 11 +---------- 2 files changed, 15 insertions(+), 10 deletions(-) create mode 100644 pymin/validation.py diff --git a/pymin/validation.py b/pymin/validation.py new file mode 100644 index 0000000..a9baf22 --- /dev/null +++ b/pymin/validation.py @@ -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) + diff --git a/services/firewall/rule.py b/services/firewall/rule.py index c774582..b9f09a4 100644 --- a/services/firewall/rule.py +++ b/services/firewall/rule.py @@ -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. -- 2.43.0