diff options
author | Jan Cholasta <jcholast@redhat.com> | 2016-06-01 06:53:19 +0200 |
---|---|---|
committer | Jan Cholasta <jcholast@redhat.com> | 2016-06-03 09:00:34 +0200 |
commit | 60d946241cc5a13050fd67873a2044df144d6743 (patch) | |
tree | af3b6aa02c7b563be9fbc2cbcdd6356f9a9b0b77 /ipalib | |
parent | 1391cd65ad87e70b9544c11cf8c9d22f54df2902 (diff) | |
download | freeipa-60d946241cc5a13050fd67873a2044df144d6743.tar.gz freeipa-60d946241cc5a13050fd67873a2044df144d6743.tar.xz freeipa-60d946241cc5a13050fd67873a2044df144d6743.zip |
frontend: turn Method attributes into properties
Implement the `obj_name`, `attr_name` and `obj` Method attributes as
properties to allow them to be overriden in sub-classes.
https://fedorahosted.org/freeipa/ticket/4739
Reviewed-By: David Kupka <dkupka@redhat.com>
Diffstat (limited to 'ipalib')
-rw-r--r-- | ipalib/frontend.py | 43 |
1 files changed, 11 insertions, 32 deletions
diff --git a/ipalib/frontend.py b/ipalib/frontend.py index 98dcbe3d3..41a0f7c1a 100644 --- a/ipalib/frontend.py +++ b/ipalib/frontend.py @@ -21,7 +21,6 @@ Base classes for all front-end plugins. """ -import re from distutils import version import six @@ -1336,39 +1335,19 @@ class Attribute(Plugin): """ finalize_early = False - NAME_REGEX = re.compile( - '^(?P<obj>[a-z][a-z0-9]+)_(?P<attr>[a-z][a-z0-9]+(?:_[a-z][a-z0-9]+)*)$' - ) - - # Create stubs for attributes that are set in _on_finalize() - __obj = Plugin.finalize_attr('_Attribute__obj') - - def __init__(self, api): - m = self.NAME_REGEX.match(type(self).__name__) - assert m - self.__obj_name = m.group('obj') - self.__attr_name = m.group('attr') - super(Attribute, self).__init__(api) - - def __get_obj_name(self): - return self.__obj_name - obj_name = property(__get_obj_name) - - def __get_attr_name(self): - return self.__attr_name - attr_name = property(__get_attr_name) + @property + def obj_name(self): + return self.name.partition('_')[0] - def __get_obj(self): - """ - Returns the obj instance this attribute is associated with, or None - if no association has been set. - """ - return self.__obj - obj = property(__get_obj) + @property + def attr_name(self): + prefix = '{}_'.format(self.obj_name) + assert self.name.startswith(prefix) + return self.name[len(prefix):] - def _on_finalize(self): - self.__obj = self.api.Object[self.obj_name] - super(Attribute, self)._on_finalize() + @property + def obj(self): + return self.api.Object[self.obj_name] class Method(Attribute, Command): |