Tres Seaver wrote:
Matt Hahnfeld wrote:
I am using Plone 2.1.2, w/ CMF 1.5.5.  I'm having trouble using
the overridden _checkPermission function in 1.5.5 to handle proxy roles on
a FSPythonScript.  After hacking around, I've determined the best method
to repair this issue is to "backport" CMF 1.6.0's function and make
_checkPermission call SecurityManager's _checkPermission.  I don't really
want to change the core libraries, so my idea was to do it as a monkey
patch.

So, I added this monkey patch to one of my custom zope products:

-----
from AccessControl import getSecurityManager

def _checkPermission(permission, obj):
    return getSecurityManager().checkPermission(permission, obj)

import Products.CMFCore.utils
Products.CMFCore.utils._checkPermission = _checkPermission
-----

But every time I use _checkPermission from Products.CMFCore.utils I'm
still getting the old one... Is it possible to monkey patch functions (as
opposed to methods)?  Any idea why this monkey patch wouldn't be working?

Other modules may have already imported it, using:

  from Products.CMFCore.utils import _checkPermission

Those modules *also* need monkey patching, because they are holding onto a reference to the original object, even though you have bound a new reference to that name with your monkey.

It might be possible to monkey patch only _checkPermission.func_code, which seems to work on simple tests, but I've never tried it in real life:

>>> def f(a):
...     print a+1

>>> def g(b):
...     print b+2

>>> f(0)
1
>>> f.func_code = g.func_code
>>> f(0)
2

Florent

--
Florent Guillaume, Nuxeo (Paris, France)   Director of R&D
+33 1 40 33 71 59   http://nuxeo.com   [EMAIL PROTECTED]
_______________________________________________
Zope-CMF maillist  -  Zope-CMF@lists.zope.org
http://mail.zope.org/mailman/listinfo/zope-cmf

See http://collector.zope.org/CMF for bug reports and feature requests

Reply via email to