[z3-checkins] r27843 - in z3/pythonproducts/trunk: . src/pythonproducts
rocky at codespeak.net
rocky at codespeak.net
Mon May 29 14:38:35 CEST 2006
Author: rocky
Date: Mon May 29 14:17:51 2006
New Revision: 27843
Modified:
z3/pythonproducts/trunk/ (props changed)
z3/pythonproducts/trunk/src/pythonproducts/pythonproducts.py
Log:
Made pythonproducts smarter and figuring out when it should patch zope and cmf.
Modified: z3/pythonproducts/trunk/src/pythonproducts/pythonproducts.py
==============================================================================
--- z3/pythonproducts/trunk/src/pythonproducts/pythonproducts.py (original)
+++ z3/pythonproducts/trunk/src/pythonproducts/pythonproducts.py Mon May 29 14:17:51 2006
@@ -27,6 +27,11 @@
_zope_app = None
+_original_initialize = None
+_original__bobo_traverse__ = None
+_originalGetPath = None
+_originalListDefaultTypeInformation = None
+
def registerPackage(_context, package, initialize=None):
"""ZCML directive function for registering a python package product
"""
@@ -75,9 +80,37 @@
_zope_app = app
global _zope_app
- patch_ProductDispatcher__bobo_traverse__(app)
- patch_externalmethod(app)
- patch_listDefaultTypeInformation(app)
+ patch_zope = True
+ patch_cmf = True
+
+ try:
+ # lets check to see if Zope itself has been fixed yet
+ from App.FactoryDispatcher import _product_packages
+ patch_zope = False
+ except ImportError:
+ patch_zope = True
+
+ if patch_zope:
+ # make sure we're not using a Five that already has the patches
+ try:
+ from Products.Five import pythonproducts
+ patch_zope = False
+ except ImportError:
+ patch_zope = True
+
+ try:
+ # make sure CMF has been installed before we try patching it
+ from Products.CMFCore.TypesTool import TypesTool
+ patch_cmf = True
+ except ImportError, e:
+ patch_cmf = False
+
+ if patch_zope:
+ patch_ProductDispatcher__bobo_traverse__(app)
+ patch_externalmethod(app)
+
+ if patch_cmf:
+ patch_listDefaultTypeInformation(app)
def removePatches():
"""Remove any monkey patches that had been applied
@@ -87,16 +120,15 @@
from App import Extensions, FactoryDispatcher
from Products.ExternalMethod import ExternalMethod
- ProductDispatcher.__bobo_traverse__ = _original__bobo_traverse__
- Extensions.getPath = _originalGetPath
- Products.Five.initialize = _original_initialize
-
- try:
+ if _original__bobo_traverse__ is not None:
+ ProductDispatcher.__bobo_traverse__ = _original__bobo_traverse__
+ if _originalGetPath is not None:
+ Extensions.getPath = _originalGetPath
+ if _original_initialize is not None:
+ Products.Five.initialize = _original_initialize
+ if _originalListDefaultTypeInformation is not None:
from Products.CMFCore.TypesTool import TypesTool
TypesTool.listDefaultTypeInformation = _originalListDefaultTypeInformation
- except ImportError, e:
- # don't continue trying to monkey patch CMF if it doesn't exist
- pass
# BEGIN MONKEY PATCHES
@@ -139,8 +171,8 @@
"""
from App.FactoryDispatcher import FactoryDispatcher, ProductDispatcher
- _original__bobo_traverse__ = ProductDispatcher.__bobo_traverse__
global _original__bobo_traverse__
+ _original__bobo_traverse__ = ProductDispatcher.__bobo_traverse__
def __bobo_traverse__(self, REQUEST, name):
product=self.aq_acquire('_getProducts')()._product(name)
@@ -167,8 +199,8 @@
from App import Extensions, FactoryDispatcher
from Products.ExternalMethod import ExternalMethod
- _originalGetPath = Extensions.getPath
global _originalGetPath
+ _originalGetPath = Extensions.getPath
def getPath(prefix, name, checkProduct=1, suffixes=('',)):
"""Make sure to check paths of all registered product packages.
@@ -208,14 +240,10 @@
be extended to check the regular prooduct packages as well.
"""
- try:
- from Products.CMFCore.TypesTool import TypesTool
- except ImportError, e:
- # don't continue trying to monkey patch CMF if it doesn't exist
- return
-
- _originalListDefaultTypeInformation = TypesTool.listDefaultTypeInformation
+ from Products.CMFCore.TypesTool import TypesTool
+
global _originalListDefaultTypeInformation
+ _originalListDefaultTypeInformation = TypesTool.listDefaultTypeInformation
from Acquisition import aq_base
@@ -263,6 +291,6 @@
_original_initialize(context)
- _original_initialize = Products.Five.initialize
global _original_initialize
+ _original_initialize = Products.Five.initialize
Products.Five.initialize = initialize
More information about the z3-checkins
mailing list