mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2026-07-29 23:58:23 -05:00
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>
This commit is contained in:
+11
-32
@@ -21,7 +21,6 @@
|
|||||||
Base classes for all front-end plugins.
|
Base classes for all front-end plugins.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import re
|
|
||||||
from distutils import version
|
from distutils import version
|
||||||
|
|
||||||
import six
|
import six
|
||||||
@@ -1336,39 +1335,19 @@ class Attribute(Plugin):
|
|||||||
"""
|
"""
|
||||||
finalize_early = False
|
finalize_early = False
|
||||||
|
|
||||||
NAME_REGEX = re.compile(
|
@property
|
||||||
'^(?P<obj>[a-z][a-z0-9]+)_(?P<attr>[a-z][a-z0-9]+(?:_[a-z][a-z0-9]+)*)$'
|
def obj_name(self):
|
||||||
)
|
return self.name.partition('_')[0]
|
||||||
|
|
||||||
# Create stubs for attributes that are set in _on_finalize()
|
@property
|
||||||
__obj = Plugin.finalize_attr('_Attribute__obj')
|
def attr_name(self):
|
||||||
|
prefix = '{}_'.format(self.obj_name)
|
||||||
|
assert self.name.startswith(prefix)
|
||||||
|
return self.name[len(prefix):]
|
||||||
|
|
||||||
def __init__(self, api):
|
@property
|
||||||
m = self.NAME_REGEX.match(type(self).__name__)
|
def obj(self):
|
||||||
assert m
|
return self.api.Object[self.obj_name]
|
||||||
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)
|
|
||||||
|
|
||||||
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)
|
|
||||||
|
|
||||||
def _on_finalize(self):
|
|
||||||
self.__obj = self.api.Object[self.obj_name]
|
|
||||||
super(Attribute, self)._on_finalize()
|
|
||||||
|
|
||||||
|
|
||||||
class Method(Attribute, Command):
|
class Method(Attribute, Command):
|
||||||
|
|||||||
Reference in New Issue
Block a user