[Zope-dev] multiple monkeypatches
Florent Guillaume
fg@nuxeo.com
Wed, 5 Jun 2002 17:15:10 +0000 (UTC)
Jim Penny <jpenny@universal-fasteners.com> wrote:
> Is there a safe way to handle multiple monkeypatches?
Without an existing framework (I haven't looked at Adrian's PatchKit),
it's the same old problem as "intercepting interrupts" on good old 8-bit
computers. You just have to save and call the previous one.
What I do is this:
# 1. define my method
def manage_main(...):
# ...
...
res = self._myproduct_old_manage_main(...)
...
return res
# 2. put the old version in a private variable
ObjectManager._myproduct_old_manage_main = ObjectManager.manage_main
# 3. patch
ObjectManager.manage_main = manage_main
If you want to play nice with refresh, you have to be a bit more
careful, because then you don't want to do step 2. A simple test for
absence of the _myproduct_old_manage_main attribute before doing it is
enough.
Florent
--
Florent Guillaume, Nuxeo (Paris, France)
+33 1 40 33 79 87 http://nuxeo.com mailto:fg@nuxeo.com