[Zope] Clean Zope source patch

Brian Lloyd brian@digicool.com
Thu, 21 Sep 2000 10:05:24 -0400


> I need to patch Zope source code to make an I18N module of my own work.
> The function I need to patch is Publish.py in lib/python/ZPublisher
> (only the publish function).
> 
> I'd like to to it a 'clean' way, that is, without modifying the actual
> source code. To achieve this, I can copy the publish function into
> MyPublish.py, patch it, and, somewhere in the Zope source file
> hierarchy, put something the following statement :
> ZPublisher.publish = MyPublish
>
> Well, huh... This is theory. It doesn't work because I don't know where
> ZPublisher is actually imported into Zope, and, thus, where my
> affectation will really take effect.
> 
> 
> Does anyone knows how to do this ? Or perhaps someone knows a better way
> to "cleanly" patch Zope source ?.....

An ideal way to do "guerilla patching" like this is with a 
Product. This is in fact how HotFix products work.

At Zope startup time, the Zope machinery tries to import 
each package in lib/python/Products. So you can create 
your own "product" which is nothing more than a package 
with an "__init__.py" that performs the replacement.

For example, create a directory "I18NHack" in your 
lib/python/Products and a file therein "__init__.py"
(along with your MyPublish module). The __init__.py
would look something like:

from MyPublish import publish
import ZPublisher.Publish

# replace the original publish function...
ZPublisher.Publish.publish=publish

This way you don't modify any Zope source and  can pretty
easily manage and distribute your patch.

Hope this helps!


Brian Lloyd        brian@digicool.com
Software Engineer  540.371.6909              
Digital Creations  http://www.digicool.com