diff options
author | Jason Gerard DeRose <jderose@redhat.com> | 2009-01-14 10:58:05 -0700 |
---|---|---|
committer | Jason Gerard DeRose <jderose@redhat.com> | 2009-01-14 10:58:05 -0700 |
commit | 3e201dfff6d96f415a7f7d7f6010e97877b5a5c0 (patch) | |
tree | 4eb686ca0dc84088a451cb7ee8403bdf687a07ef /ipalib | |
parent | 3a6f716aac6c2750f42a04eba18f1023b866b790 (diff) | |
download | freeipa-3e201dfff6d96f415a7f7d7f6010e97877b5a5c0.tar.gz freeipa-3e201dfff6d96f415a7f7d7f6010e97877b5a5c0.tar.xz freeipa-3e201dfff6d96f415a7f7d7f6010e97877b5a5c0.zip |
New Param: split common Bytes/Str functionality into new Data base class; Str no longer subclasses from Bytes
Diffstat (limited to 'ipalib')
-rw-r--r-- | ipalib/parameters.py | 51 |
1 files changed, 36 insertions, 15 deletions
diff --git a/ipalib/parameters.py b/ipalib/parameters.py index bfe601a9..da01bfcf 100644 --- a/ipalib/parameters.py +++ b/ipalib/parameters.py @@ -19,6 +19,16 @@ """ Parameter system for command plugins. + +TODO: + + * Change rule call signature to rule(_, value, **kw) so that rules can also + validate relative to other parameter values (e.g., login name as it relates + to first name and last name) + + * Add the _rule_pattern() methods to `Bytes` and `Str` + + * Add maxvalue, minvalue kwargs and rules to `Int` and `Float` """ from types import NoneType @@ -28,7 +38,6 @@ from plugable import ReadOnly, lock, check_name from errors2 import ConversionError, RequirementError, ValidationError from constants import NULLS, TYPE_ERROR, CALLABLE_ERROR - class DefaultFrom(ReadOnly): """ Derive a default value from other supplied values. @@ -695,29 +704,23 @@ class Float(Param): type_error = _('must be a decimal number') -class Bytes(Param): +class Data(Param): """ - A parameter for binary data (stored in the ``str`` type). - - This class is named *Bytes* instead of *Str* so it's aligned with the - Python v3 ``(str, unicode) => (bytes, str)`` clean-up. See: + Base class for the `Bytes` and `Str` parameters. - http://docs.python.org/3.0/whatsnew/3.0.html + Previously `Str` was as subclass of `Bytes`. Now the common functionality + has been split into this base class so that ``isinstance(foo, Bytes)`` wont + be ``True`` when ``foo`` is actually an `Str` instance (which is confusing). """ - type = str - type_error = _('must be binary data') - kwargs = Param.kwargs + ( ('minlength', int, None), ('maxlength', int, None), ('length', int, None), - ('pattern', str, None), - ) def __init__(self, name, *rules, **kw): - super(Bytes, self).__init__(name, *rules, **kw) + super(Data, self).__init__(name, *rules, **kw) if not ( self.length is None or @@ -749,6 +752,24 @@ class Bytes(Param): self.nice, self.minlength) ) + +class Bytes(Data): + """ + A parameter for binary data (stored in the ``str`` type). + + This class is named *Bytes* instead of *Str* so it's aligned with the + Python v3 ``(str, unicode) => (bytes, str)`` clean-up. See: + + http://docs.python.org/3.0/whatsnew/3.0.html + """ + + type = str + type_error = _('must be binary data') + + kwargs = Data.kwargs + ( + ('pattern', str, None), + ) + def _rule_minlength(self, _, value): """ Check minlength constraint. @@ -780,7 +801,7 @@ class Bytes(Param): ) -class Str(Bytes): +class Str(Data): """ A parameter for Unicode text (stored in the ``unicode`` type). @@ -793,7 +814,7 @@ class Str(Bytes): type = unicode type_error = _('must be Unicode text') - kwargs = Bytes.kwargs[:-1] + ( + kwargs = Data.kwargs + ( ('pattern', unicode, None), ) |