diff options
Diffstat (limited to 'ipalib')
-rw-r--r-- | ipalib/public.py | 26 | ||||
-rw-r--r-- | ipalib/run.py | 4 | ||||
-rw-r--r-- | ipalib/tests/test_public.py | 17 |
3 files changed, 38 insertions, 9 deletions
diff --git a/ipalib/public.py b/ipalib/public.py index 99d890000..b9f858fb9 100644 --- a/ipalib/public.py +++ b/ipalib/public.py @@ -26,25 +26,32 @@ import re import plugable -class cmd_proxy(plugable.Proxy): +class generic_proxy(plugable.Proxy): __slots__ = ( 'get_label', - 'get_summary', - 'get_help', - 'get_options', + ) + + +class cmd_proxy(plugable.Proxy): + __slots__ = ( + '__call__', ) class cmd(plugable.Plugin): proxy = cmd_proxy + def __call__(self, *args, **kw): + print repr(self) + class obj(plugable.Plugin): - pass + proxy = generic_proxy class attr(plugable.Plugin): __obj = None + proxy = generic_proxy def __init__(self): m = re.match('^([a-z]+)_([a-z]+)$', self.__class__.__name__) @@ -74,8 +81,13 @@ class attr(plugable.Plugin): class mthd(attr, cmd): - pass + proxy = generic_proxy class prop(attr): - pass + proxy = generic_proxy + + +class PublicAPI(plugable.API): + def __init__(self): + super(PublicAPI, self).__init__(cmd, obj, prop) diff --git a/ipalib/run.py b/ipalib/run.py index ffaa655f4..eaaaed9c8 100644 --- a/ipalib/run.py +++ b/ipalib/run.py @@ -22,7 +22,7 @@ Standard run-time instances of importard classes. This is where plugins should access the registration API. """ -import base +import public # The standard API instance -api = base.API() +api = public.PublicAPI() diff --git a/ipalib/tests/test_public.py b/ipalib/tests/test_public.py index 5ea18430b..bfe951aba 100644 --- a/ipalib/tests/test_public.py +++ b/ipalib/tests/test_public.py @@ -64,3 +64,20 @@ def test_mthd(): def test_prop(): cls = public.prop assert issubclass(cls, public.attr) + + +def test_PublicAPI(): + cls = public.PublicAPI + assert issubclass(cls, plugable.API) + + api = cls() + + class cmd1(public.cmd): + pass + api.register(cmd1) + + class cmd2(public.cmd): + pass + api.register(cmd2) + + api() |