From a79434584eaab5692d716368b54572aa2b6be70c Mon Sep 17 00:00:00 2001 From: Jason Gerard DeRose Date: Wed, 24 Sep 2008 18:44:43 +0000 Subject: 343: create_param() function no longer parses the param spec itself but relies on Param.__init__() to do it --- ipalib/frontend.py | 26 ++++---------------------- 1 file changed, 4 insertions(+), 22 deletions(-) (limited to 'ipalib/frontend.py') diff --git a/ipalib/frontend.py b/ipalib/frontend.py index f6626973..ce43ecea 100644 --- a/ipalib/frontend.py +++ b/ipalib/frontend.py @@ -86,7 +86,7 @@ class DefaultFrom(plugable.ReadOnly): def parse_param_spec(spec): """ - Parse param spec to get name, required, and multivalue. + 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 @@ -322,20 +322,14 @@ class Param(plugable.ReadOnly): def create_param(spec): """ - Create a `Param` instance from a param spec string. + Create a `Param` instance from a param spec. If ``spec`` is a `Param` instance, ``spec`` is returned unchanged. If ``spec`` is an str instance, then ``spec`` is parsed and an appropriate `Param` instance is created and returned. - The spec string determines the param name, whether the param is required, - and whether the param is multivalue according the following syntax: - - name => required=True, multivalue=False - name? => required=False, multivalue=False - name+ => required=True, multivalue=True - name* => required=False, multivalue=True + See `parse_param_spec` for the definition of the spec syntax. :param spec: A spec string or a `Param` instance. """ @@ -345,19 +339,7 @@ def create_param(spec): raise TypeError( 'create_param() takes %r or %r; got %r' % (str, Param, spec) ) - if spec.endswith('?'): - kw = dict(required=False, multivalue=False) - name = spec[:-1] - elif spec.endswith('*'): - kw = dict(required=False, multivalue=True) - name = spec[:-1] - elif spec.endswith('+'): - kw = dict(required=True, multivalue=True) - name = spec[:-1] - else: - kw = dict(required=True, multivalue=False) - name = spec - return Param(name, ipa_types.Unicode(), **kw) + return Param(spec) class Command(plugable.Plugin): -- cgit