diff options
author | Jason Gerard DeRose <jderose@redhat.com> | 2008-08-06 03:27:00 +0000 |
---|---|---|
committer | Jason Gerard DeRose <jderose@redhat.com> | 2008-08-06 03:27:00 +0000 |
commit | 277685439c91f496df9510e02418da01160df0ea (patch) | |
tree | df4e1ac59611a3ea0fa22779cd01a5e81c4dca58 /ipalib/plugable.py | |
parent | c6f69e1c66b86f8f375a3c561922a42fdc0b1afb (diff) | |
download | freeipa.git-277685439c91f496df9510e02418da01160df0ea.tar.gz freeipa.git-277685439c91f496df9510e02418da01160df0ea.tar.xz freeipa.git-277685439c91f496df9510e02418da01160df0ea.zip |
55: Cleaned up print_api() function in ipa script
Diffstat (limited to 'ipalib/plugable.py')
-rw-r--r-- | ipalib/plugable.py | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/ipalib/plugable.py b/ipalib/plugable.py index 6e6c6973..e017a8a4 100644 --- a/ipalib/plugable.py +++ b/ipalib/plugable.py @@ -175,12 +175,13 @@ class NameSpace(ReadOnly): __max_len = None - def __init__(self, items): + def __init__(self, items, base=None): """ `items` should be an iterable providing the members of this NameSpace. """ object.__setattr__(self, '_NameSpace__items', tuple(items)) + object.__setattr__(self, '_NameSpace__base', base) # dict mapping Python name to item: object.__setattr__(self, '_NameSpace__pname', {}) @@ -234,6 +235,14 @@ class NameSpace(ReadOnly): object.__setattr__(self, '_NameSpace__max_len', ml) return self.__max_len + def __repr__(self): + if self.__base is None: + base = repr(self.__base) + else: + base = '%s.%s' % (self.__base.__module__, self.__base.__name__) + return '%s(*proxies, base=%s)' % (self.__class__.__name__, base) + + @@ -329,6 +338,8 @@ class Registrar(object): class API(ReadOnly): def __init__(self, *allowed): + keys = tuple(b.__name__ for b in allowed) + object.__setattr__(self, '_API__keys', keys) object.__setattr__(self, 'register', Registrar(*allowed)) object.__setattr__(self, '_API__plugins', []) @@ -337,7 +348,7 @@ class API(ReadOnly): Finalize the registration, instantiate the plugins. """ for (base, plugins) in self.register: - ns = NameSpace(self.__plugin_iter(base, plugins)) + ns = NameSpace(self.__plugin_iter(base, plugins), base=base) assert not hasattr(self, base.__name__) object.__setattr__(self, base.__name__, ns) for plugin in self.__plugins: @@ -350,3 +361,7 @@ class API(ReadOnly): plugin = cls() self.__plugins.append(plugin) yield base.proxy(plugin) + + def __iter__(self): + for key in self.__keys: + yield key |