incubator-bloodhound-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From g..@apache.org
Subject svn commit: r1309470 - /incubator/bloodhound/trunk/trac/trac/core.py
Date Wed, 04 Apr 2012 15:56:22 GMT
Author: gjm
Date: Wed Apr  4 15:56:22 2012
New Revision: 1309470

URL: http://svn.apache.org/viewvc?rev=1309470&view=rev
Log:
dynamically replace component __init__ methods with one that only calls the original init
code once - #22

Modified:
    incubator/bloodhound/trunk/trac/trac/core.py

Modified: incubator/bloodhound/trunk/trac/trac/core.py
URL: http://svn.apache.org/viewvc/incubator/bloodhound/trunk/trac/trac/core.py?rev=1309470&r1=1309469&r2=1309470&view=diff
==============================================================================
--- incubator/bloodhound/trunk/trac/trac/core.py (original)
+++ incubator/bloodhound/trunk/trac/trac/core.py Wed Apr  4 15:56:22 2012
@@ -94,7 +94,23 @@ class ComponentMeta(type):
     def __new__(mcs, name, bases, d):
         """Create the component class."""
 
-        new_class = type.__new__(mcs, name, bases, d)
+        def nonrecursive_init(cls):
+            """Replaces __init__ of the class with one that checks for
+            recursion"""
+            original_init = cls.__init__
+            compmgrs = set()
+            def new_init(self, *args, **kwargs):
+                """Only run the original __init__ once per component manager"""
+                if self.compmgr not in compmgrs:
+                    try:
+                        compmgrs.add(self.compmgr)
+                        original_init(self, *args, **kwargs)
+                    finally:
+                        compmgrs.remove(self.compmgr)
+            cls.__init__ = new_init
+            return cls
+
+        new_class = nonrecursive_init(type.__new__(mcs, name, bases, d))
         if name == 'Component':
             # Don't put the Component base class in the registry
             return new_class



Mime
View raw message