[Erp5-report] r32255 jm - in /erp5/trunk/products/ERP5Type: ./ Accessor/

nobody at svn.erp5.org nobody at svn.erp5.org
Thu Feb 4 11:00:46 CET 2010


Author: jm
Date: Thu Feb  4 11:00:42 2010
New Revision: 32255

URL: http://svn.erp5.org?rev=32255&view=rev
Log:
Speed up Base.provides accessors by caching the result

Removed:
    erp5/trunk/products/ERP5Type/Accessor/Interface.py
Modified:
    erp5/trunk/products/ERP5Type/Base.py
    erp5/trunk/products/ERP5Type/Utils.py

Removed: erp5/trunk/products/ERP5Type/Accessor/Interface.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/Accessor/Interface.py?rev=32254&view=auto
==============================================================================
--- erp5/trunk/products/ERP5Type/Accessor/Interface.py [utf8] (original)
+++ erp5/trunk/products/ERP5Type/Accessor/Interface.py (removed)
@@ -1,57 +1,0 @@
-##############################################################################
-#
-# Copyright (c) 2002-2009 Nexedi SARL and Contributors. All Rights Reserved.
-#                    Sebastien Robin <seb at nexedi.com>
-#
-# WARNING: This program as such is intended to be used by professional
-# programmers who take the whole responsability of assessing all potential
-# consequences resulting from its eventual inadequacies and bugs
-# End users who are looking for a ready-to-use solution with commercial
-# garantees and support are strongly adviced to contract a Free Software
-# Service Company
-#
-# This program is Free Software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License
-# as published by the Free Software Foundation; either version 2
-# of the License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
-#
-##############################################################################
-
-from Accessor import Accessor
-
-# Creation of default constructor
-class func_code: pass
-
-class Getter(Accessor):
-  """
-  This getter will calls the provides method. This allows
-  lazy evaluation of the interface list provided by every portal type
-  """
-  _need__name__ = 1
-
-  # Generic Definition of Method Object
-  # This is required to call the method form the Web
-  # More information at http://www.zope.org/Members/htrd/howto/FunctionTemplate
-  func_code = func_code()
-  func_code.co_varnames = ('self', )
-  func_code.co_argcount = 1
-  func_defaults = ()
-
-  # default values
-  _value = None
-
-  def __init__(self, id, key):
-    self._id = id
-    self._key = key
-
-  def __call__(self, instance):
-    return instance.provides(self._key)

Modified: erp5/trunk/products/ERP5Type/Base.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/Base.py?rev=32255&r1=32254&r2=32255&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/Base.py [utf8] (original)
+++ erp5/trunk/products/ERP5Type/Base.py [utf8] Thu Feb  4 11:00:42 2010
@@ -818,17 +818,17 @@
     """
     initializeClassDynamicProperties(self, self.__class__)
 
-  security.declareProtected( Permissions.AccessContentsInformation, 'provides' )
-  def provides(self, interface_name):
+  security.declarePublic('provides')
+  def provides(cls, interface_name):
     """
     Check if the current class provides a particular interface
     """
-    result = False
-    for interface in implementedBy(self.__class__):
+    for interface in implementedBy(cls):
       if interface.getName() == interface_name:
-        result = True
-        break
-    return result
+        return True
+    return False
+  provides = classmethod(CachingMethod(provides, 'Base.provides',
+                                       cache_factory='erp5_ui_long'))
 
   def _aq_key(self):
     return (self.portal_type, self.__class__)

Modified: erp5/trunk/products/ERP5Type/Utils.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/Utils.py?rev=32255&r1=32254&r2=32255&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/Utils.py [utf8] (original)
+++ erp5/trunk/products/ERP5Type/Utils.py [utf8] Thu Feb  4 11:00:42 2010
@@ -69,7 +69,6 @@
 from Products.ERP5Type.Accessor.Constant import PropertyGetter as \
     PropertyConstantGetter
 from Products.ERP5Type.Accessor.Constant import Getter as ConstantGetter
-from Products.ERP5Type.Accessor.Interface import Getter as InterfaceGetter
 from Products.ERP5Type.Cache import getReadOnlyTransactionCache
 from Products.ERP5Type.TransactionalVariable import getTransactionalVariable
 from zLOG import LOG, BLATHER, PROBLEM, WARNING
@@ -594,16 +593,12 @@
       module = imp.load_source(class_id, path, f)
       import Products.ERP5Type.interfaces
       setattr(Products.ERP5Type.interfaces, class_id, getattr(module, class_id))
-
-    # Create interface getter
-    accessor_name = 'provides' + class_id
-    accessor = InterfaceGetter(accessor_name, class_id)
-    setattr(BaseClass, accessor_name, accessor)
-    BaseClass.security.declareProtected(
-                Permissions.AccessContentsInformation, accessor_name)
-
   finally:
     f.close()
+  # Create interface getter
+  accessor_name = 'provides' + class_id
+  setattr(BaseClass, accessor_name, lambda self: self.provides(class_id))
+  BaseClass.security.declarePublic(accessor_name)
 
 def importLocalConstraint(class_id, path = None):
   import Products.ERP5Type.Constraint




More information about the Erp5-report mailing list