[Zope] HotFixing methods of modules (not classes)

Stefan H. Holek stefan@epy.co.at
Tue, 17 Jul 2001 12:33:01 +0200 (CEST)


On Mon, 16 Jul 2001, Evan Simpson wrote:

> Peter Bengtsson wrote:
> 
> > But it is this that I can't get to work. Here I need help:
> > 
> > ---- buggyhotfix: __init__.py --------------
> > # import function
> > from module import manage_addSomething
> > 
> > def myown(self,id):
> >      id = string.upper(id)
> >      self._setObject(id,Something(id))
> > 
> > module.manage_addSomething = myown
> > --------------------------------------
> 
> As Casey mentioned, this will fail as written because 'module' isn't 
> defined.  You need to 'import module'.  There's a problem implicit in 
> the name you're overriding, though.  If 'manage_addSomething' is a 
> constructor, as its name suggests, it has probably been registered with 
> the Zope machinery by the time you get around to replacing it in the 
> module namespace.  Check to see whether 'manage_addSomething' is passed 
> to a registration function in 'module'.

You could also go the way of Transparent Folders and apply the patch in
OFS/__init__.py. That way it will always be applied before any product
initialization...

Stefan