[Zope-dev] problems setting up methods for a product that registers no classes

Chris Withers chris at simplistix.co.uk
Thu Sep 29 04:17:01 EDT 2005


...zdb in this case.

I need to make a "global recompile" function available, since zdb 
requires the co_filename attribute of the script's func_code object to 
be set to something meaningful, rather than the useless "Script 
(Python)" it usually gets set to.

Once zdb is installed, any scripts editted will have this set, but I 
wanted to provide a utility method in a similar vein to python scripts' 
recompile function that could be globally accesed, however since zdb 
registers no classes, I ended up having to do some fairly horrific 
stuff, the following code is from zdb's __init__.py:

# recompilation utlitity
def initialize(context):
     # This horrificness is required because Zope doesn't understand the 
concept
     # of a Product that doesn't register any classes :-(
     pack=context._ProductContext__pack
     fd=getattr(pack, '__FactoryDispatcher__', None)
     if fd is None:
         class __FactoryDispatcher__(FactoryDispatcher):
             "Factory Dispatcher for a Specific Product"

         fd = pack.__FactoryDispatcher__ = __FactoryDispatcher__

     if not hasattr(pack, '_m'): pack._m=fd.__dict__
     pack._m['debug_compile'] = debug_compile
     pack._m['debug_compile__roles__'] = ('Manager',)

Now, this breaks in 2.8, so what SHOULD I be doing to make a method 
globally available in a way that works in both 2.7 and 2.8?

cheers,

Chris

-- 
Simplistix - Content Management, Zope & Python Consulting
            - http://www.simplistix.co.uk


More information about the Zope-Dev mailing list