SVN: Zope/trunk/src/App/FactoryDispatcher.py optimize access to product packages

Nikolay Kim <[email protected]>
Newsgroups gmane.comp.web.zope.cvs
Message-ID <[email protected]>
Log message for revision 121936:
  optimize access to product packages

Changed:
  U   Zope/trunk/src/App/FactoryDispatcher.py

-=-
Modified: Zope/trunk/src/App/FactoryDispatcher.py
===================================================================
--- Zope/trunk/src/App/FactoryDispatcher.py	2011-06-14 19:51:37 UTC (rev 121935)
+++ Zope/trunk/src/App/FactoryDispatcher.py	2011-06-15 05:28:30 UTC (rev 121936)
@@ -32,16 +32,17 @@
     zope2 packages and those without the Products namespace package.
     """
     import Products
-    packages = {}
+
+    _packages = {}
     for x in dir(Products):
         m = getattr(Products, x)
         if isinstance(m, types.ModuleType):
-            packages[x] = m
+            _packages[x] = m
 
     for m in get_registered_packages():
-        packages[m.__name__] = m
+        _packages[m.__name__] = m
 
-    return packages
+    return _packages
 
 
 class Product(Base):
@@ -85,8 +86,15 @@
 
     def __bobo_traverse__(self, REQUEST, name):
         # Try to get a custom dispatcher from a Python product
+        global _packages
+        try:
+            package = _packages.get(name, None)
+        except NameError:
+            _packages = _product_packages()
+            package = _packages.get(name, None)
+
         dispatcher_class=getattr(
-            _product_packages().get(name, None),
+            package,
             '__FactoryDispatcher__',
             FactoryDispatcher)
 
@@ -139,7 +147,7 @@
     def __getattr__(self, name):
         p=self.__dict__['_product']
         d=p.__dict__
-        if hasattr(p,name) and d.has_key(name):
+        if hasattr(p,name) and name in d:
             m=d[name]
             w=getattr(m, '_permissionMapper', None)
             if w is not None:
@@ -149,7 +157,7 @@
 
         # Waaa
         m = 'Products.%s' % p.id
-        if sys.modules.has_key(m) and sys.modules[m]._m.has_key(name):
+        if m in sys.modules and sys.modules[m]._m.has_key(name):
             return sys.modules[m]._m[name]
 
         raise AttributeError, name

_______________________________________________
Zope-Checkins maillist  -  [email protected]
https://mail.zope.org/mailman/listinfo/zope-checkins
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.