[Zope-Checkins] SVN: Zope/trunk/lib/python/App/FactoryDispatcher.py External methods can now live outside of Products based python packages.

Rocky Burt rocky at serverzen.com
Tue May 2 16:59:08 EDT 2006


Log message for revision 67869:
  External methods can now live outside of Products based python packages.

Changed:
  U   Zope/trunk/lib/python/App/FactoryDispatcher.py

-=-
Modified: Zope/trunk/lib/python/App/FactoryDispatcher.py
===================================================================
--- Zope/trunk/lib/python/App/FactoryDispatcher.py	2006-05-02 20:57:53 UTC (rev 67868)
+++ Zope/trunk/lib/python/App/FactoryDispatcher.py	2006-05-02 20:59:07 UTC (rev 67869)
@@ -13,12 +13,36 @@
 
 
 # Implement the manage_addProduct method of object managers
+import types
 import Acquisition, sys, Products
 from Globals import InitializeClass
 from AccessControl import ClassSecurityInfo
 from AccessControl.PermissionMapping import aqwrap
 from AccessControl.Owned import UnownableOwner
+import Zope2
 
+def _product_packages():
+    """Returns all product packages including the regularly defined
+    zope2 packages and those without the Products namespace package.
+    """
+    
+    old_product_packages = {}
+    for x in dir(Products):
+        m = getattr(Products, x)
+        if isinstance(m, types.ModuleType):
+            old_product_packages[x] = m
+    
+    packages = {}
+    products = Zope2.app().Control_Panel.Products
+    for product_id in products.objectIds():
+        product = products[product_id]
+        if hasattr(product, 'package_name'):
+            packages[product_id] = __import__(product.package_name)
+        elif old_product_packages.has_key(product_id):
+            packages[product_id] = old_product_packages[product_id]
+    
+    return packages
+
 class ProductDispatcher(Acquisition.Implicit):
     " "
     # Allow access to factory dispatchers
@@ -32,7 +56,7 @@
 
         # Try to get a custom dispatcher from a Python product
         dispatcher_class=getattr(
-            getattr(Products, name, None),
+            _product_packages().get(name, None),
             '__FactoryDispatcher__',
             FactoryDispatcher)
 



More information about the Zope-Checkins mailing list