Log message for revision 69719:
  Removed awful _zope_app usage which was causing ConnectionStateError problems.

Changed:
  U   Products.Five/branches/1.4/CHANGES.txt
  U   Products.Five/branches/1.4/fiveconfigure.py
  U   Products.Five/branches/1.4/pythonproducts.py
  U   Products.Five/branches/1.4/tests/test_pythonproducts.py

-=-
Modified: Products.Five/branches/1.4/CHANGES.txt
===================================================================
--- Products.Five/branches/1.4/CHANGES.txt      2006-08-21 12:27:47 UTC (rev 
69718)
+++ Products.Five/branches/1.4/CHANGES.txt      2006-08-21 13:53:13 UTC (rev 
69719)
@@ -2,6 +2,16 @@
 Five Changes
 ============
 
+Five 1.4.x
+==========
+
+Bugfixes
+--------
+
+* Backported Zope 2.10's pythonproducts zope app handling to help resolve
+  an issue with ConnectionStateError's.
+
+
 Five 1.4.1 (2006-08-13)
 =======================
 

Modified: Products.Five/branches/1.4/fiveconfigure.py
===================================================================
--- Products.Five/branches/1.4/fiveconfigure.py 2006-08-21 12:27:47 UTC (rev 
69718)
+++ Products.Five/branches/1.4/fiveconfigure.py 2006-08-21 13:53:13 UTC (rev 
69719)
@@ -27,6 +27,7 @@
 from App.ProductContext import ProductContext
 import Products
 from zLOG import LOG, ERROR
+import Zope2
 
 from zope.interface import classImplements, classImplementsOnly, implementedBy
 from zope.interface.interface import InterfaceClass
@@ -266,18 +267,25 @@
         raise ValueError("Must be a package and the " \
                          "package must be filesystem based")
     
-    product = initializeProduct(module_, 
-                                module_.__name__, 
-                                module_.__path__[0], 
-                                pythonproducts._zope_app)
+    app = Zope2.app()
+    try:
+        product = initializeProduct(module_, 
+                                    module_.__name__, 
+                                    module_.__path__[0],
+                                    app)
 
-    product.package_name = module_.__name__
+        product.package_name = module_.__name__
 
-    if initFunc is not None:
-        newContext = ProductContext(product, pythonproducts._zope_app, module_)
-        initFunc(newContext)
+        if initFunc is not None:
+            newContext = ProductContext(product, app, module_)
+            initFunc(newContext)
+    finally:
+        try:
+            import transaction
+            transaction.commit()
+        finally:
+            app._p_jar.close()
 
-
 def registerPackage(_context, package, initialize=None):
     """ZCML directive function for registering a python package product
     """

Modified: Products.Five/branches/1.4/pythonproducts.py
===================================================================
--- Products.Five/branches/1.4/pythonproducts.py        2006-08-21 12:27:47 UTC 
(rev 69718)
+++ Products.Five/branches/1.4/pythonproducts.py        2006-08-21 13:53:13 UTC 
(rev 69719)
@@ -25,9 +25,8 @@
 from App.Product import initializeProduct
 from App.ProductContext import ProductContext
 from zope.testing import cleanup
+import Zope2
 
-_zope_app = None
-
 def isMonkeyPatched(m):
     return hasattr(m, '__five_method__')  
 
@@ -35,26 +34,18 @@
     """Initialize the python-packages-as-products logic
     """
     
-    from OFS.Application import Application
-    
-    global _zope_app
-    if isinstance(appOrContext, Application):
-        _zope_app = appOrContext
-    else:
-        _zope_app = appOrContext._ProductContext__app
-    
-    applyPatches(_zope_app)
+    applyPatches()
 
 
-def applyPatches(app):
+def applyPatches():
     """Apply necessary monkey patches to force Zope 2 to be capable of
     handling "products" that are not necessarily located under the Products
     package.  Ultimately all functionality provided by these patches should
     be folded into Zope 2 core.
     """
     
-    patch_ProductDispatcher__bobo_traverse__(app)
-    patch_externalmethod(app)
+    patch_ProductDispatcher__bobo_traverse__()
+    patch_externalmethod()
 
 def removePatches():
     """Remove all monkey patches.
@@ -77,11 +68,11 @@
 # Most of these monkey patches were repurposed from the code I 
 # wrote for Basket - Rocky
 
-def product_packages(app):
+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)
@@ -89,23 +80,27 @@
             old_product_packages[x] = m
     
     packages = {}
-    products = app.Control_Panel.Products
-    for product_id in products.objectIds():
-        product = products[product_id]
-        if hasattr(product, 'package_name'):
-            pos = product.package_name.rfind('.')
-            if pos > -1:
-                packages[product_id] = __import__(product.package_name, 
-                                                  globals(), {}, 
-                                                  product.package_name[pos+1:])
-            else:
-                packages[product_id] = __import__(product.package_name)
-        elif old_product_packages.has_key(product_id):
-            packages[product_id] = old_product_packages[product_id]
+    app = Zope2.app()
+    try:
+        products = app.Control_Panel.Products
+        for product_id in products.objectIds():
+            product = products[product_id]
+            if hasattr(product, 'package_name'):
+                pos = product.package_name.rfind('.')
+                if pos > -1:
+                    packages[product_id] = __import__(product.package_name, 
+                                                      globals(), {}, 
+                                                      
product.package_name[pos+1:])
+                else:
+                    packages[product_id] = __import__(product.package_name)
+            elif old_product_packages.has_key(product_id):
+                packages[product_id] = old_product_packages[product_id]
+    finally:
+        app._p_jar.close()
     
     return packages
     
-def patch_ProductDispatcher__bobo_traverse__(app):
+def patch_ProductDispatcher__bobo_traverse__():
     """Currently, z2's App.FactoryDispatcher.ProductDispatcher only checks
     the Products module for products to look up existing factory dispatchers
     on.  This needs to be fixed to look in all enabled product packages
@@ -124,7 +119,7 @@
         product=self.aq_acquire('_getProducts')()._product(name)
 
         # Try to get a custom dispatcher from a Python product
-        productPkgs = product_packages(app)
+        productPkgs = product_packages()
         dispatcher_class=getattr(
             productPkgs.get(name, None),
             '__FactoryDispatcher__',
@@ -137,7 +132,7 @@
     ProductDispatcher.__bobo_traverse__ = __bobo_traverse__
     
 
-def patch_externalmethod(app):
+def patch_externalmethod():
     """In an effort to make External Methods work with regular python
     packages, this function replaces App.Extensions.getPath with a custom 
     getPath function.  See the getPath doc string for extra details.

Modified: Products.Five/branches/1.4/tests/test_pythonproducts.py
===================================================================
--- Products.Five/branches/1.4/tests/test_pythonproducts.py     2006-08-21 
12:27:47 UTC (rev 69718)
+++ Products.Five/branches/1.4/tests/test_pythonproducts.py     2006-08-21 
13:53:13 UTC (rev 69719)
@@ -24,39 +24,17 @@
 from Products.Five.tests import testing
 sys.path.append(testing.__path__[0])
 
-def test_aRegisterPackageCall():
+def test_registerPackage():
     """
-    Testing registerPackage.  Recently renamed method to something to
-    would produce an out of order issue that breaks the test.
+    Testing registerPackage
 
       >>> from zope.app.testing.placelesssetup import setUp, tearDown
       >>> setUp()
       >>> import Products
       >>> import Products.Five
       >>> from Products.Five import zcml
-      >>> from Products.Five import pythonproducts
       >>> zcml.load_config('meta.zcml', Products.Five)
-      >>> pythonproducts.setupPythonProducts(app)
 
-    Make sure a python package with no initialize (even though one
-    is specified) will fail::
-    
-      >>> configure_zcml = '''
-      ... <configure
-      ...     xmlns="http://namespaces.zope.org/zope";
-      ...     xmlns:five="http://namespaces.zope.org/five";
-      ...     i18n_domain="foo">
-      ...   <five:registerPackage
-      ...       package="pythonproduct1"
-      ...       initialize="pythonproduct1.initialize"
-      ...       />
-      ... </configure>'''
-      >>> zcml.load_string(configure_zcml)
-      Traceback (most recent call last):
-          ...
-      ZopeXMLConfigurationError: ...
-      ConfigurationError: ('...pythonproduct1 has no global initialize')    
-
     Make sure a python package with a valid initialize gets its
     initialize function called::
     
@@ -76,61 +54,25 @@
     Test to see if the pythonproduct2 python package actually gets setup
     as a zope2 product in the Control Panel.
 
-      >>> productListing = app.Control_Panel.Products.objectIds()
-      >>> 'pythonproduct2' in productListing
+      >>> product_listing = []
+      >>> import Zope2
+      >>> app = Zope2.app()
+      >>> try:
+      ...    product_listing = app.Control_Panel.Products.objectIds()
+      ... finally:
+      ...     app._p_jar.close()
+      >>> 'pythonproduct2' in product_listing
       True
 
-    Clean up:
 
-      >>> tearDown()
-    """
-
-def test_externalmethods():
-    """
-    Testing registerPackage
-
-      >>> from zope.app.testing.placelesssetup import setUp, tearDown
-      >>> setUp()
-      >>> import Products
-      >>> import Products.Five
-      >>> from Products.Five import zcml
-      >>> from Products.Five import pythonproducts
-      >>> zcml.load_config('meta.zcml', Products.Five)
-      >>> pythonproducts.setupPythonProducts(app)
-
-      >>> configure_zcml = '''
-      ... <configure
-      ...     xmlns="http://namespaces.zope.org/zope";
-      ...     xmlns:five="http://namespaces.zope.org/five";
-      ...     i18n_domain="foo">
-      ...   <five:registerPackage
-      ...       package="pythonproduct2"
-      ...       initialize="pythonproduct2.initialize"
-      ...       />
-      ... </configure>'''
-      >>> zcml.load_string(configure_zcml)
-      pythonproduct2 initialized
-      
-    Lets go ahead and try setting up an external method from the
-    pythonproduct2 product.
-    
-      >>> from Products.ExternalMethod.ExternalMethod import 
manage_addExternalMethod
-      >>> manage_addExternalMethod(app, 'testexternal', '', 
'pythonproduct2.somemodule', 'somemethod')
-      
-    Now lets actually execute the external method.
-        
-      >>> app.testexternal()
-      Executed somemethod
-
     Clean up:
 
       >>> tearDown()
     """
 
-
 def test_suite():
-    from Testing.ZopeTestCase import ZopeDocTestSuite
-    return ZopeDocTestSuite()
+    from zope.testing.doctest import DocTestSuite
+    return DocTestSuite()
 
 if __name__ == '__main__':
     framework()

_______________________________________________
Zope-Checkins maillist  -  Zope-Checkins@zope.org
http://mail.zope.org/mailman/listinfo/zope-checkins

Reply via email to