Clean Zope source patch
Hi, 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 ?..... Many thanks, P.-J.
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
hi guys, thanks for everyones help. I was trying to fish some values (email addresses) from database based on the value of someone's username in an acl_users folder. I got it working, I think part of the problem is that ZSQL Methods seem to be real picky about their params. For example "theName" doesn't work as a param but "theName:string" does. Anyway, here's my code tom dtml_method --------------------------------------------- <dtml-in "theOTHERintranet.acl_users.getUserNames()"> <dtml-let uName="_['sequence-item']"> <dtml-in "get_email(theName=uName)"> <a href="mailto:<dtml-var Email>"><dtml-var UserName></a><br> </dtml-in> </dtml-let> </dtml-in> ----------------------------------------------- sql_method "get_email" -------------------------------------------- params :theName:string select UserName, Email from tblUsers where UserName = '<dtml-var theName>';
participants (3)
-
Brian Lloyd -
Pierre-Julien Grizel -
tom smith