diff options
author | Jason Gerard DeRose <jderose@redhat.com> | 2008-08-05 23:34:59 +0000 |
---|---|---|
committer | Jason Gerard DeRose <jderose@redhat.com> | 2008-08-05 23:34:59 +0000 |
commit | f31f7813febf0665a072d474166ea883bc7365dc (patch) | |
tree | fc3712296386d0b5b5a5a146970921c423c90797 /ipalib/plugable.py | |
parent | 159207514fadfacb6e1df9713abd2c61c24d7b77 (diff) | |
download | freeipa.git-f31f7813febf0665a072d474166ea883bc7365dc.tar.gz freeipa.git-f31f7813febf0665a072d474166ea883bc7365dc.tar.xz freeipa.git-f31f7813febf0665a072d474166ea883bc7365dc.zip |
53: Changed plugable.Registar so the same plugin can be added to in the ns for more than one base (for cmd and mthd)
Diffstat (limited to 'ipalib/plugable.py')
-rw-r--r-- | ipalib/plugable.py | 39 |
1 files changed, 22 insertions, 17 deletions
diff --git a/ipalib/plugable.py b/ipalib/plugable.py index 2c5fd18c..a8996cf2 100644 --- a/ipalib/plugable.py +++ b/ipalib/plugable.py @@ -236,10 +236,13 @@ class Registrar(object): base; otherwise raises SubclassError. """ assert inspect.isclass(cls) + found = False for base in self.__allowed: if issubclass(cls, base): - return base - raise errors.SubclassError(cls, self.__allowed) + found = True + yield base + if not found: + raise errors.SubclassError(cls, self.__allowed) def __call__(self, cls, override=False): """ @@ -248,27 +251,29 @@ class Registrar(object): if not inspect.isclass(cls): raise TypeError('plugin must be a class: %r' % cls) - # Find the base class or raise SubclassError: - base = self.__findbase(cls) - sub_d = self.__d[base.__name__] - # Raise DuplicateError if this exact class was already registered: if cls in self.__registered: raise errors.DuplicateError(cls) - # Check override: - if cls.__name__ in sub_d: - # Must use override=True to override: - if not override: - raise errors.OverrideError(base, cls) - else: - # There was nothing already registered to override: - if override: - raise errors.MissingOverrideError(base, cls) + # Find the base class or raise SubclassError: + for base in self.__findbase(cls): + sub_d = self.__d[base.__name__] + + # Check override: + if cls.__name__ in sub_d: + # Must use override=True to override: + if not override: + raise errors.OverrideError(base, cls) + else: + # There was nothing already registered to override: + if override: + raise errors.MissingOverrideError(base, cls) + + # The plugin is okay, add to sub_d: + sub_d[cls.__name__] = cls - # The plugin is okay, add to __registered and sub_d: + # The plugin is okay, add to __registered: self.__registered.add(cls) - sub_d[cls.__name__] = cls def __getitem__(self, item): """ |