From 77c8b62d01f955987d2a3312beb2bd44b19ee122 Mon Sep 17 00:00:00 2001 From: Nicolas Dumazet <nicolas.dumazet@nexedi.com> Date: Tue, 2 Nov 2010 05:54:56 +0000 Subject: [PATCH] rename InitializePortalTypeClass and make it a metaclass member git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@39753 20353a03-c40f-0410-a6d1-a30d3c3de9de --- product/ERP5Type/dynamic/lazy_class.py | 28 ++++++++++--------- product/ERP5Type/dynamic/portal_type_class.py | 4 +-- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/product/ERP5Type/dynamic/lazy_class.py b/product/ERP5Type/dynamic/lazy_class.py index d958a7ad78..331634a075 100644 --- a/product/ERP5Type/dynamic/lazy_class.py +++ b/product/ERP5Type/dynamic/lazy_class.py @@ -17,8 +17,10 @@ class PortalTypeMetaClass(ExtensionClass): """ Meta class that will be used by portal type classes """ + # register which classes subclass portal type classes subclass_register = {} # XXX ideal defaultdict(list) wannabe + def __init__(cls, name, bases, dictionary): """ This method is called when a portal type class is @@ -38,19 +40,19 @@ class PortalTypeMetaClass(ExtensionClass): """ return metacls.subclass_register.get(cls, []) -def InitializePortalTypeClass(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) + def resetAcquisitionAndSecurity(cls): + # 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(cls) + # Then, call __class_init__ on the class for security + InitializeClass(cls) - # And we need to do the same thing on subclasses - for klass in PortalTypeMetaClass.getSubclassList(klass): - pmc_init_of(klass) - InitializeClass(klass) + # And we need to do the same thing on subclasses + for subcls in PortalTypeMetaClass.getSubclassList(cls): + pmc_init_of(subcls) + InitializeClass(subcls) def generateLazyPortalTypeClass(portal_type_name, portal_type_class_loader): @@ -81,7 +83,7 @@ def generateLazyPortalTypeClass(portal_type_name, for key, value in attributes.iteritems(): setattr(klass, key, value) - InitializePortalTypeClass(klass) + klass.resetAcquisitionAndSecurity() return getattr(self, attr) diff --git a/product/ERP5Type/dynamic/portal_type_class.py b/product/ERP5Type/dynamic/portal_type_class.py index f38e1fa584..e9eb3ee78d 100644 --- a/product/ERP5Type/dynamic/portal_type_class.py +++ b/product/ERP5Type/dynamic/portal_type_class.py @@ -33,7 +33,7 @@ import inspect from types import ModuleType from dynamic_module import registerDynamicModule -from lazy_class import generateLazyPortalTypeClass, InitializePortalTypeClass +from lazy_class import generateLazyPortalTypeClass from Products.ERP5Type.Base import _aq_reset from Products.ERP5Type.Globals import InitializeClass @@ -308,7 +308,7 @@ def synchronizeDynamicModules(context, force=False): if attr != '__module__': delattr(klass, attr) klass.__bases__ = ghostbase - InitializePortalTypeClass(klass) + klass.resetAcquisitionAndSecurity() # Clear accessor holders of ZODB Property Sheets _clearAccessorHolderModule(erp5.zodb_accessor_holder) -- 2.30.9