problems setting up methods for a product that registers no classes
...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
Chris Withers wrote at 2005-9-29 09:17 +0100:
...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. ... 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?
You could use part of the old style initialization, the "methods" declaration to be precise. You see an example in ".../Products/ZSQLMethods/__init__.py". Be warned, however: the old style initialization puts the declared methods on the "OFS.Folder" class. Thus, you better choose a name that is unlikely to conflict with other methods that might be relevant for classes derived from "Folder"... -- Dieter
Dieter Maurer wrote:
You could use part of the old style initialization, the "methods" declaration to be precise.
You see an example in ".../Products/ZSQLMethods/__init__.py".
Be warned, however: the old style initialization puts the declared methods on the "OFS.Folder" class.
Yeah, I thought about that, but it sux for the reasons you gave. I've found a similar solution to what's currently there which works in both 2.7 and 2.8, so I'll make a new release sometime soon... cheers, Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk
participants (2)
-
Chris Withers -
Dieter Maurer