diff options
author | Jan Cholasta <jcholast@redhat.com> | 2016-06-14 13:02:30 +0200 |
---|---|---|
committer | Jan Cholasta <jcholast@redhat.com> | 2016-06-15 14:03:51 +0200 |
commit | bebdce89b6075f77beb36ce194b36ad4d7104ca3 (patch) | |
tree | 8ea216e2ed72e70b5007ae7047a0dabd4c6a5e47 /ipalib/util.py | |
parent | 3e6af238bb695572e462ff49a3096ab0e2e85bc5 (diff) | |
download | freeipa-bebdce89b6075f77beb36ce194b36ad4d7104ca3.tar.gz freeipa-bebdce89b6075f77beb36ce194b36ad4d7104ca3.tar.xz freeipa-bebdce89b6075f77beb36ce194b36ad4d7104ca3.zip |
plugable: allow plugins to be non-classes
Allow registering any object that is callable and has `name` and `bases`
attributes as a plugin.
https://fedorahosted.org/freeipa/ticket/4739
Reviewed-By: David Kupka <dkupka@redhat.com>
Diffstat (limited to 'ipalib/util.py')
-rw-r--r-- | ipalib/util.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/ipalib/util.py b/ipalib/util.py index 2c8772e52..4b5f11509 100644 --- a/ipalib/util.py +++ b/ipalib/util.py @@ -872,3 +872,29 @@ def detect_dns_zone_realm_type(api, domain): def has_managed_topology(api): domainlevel = api.Command['domainlevel_get']().get('result', DOMAIN_LEVEL_0) return domainlevel > DOMAIN_LEVEL_0 + + +class classproperty(object): + __slots__ = ('__doc__', 'fget') + + def __init__(self, fget=None, doc=None): + if doc is None and fget is not None: + doc = fget.__doc__ + + self.fget = fget + self.__doc__ = doc + + def __get__(self, obj, obj_type): + if self.fget is not None: + return self.fget.__get__(obj, obj_type)() + raise AttributeError("unreadable attribute") + + def __set__(self, obj, value): + raise AttributeError("can't set attribute") + + def __delete__(self, obj): + raise AttributeError("can't delete attribute") + + def getter(self, fget): + self.fget = fget + return self |