mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2024-12-24 08:00:02 -06:00
plugable: simplify API plugin initialization code
Use a flat dictionary to track plugins in API rather than nested dictionaries. https://fedorahosted.org/freeipa/ticket/4739 Reviewed-By: David Kupka <dkupka@redhat.com>
This commit is contained in:
parent
ed4c2d9252
commit
19cf6e9509
@ -574,16 +574,18 @@ class API(ReadOnly):
|
||||
raise TypeError('plugin must be a class; got %r' % klass)
|
||||
|
||||
# Find the base class or raise SubclassError:
|
||||
found = False
|
||||
for base in self.bases:
|
||||
if not issubclass(klass, base):
|
||||
continue
|
||||
|
||||
sub_d = self.__plugins.setdefault(base, {})
|
||||
found = True
|
||||
if issubclass(klass, self.bases):
|
||||
break
|
||||
else:
|
||||
raise errors.PluginSubclassError(
|
||||
plugin=klass,
|
||||
bases=self.bases,
|
||||
)
|
||||
|
||||
# Check override:
|
||||
if klass.__name__ in sub_d:
|
||||
prev = self.__plugins.get(klass.__name__)
|
||||
if prev:
|
||||
if not override:
|
||||
# Must use override=True to override:
|
||||
raise errors.PluginOverrideError(
|
||||
@ -601,13 +603,7 @@ class API(ReadOnly):
|
||||
)
|
||||
|
||||
# The plugin is okay, add to sub_d:
|
||||
sub_d[klass.__name__] = klass
|
||||
|
||||
if not found:
|
||||
raise errors.PluginSubclassError(
|
||||
plugin=klass,
|
||||
bases=self.bases,
|
||||
)
|
||||
self.__plugins[klass.__name__] = klass
|
||||
|
||||
def finalize(self):
|
||||
"""
|
||||
@ -625,10 +621,11 @@ class API(ReadOnly):
|
||||
|
||||
for base in self.bases:
|
||||
name = base.__name__
|
||||
sub_d = self.__plugins.get(base, {})
|
||||
|
||||
members = []
|
||||
for klass in sub_d.values():
|
||||
|
||||
for klass in self.__plugins.values():
|
||||
if not issubclass(klass, base):
|
||||
continue
|
||||
try:
|
||||
instance = plugins[klass]
|
||||
except KeyError:
|
||||
|
Loading…
Reference in New Issue
Block a user