Edgewall Software

Ticket #9418: 9416-r9841-without-lock.diff

File 9416-r9841-without-lock.diff, 3.3 KB (added by jomae, 2 years ago)
  • trac/core.py

    diff --git a/trac/core.py b/trac/core.py
    index f2b92b6..0447bdc 100644
    a b class ComponentMeta(type): 
    9898            # Don't put the Component base class in the registry 
    9999            return new_class 
    100100 
    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  
    126101        if d.get('abstract'): 
    127102            # Don't put abstract component classes in the registry 
    128103            return new_class 
    class ComponentMeta(type): 
    137112 
    138113        return new_class 
    139114 
    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): 
    150116        """Return an existing instance of the component if it has already been 
    151117        activated, otherwise create a new instance. 
    152118        """ 
    class Component(object): 
    154120        if issubclass(cls, ComponentManager): 
    155121            self = super(Component, cls).__new__(cls) 
    156122            self.compmgr = self 
     123            self.__init__(*args, **kwargs) 
    157124            return self 
    158125 
    159126        # The normal case where the component is not also the component manager 
    160127        compmgr = args[0] 
    161128        self = compmgr.components.get(cls) 
    162129        if self is None: 
    163             self = super(Component, cls).__new__(cls) 
     130            self = cls.__new__(cls) 
    164131            self.compmgr = compmgr 
    165132            compmgr.component_activated(self) 
     133            self.__init__(*list(args)[1:], **kwargs) 
     134            compmgr.components[cls] = self 
    166135        return self 
    167136 
     137 
     138class 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 
    168146    @staticmethod 
    169147    def implements(*interfaces): 
    170148        """Can be used in the class definiton of `Component` subclasses to