summaryrefslogtreecommitdiffstats
path: root/ipalib
diff options
context:
space:
mode:
authorJason Gerard DeRose <jderose@redhat.com>2009-01-13 20:27:19 -0700
committerJason Gerard DeRose <jderose@redhat.com>2009-01-13 20:27:19 -0700
commit8cc38e681f9caca838540511664337f964302f56 (patch)
tree57bf2b6dfff4c90e3ac0e46700e24ddf0279283f /ipalib
parent659bb4c142ee9a987babd38fad93b539e51309f3 (diff)
downloadfreeipa-8cc38e681f9caca838540511664337f964302f56.tar.gz
freeipa-8cc38e681f9caca838540511664337f964302f56.tar.xz
freeipa-8cc38e681f9caca838540511664337f964302f56.zip
New Param: added new Flag param class and its unit test
Diffstat (limited to 'ipalib')
-rw-r--r--ipalib/parameter.py32
1 files changed, 30 insertions, 2 deletions
diff --git a/ipalib/parameter.py b/ipalib/parameter.py
index 7d70f40a8..31bd9db2b 100644
--- a/ipalib/parameter.py
+++ b/ipalib/parameter.py
@@ -219,6 +219,7 @@ class Param(ReadOnly):
('normalizer', callable, None),
('default_from', DefaultFrom, None),
('create_default', callable, None),
+ ('autofill', bool, False),
('flags', frozenset, frozenset()),
# The 'default' kwarg gets appended in Param.__init__():
@@ -329,6 +330,17 @@ class Param(ReadOnly):
**self.__kw
)
+ def __call__(self, value, **kw):
+ """
+ One stop shopping.
+ """
+ if value in NULLS:
+ value = self.get_default(**kw)
+ else:
+ value = self.convert(self.normalize(value))
+ self.validate(value)
+ return value
+
def clone(self, **overrides):
"""
Return a new `Param` instance similar to this one.
@@ -619,6 +631,20 @@ class Bool(Param):
A parameter for boolean values (stored in the ``bool`` type).
"""
+ type = bool
+
+
+class Flag(Bool):
+ """
+ A boolean parameter that always gets filled in with a default value.
+
+ This `Bool` subclass forces ``autofill=True`` in `Flag.__init__()`.
+ """
+
+ def __init__(self, name, *rules, **kw):
+ kw['autofill'] = True
+ super(Flag, self).__init__(name, *rules, **kw)
+
class Int(Param):
"""
@@ -635,6 +661,7 @@ class Float(Param):
"""
type = float
+ type_error = _('must be a decimal number')
class Bytes(Param):
@@ -648,6 +675,7 @@ class Bytes(Param):
"""
type = str
+ type_error = _('must be binary data')
kwargs = Param.kwargs + (
('minlength', int, None),
@@ -657,8 +685,8 @@ class Bytes(Param):
)
- def __init__(self, name, **kw):
- super(Bytes, self).__init__(name, **kw)
+ def __init__(self, name, *rules, **kw):
+ super(Bytes, self).__init__(name, *rules, **kw)
if not (
self.length is None or