summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason Gerard DeRose <jderose@redhat.com>2008-12-18 01:45:13 -0700
committerJason Gerard DeRose <jderose@redhat.com>2008-12-18 01:45:13 -0700
commit99363131df63f3b1d22bf325282eee5671eff924 (patch)
tree55caad2e021943569cc775005f902aeac2d76682
parenta632c2935aad26666a579204505ec0770bbe953d (diff)
downloadfreeipa-99363131df63f3b1d22bf325282eee5671eff924.tar.gz
freeipa-99363131df63f3b1d22bf325282eee5671eff924.tar.xz
freeipa-99363131df63f3b1d22bf325282eee5671eff924.zip
New Param: swapped location of DefaultFrom class and parse_param_spec() function
-rw-r--r--ipalib/parameter.py94
1 files changed, 47 insertions, 47 deletions
diff --git a/ipalib/parameter.py b/ipalib/parameter.py
index 76b696098..a80c43c4d 100644
--- a/ipalib/parameter.py
+++ b/ipalib/parameter.py
@@ -26,53 +26,6 @@ from plugable import ReadOnly, lock, check_name
from constants import NULLS, TYPE_ERROR, CALLABLE_ERROR
-def parse_param_spec(spec):
- """
- Parse a param spec into to (name, kw).
-
- The ``spec`` string determines the param name, whether the param is
- required, and whether the param is multivalue according the following
- syntax:
-
- ====== ===== ======== ==========
- Spec Name Required Multivalue
- ====== ===== ======== ==========
- 'var' 'var' True False
- 'var?' 'var' False False
- 'var*' 'var' False True
- 'var+' 'var' True True
- ====== ===== ======== ==========
-
- For example,
-
- >>> parse_param_spec('login')
- ('login', {'required': True, 'multivalue': False})
- >>> parse_param_spec('gecos?')
- ('gecos', {'required': False, 'multivalue': False})
- >>> parse_param_spec('telephone_numbers*')
- ('telephone_numbers', {'required': False, 'multivalue': True})
- >>> parse_param_spec('group+')
- ('group', {'required': True, 'multivalue': True})
-
- :param spec: A spec string.
- """
- if type(spec) is not str:
- raise_TypeError(spec, str, 'spec')
- if len(spec) < 2:
- raise ValueError(
- 'param spec must be at least 2 characters; got %r' % spec
- )
- _map = {
- '?': dict(required=False, multivalue=False),
- '*': dict(required=False, multivalue=True),
- '+': dict(required=True, multivalue=True),
- }
- end = spec[-1]
- if end in _map:
- return (spec[:-1], _map[end])
- return (spec, dict(required=True, multivalue=False))
-
-
class DefaultFrom(ReadOnly):
"""
Derive a default value from other supplied values.
@@ -177,6 +130,53 @@ class DefaultFrom(ReadOnly):
pass
+def parse_param_spec(spec):
+ """
+ Parse a param spec into to (name, kw).
+
+ The ``spec`` string determines the param name, whether the param is
+ required, and whether the param is multivalue according the following
+ syntax:
+
+ ====== ===== ======== ==========
+ Spec Name Required Multivalue
+ ====== ===== ======== ==========
+ 'var' 'var' True False
+ 'var?' 'var' False False
+ 'var*' 'var' False True
+ 'var+' 'var' True True
+ ====== ===== ======== ==========
+
+ For example,
+
+ >>> parse_param_spec('login')
+ ('login', {'required': True, 'multivalue': False})
+ >>> parse_param_spec('gecos?')
+ ('gecos', {'required': False, 'multivalue': False})
+ >>> parse_param_spec('telephone_numbers*')
+ ('telephone_numbers', {'required': False, 'multivalue': True})
+ >>> parse_param_spec('group+')
+ ('group', {'required': True, 'multivalue': True})
+
+ :param spec: A spec string.
+ """
+ if type(spec) is not str:
+ raise_TypeError(spec, str, 'spec')
+ if len(spec) < 2:
+ raise ValueError(
+ 'param spec must be at least 2 characters; got %r' % spec
+ )
+ _map = {
+ '?': dict(required=False, multivalue=False),
+ '*': dict(required=False, multivalue=True),
+ '+': dict(required=True, multivalue=True),
+ }
+ end = spec[-1]
+ if end in _map:
+ return (spec[:-1], _map[end])
+ return (spec, dict(required=True, multivalue=False))
+
+
class Param(ReadOnly):
"""
Base class for all parameters.