To end this, I finally came up with a works-for-me solution,
however that solution is supposed to break, see available
comments in the source:
def get_instance(iface, handler):
"""Gets an instance of the specified interface for the specified request
handler.
IMPORTANT: this will break if the handler's module and the implementing
instances of the interface do not share the same module, or if multiple
implementations of the specified interface exist in the module or its
direct anchestor.
"""
def is_same_module_or_namespace(module, other):
"""Returns whether module and other share a common parent namespace
module or are the same module. Will only test for the two modules
sharing a direct anchestor. It will not traverse the anchestors until
it finds a common anchestor.
"""
# handler.log.debug("module: %s, other: %s", module, other)
if module == other:
return True
idx = other.rfind('.')
if module.startswith(other[:idx]):
# handler.log.debug("tmp: %s", other[:idx])
return True
return False
module = handler.__module__
extensions = filter(None, [handler.compmgr[cls] for cls in
ComponentMeta._registry.get(iface, ())])
for extension in extensions:
# NOTE if a plugin or distribution implements multiple instances of
# the specified interface under a common location or module, then
# this will fail.
# E.g. foo.bar.extensions holds multiple implementations of the
# specified interface iface
if is_same_module_or_namespace(module, extension.__module__):
# found matching extension
return extension
return None
Regards
Carsten
--
Carsten Klein
Mobil +491 577 666 256 5
[email protected]
axn software UG (haftungsbeschränkt)
Wipperfürther Str. 278, 51515 Kürten
Geschäftsführung Carsten Klein
HRB 66732, Gerichtsstand Amtsgericht Bergisch Gladbach
Steuernr. 204/5740/0835, USt-IdNr. DE 266 540 939
Telefon +492 268 801 285, Telefax +492 268 801 285
www.axn-software.de, [email protected]
--
You received this message because you are subscribed to the Google Groups "Trac
Development" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/trac-dev?hl=en.