Commit a581a35f authored by Rocky Burt's avatar Rocky Burt

No longer opens a zodb connection every time a ProductDispatcher is looked up,...

No longer opens a zodb connection every time a ProductDispatcher is looked up, forward ported from zope 2.10 branch r72990 and five 1.5 branch r72986.
parent ef0e48c2
...@@ -82,6 +82,9 @@ Zope Changes ...@@ -82,6 +82,9 @@ Zope Changes
Bugs Fixed Bugs Fixed
- No longer opens a zodb connection every time a ProductDispatcher
is looked up.
- PageTemplate/ZRPythonExpr.py: expressions represented as unicode string - PageTemplate/ZRPythonExpr.py: expressions represented as unicode string
caused UnicodeDecodeErrors. caused UnicodeDecodeErrors.
......
...@@ -26,31 +26,14 @@ def _product_packages(): ...@@ -26,31 +26,14 @@ def _product_packages():
zope2 packages and those without the Products namespace package. zope2 packages and those without the Products namespace package.
""" """
old_product_packages = {} packages = {}
for x in dir(Products): for x in dir(Products):
m = getattr(Products, x) m = getattr(Products, x)
if isinstance(m, types.ModuleType): if isinstance(m, types.ModuleType):
old_product_packages[x] = m packages[x] = m
packages = {} for m in getattr(Products, '_registered_packages', []):
app = Zope2.app() packages[m.__name__] = m
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 return packages
......
...@@ -218,6 +218,11 @@ def _registerPackage(module_, init_func=None): ...@@ -218,6 +218,11 @@ def _registerPackage(module_, init_func=None):
if init_func is not None: if init_func is not None:
newContext = ProductContext(product, app, module_) newContext = ProductContext(product, app, module_)
init_func(newContext) init_func(newContext)
registered_packages = getattr(Products, '_registered_packages', None)
if registered_packages is None:
registered_packages = Products._registered_packages = []
registered_packages.append(module_)
finally: finally:
try: try:
import transaction import transaction
......
...@@ -65,6 +65,10 @@ def test_registerPackage(): ...@@ -65,6 +65,10 @@ def test_registerPackage():
>>> 'pythonproduct2' in product_listing >>> 'pythonproduct2' in product_listing
True True
Make sure it also shows up in ``Products._registered_packages``.
>>> [x.__name__ for x in getattr(Products, '_registered_packages', [])]
['pythonproduct2']
Clean up: Clean up:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment