diff options
author | Jason Gerard DeRose <jderose@redhat.com> | 2009-01-14 09:56:10 -0700 |
---|---|---|
committer | Jason Gerard DeRose <jderose@redhat.com> | 2009-01-14 09:56:10 -0700 |
commit | 05514292dcf2448f0340e09cd0da88f815c43c5b (patch) | |
tree | 1b7d1956b544f5e128ad0671c57b9470639df240 /ipalib | |
parent | 8cc38e681f9caca838540511664337f964302f56 (diff) | |
download | freeipa-05514292dcf2448f0340e09cd0da88f815c43c5b.tar.gz freeipa-05514292dcf2448f0340e09cd0da88f815c43c5b.tar.xz freeipa-05514292dcf2448f0340e09cd0da88f815c43c5b.zip |
New Param: Flag now fill-in default=False and also forces default to be a bool
Diffstat (limited to 'ipalib')
-rw-r--r-- | ipalib/parameter.py | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/ipalib/parameter.py b/ipalib/parameter.py index 31bd9db2b..0617c84da 100644 --- a/ipalib/parameter.py +++ b/ipalib/parameter.py @@ -638,11 +638,34 @@ class Flag(Bool): """ A boolean parameter that always gets filled in with a default value. - This `Bool` subclass forces ``autofill=True`` in `Flag.__init__()`. + This `Bool` subclass forces ``autofill=True`` in `Flag.__init__()`. If no + default is provided, it also fills in a default value of ``False``. + Lastly, unlike the `Bool` class, the default must be either ``True`` or + ``False`` and cannot be ``None``. + + For example: + + >>> Flag('my_flag') + Flag('my_flag', autofill=True, default=False) + >>> Flag('my_flag', default=True) # Do this for default of True + Flag('my_flag', autofill=True, default=True) + + Also note that creating a `Flag` instance with ``autofill=False`` will have + no effect. For example: + + >>> Flag('my_flag', autofill=False) # autofill will still be True + Flag('my_flag', autofill=True, default=False) """ def __init__(self, name, *rules, **kw): kw['autofill'] = True + if 'default' not in kw: + kw['default'] = False + if type(kw['default']) is not bool: + default = kw['default'] + raise TypeError( + TYPE_ERROR % ('default', bool, default, type(default)) + ) super(Flag, self).__init__(name, *rules, **kw) @@ -751,7 +774,7 @@ class Bytes(Param): class Str(Bytes): """ - A parameter for Unicode text (stored in the``unicode`` type). + A parameter for Unicode text (stored in the ``unicode`` type). This class is named *Str* instead of *Unicode* so it's aligned with the Python v3 ``(str, unicode) => (bytes, str)`` clean-up. See: |