diff options
author | Jason Gerard DeRose <jderose@redhat.com> | 2008-09-24 23:49:44 +0000 |
---|---|---|
committer | Jason Gerard DeRose <jderose@redhat.com> | 2008-09-24 23:49:44 +0000 |
commit | f531f7da81864f135ff1a5f7d69e15fbe8a27210 (patch) | |
tree | 50d838f3b35d1dee017755d215f6f93b08b4e4aa /ipalib | |
parent | be2e323bbf3f036777acd6e5e16e03f9e66b2ee8 (diff) | |
download | freeipa-f531f7da81864f135ff1a5f7d69e15fbe8a27210.tar.gz freeipa-f531f7da81864f135ff1a5f7d69e15fbe8a27210.tar.xz freeipa-f531f7da81864f135ff1a5f7d69e15fbe8a27210.zip |
354: Added NameSpace.__todict__() method that returns copy of NameSpace.__map; updated NameSpace unit test to also test __todict__()
Diffstat (limited to 'ipalib')
-rw-r--r-- | ipalib/frontend.py | 9 | ||||
-rw-r--r-- | ipalib/plugable.py | 18 | ||||
-rw-r--r-- | ipalib/tests/test_plugable.py | 1 |
3 files changed, 20 insertions, 8 deletions
diff --git a/ipalib/frontend.py b/ipalib/frontend.py index bcd610a53..6c5f8c76b 100644 --- a/ipalib/frontend.py +++ b/ipalib/frontend.py @@ -521,8 +521,13 @@ class Object(plugable.Plugin): takes_params = tuple() def __create_params(self): - for param in self.takes_params: - yield create_param(param) + props = self.properties.__todict__() + for spec in self.takes_params: + if type(spec) is str and spec.rstrip('?*+') in props: + yield props.pop(spec.rstrip('?*+')).param + else: + yield create_param(spec) + def set_api(self, api): super(Object, self).set_api(api) diff --git a/ipalib/plugable.py b/ipalib/plugable.py index cd130a19a..e1d728d49 100644 --- a/ipalib/plugable.py +++ b/ipalib/plugable.py @@ -545,13 +545,13 @@ class NameSpace(ReadOnly): def __len__(self): """ - Returns the number of members. + Return the number of members. """ return len(self.__members) def __iter__(self): """ - Iterates through the member names. + Iterate through the member names. If this instance was created with ``sort=True``, the names will be in alphabetical order; otherwise the names will be in the same order as @@ -564,7 +564,7 @@ class NameSpace(ReadOnly): def __call__(self): """ - Iterates through the members. + Iterate through the members. If this instance was created with ``sort=True``, the members will be in alphabetical order by name; otherwise the members will be in the @@ -577,13 +577,13 @@ class NameSpace(ReadOnly): def __contains__(self, name): """ - Returns True if namespace has a member named ``name``. + Return True if namespace has a member named ``name``. """ return name in self.__map def __getitem__(self, spec): """ - Returns a member by name or index, or returns a slice of members. + Return a member by name or index, or returns a slice of members. :param spec: The name or index of a member, or a slice object. """ @@ -597,7 +597,7 @@ class NameSpace(ReadOnly): def __repr__(self): """ - Returns a pseudo-valid expression that could create this instance. + Return a pseudo-valid expression that could create this instance. """ return '%s(<%d members>, sort=%r)' % ( self.__class__.__name__, @@ -605,6 +605,12 @@ class NameSpace(ReadOnly): self.__sort, ) + def __todict__(self): + """ + Return a copy of the private dict mapping name to member. + """ + return dict(self.__map) + class Registrar(DictProxy): """ diff --git a/ipalib/tests/test_plugable.py b/ipalib/tests/test_plugable.py index 02d35cded..95d3825f7 100644 --- a/ipalib/tests/test_plugable.py +++ b/ipalib/tests/test_plugable.py @@ -586,6 +586,7 @@ class test_NameSpace(ClassChecker): else: ordered = members names = tuple(m.name for m in ordered) + assert o.__todict__() == dict((o.name, o) for o in ordered) # Test __len__: assert len(o) == cnt |