diff --git a/trac/core.py b/trac/core.py
index f2b92b6..0447bdc 100644
|
a
|
b
|
class ComponentMeta(type): |
| 98 | 98 | # Don't put the Component base class in the registry |
| 99 | 99 | return new_class |
| 100 | 100 | |
| 101 | | # Only override __init__ for Components not inheriting ComponentManager |
| 102 | | if True not in [issubclass(x, ComponentManager) for x in bases]: |
| 103 | | # Allow components to have a no-argument initializer so that |
| 104 | | # they don't need to worry about accepting the component manager |
| 105 | | # as argument and invoking the super-class initializer |
| 106 | | init = d.get('__init__') |
| 107 | | if not init: |
| 108 | | # Because we're replacing the initializer, we need to make sure |
| 109 | | # that any inherited initializers are also called. |
| 110 | | for init in [b.__init__._original for b in new_class.mro() |
| 111 | | if issubclass(b, Component) |
| 112 | | and '__init__' in b.__dict__]: |
| 113 | | break |
| 114 | | def maybe_init(self, compmgr, init=init, cls=new_class): |
| 115 | | if cls not in compmgr.components: |
| 116 | | compmgr.components[cls] = self |
| 117 | | if init: |
| 118 | | try: |
| 119 | | init(self) |
| 120 | | except: |
| 121 | | del compmgr.components[cls] |
| 122 | | raise |
| 123 | | maybe_init._original = init |
| 124 | | new_class.__init__ = maybe_init |
| 125 | | |
| 126 | 101 | if d.get('abstract'): |
| 127 | 102 | # Don't put abstract component classes in the registry |
| 128 | 103 | return new_class |
| … |
… |
class ComponentMeta(type): |
| 137 | 112 | |
| 138 | 113 | return new_class |
| 139 | 114 | |
| 140 | | |
| 141 | | class Component(object): |
| 142 | | """Base class for components. |
| 143 | | |
| 144 | | Every component can declare what extension points it provides, as well as |
| 145 | | what extension points of other components it extends. |
| 146 | | """ |
| 147 | | __metaclass__ = ComponentMeta |
| 148 | | |
| 149 | | def __new__(cls, *args, **kwargs): |
| | 115 | def __call__(cls, *args, **kwargs): |
| 150 | 116 | """Return an existing instance of the component if it has already been |
| 151 | 117 | activated, otherwise create a new instance. |
| 152 | 118 | """ |
| … |
… |
class Component(object): |
| 154 | 120 | if issubclass(cls, ComponentManager): |
| 155 | 121 | self = super(Component, cls).__new__(cls) |
| 156 | 122 | self.compmgr = self |
| | 123 | self.__init__(*args, **kwargs) |
| 157 | 124 | return self |
| 158 | 125 | |
| 159 | 126 | # The normal case where the component is not also the component manager |
| 160 | 127 | compmgr = args[0] |
| 161 | 128 | self = compmgr.components.get(cls) |
| 162 | 129 | if self is None: |
| 163 | | self = super(Component, cls).__new__(cls) |
| | 130 | self = cls.__new__(cls) |
| 164 | 131 | self.compmgr = compmgr |
| 165 | 132 | compmgr.component_activated(self) |
| | 133 | self.__init__(*list(args)[1:], **kwargs) |
| | 134 | compmgr.components[cls] = self |
| 166 | 135 | return self |
| 167 | 136 | |
| | 137 | |
| | 138 | class Component(object): |
| | 139 | """Base class for components. |
| | 140 | |
| | 141 | Every component can declare what extension points it provides, as well as |
| | 142 | what extension points of other components it extends. |
| | 143 | """ |
| | 144 | __metaclass__ = ComponentMeta |
| | 145 | |
| 168 | 146 | @staticmethod |
| 169 | 147 | def implements(*interfaces): |
| 170 | 148 | """Can be used in the class definiton of `Component` subclasses to |