[Erp5-report] r39752 nicolas.dumazet - /erp5/trunk/products/ERP5Type/dynamic/lazy_class.py

nobody at svn.erp5.org nobody at svn.erp5.org
Tue Nov 2 06:45:49 CET 2010


Author: nicolas.dumazet
Date: Tue Nov  2 06:45:48 2010
New Revision: 39752

URL: http://svn.erp5.org?rev=39752&view=rev
Log:
weed out the not-so-pretty ExtensionClass.__init__ trick

Exploring Zope code finally revealed what we needed in the
code, to allow removing the "trick".
It's a "trick" because we have no real reason to call
again the __init__ method of a metaclass: it's nicer to
understand what we need to do and to do it explicitely.

In this case, the __get__ slot was missing after the __bases__
assignement (bases are recomputed and as a result __get__ is
null'ed), and there is a method exposed in Zope's ExtensionClass
to do exactly this and only this.

The InitializeClass calls are included because
ExtensionClass.__init__ calls __class_init__, which sets correctly
roles and security on the class.

Modified:
    erp5/trunk/products/ERP5Type/dynamic/lazy_class.py

Modified: erp5/trunk/products/ERP5Type/dynamic/lazy_class.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/dynamic/lazy_class.py?rev=39752&r1=39751&r2=39752&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/dynamic/lazy_class.py [utf8] (original)
+++ erp5/trunk/products/ERP5Type/dynamic/lazy_class.py [utf8] Tue Nov  2 06:45:48 2010
@@ -1,8 +1,9 @@
 # -*- coding: utf-8 -*-
 
 import sys
+from Products.ERP5Type.Globals import InitializeClass
 from Products.ERP5Type.Base import Base as ERP5Base
-from ExtensionClass import Base as ExtensionBase
+from ExtensionClass import ExtensionClass, pmc_init_of
 from ZODB.broken import Broken, PersistentBroken
 from zLOG import LOG, ERROR, BLATHER
 
@@ -12,8 +13,6 @@ ERP5BaseBroken = type('ERP5BaseBroken', 
   for x in PersistentBroken.__dict__.iteritems()
   if x[0] not in ('__dict__', '__module__', '__weakref__')))
 
-ExtensionClass = type(ExtensionBase)
-
 class PortalTypeMetaClass(ExtensionClass):
   """
   Meta class that will be used by portal type classes
@@ -40,9 +39,18 @@ class PortalTypeMetaClass(ExtensionClass
     return metacls.subclass_register.get(cls, [])
 
 def InitializePortalTypeClass(klass):
-  ExtensionClass.__init__(klass, klass)
+  # First, fill the __get__ slot of the class
+  # that has been null'ed after resetting its __bases__
+  # This descriptor is the magic allowing __of__ and our
+  # _aq_dynamic trick
+  pmc_init_of(klass)
+  # Then, call __class_init__ on the class for security
+  InitializeClass(klass)
+
+  # And we need to do the same thing on subclasses
   for klass in PortalTypeMetaClass.getSubclassList(klass):
-    ExtensionClass.__init__(klass, klass)
+    pmc_init_of(klass)
+    InitializeClass(klass)
 
 def generateLazyPortalTypeClass(portal_type_name,
                                 portal_type_class_loader):




More information about the Erp5-report mailing list