Added new Param.flags attribute (set with flags=foo kwarg)

This commit is contained in:
Jason Gerard DeRose 2008-10-17 19:34:26 -06:00
parent f7b7fa5553
commit 8322138f38
2 changed files with 6 additions and 0 deletions

View File

@ -207,6 +207,7 @@ class Param(plugable.ReadOnly):
normalize callable None
default same as type.type None
default_from callable None
flags frozenset frozenset()
============ ================= ==================
"""
__nones = (None, '', tuple(), [])
@ -220,6 +221,7 @@ class Param(plugable.ReadOnly):
normalize=None,
default=None,
default_from=None,
flags=frozenset(),
rules=tuple(),
)
@ -249,6 +251,7 @@ class Param(plugable.ReadOnly):
self.default_from = check_type(df, DefaultFrom, 'default_from',
allow_none=True
)
self.flags = frozenset(kw['flags'])
self.__normalize = kw['normalize']
self.rules = self.__check_type(tuple, 'rules')
self.all_rules = (self.type.validate,) + self.rules

View File

@ -162,6 +162,7 @@ class test_Param(ClassChecker):
assert read_only(o, 'multivalue') is False
assert read_only(o, 'default') is None
assert read_only(o, 'default_from') is None
assert read_only(o, 'flags') == frozenset()
assert read_only(o, 'rules') == tuple()
assert len(read_only(o, 'all_rules')) == 1
assert read_only(o, 'primary_key') is False
@ -183,6 +184,8 @@ class test_Param(ClassChecker):
assert type(o.default_from) is frontend.DefaultFrom
assert o.default_from.keys == ('first', 'last')
assert o.default_from.callback('butt', 'erfly') == 'butterfly'
assert self.cls(name, flags=('one', 'two', 'three')).flags == \
frozenset(['one', 'two', 'three'])
rules = (lambda whatever: 'Not okay!',)
o = self.cls(name, rules=rules)
assert o.rules is rules