[Zope] Security class attribute

Peter Bengtsson peter at fry-it.com
Thu Jan 26 09:44:23 EST 2006


Now in Zope 2.9 I get these warnings::

 2006-01-26 14:31:45 WARNING Init Class
Products.MyProduct.Homesite.FilesContainer has a security declaration
for nonexistent method 'FileManagement'

That's understandable because I've coded it like this::

 class MyProduct(...):
     security=ClassSecurityInfo()
     security.declareProtected('View', 'FileManagement.html')

 setattr(MyProduct, 'FileManagement.html', MyProduct.FileManagement)

In other words, I create methods after the class has been defined and
squeeze them in manually. Very convenient.
To avoid the WARNING message above I thought I could use
declareProtected() _after_ the the class has been defined just as with
the additional method; but no luck :(
I tried this::
 class MyProduct(...):
     security=ClassSecurityInfo()

 setattr(MyProduct, 'FileManagement.html', MyProduct.FileManagement)
 MyProduct.security.declareProtected('View', 'FileManagement.html')

But I'm getting::

 AttributeError: type object 'MyProduct' has no attribute 'security'

Which I totally don't understand. To test my sanity I wrote this test
script which works fine::

 class _Z:
    def __init__(self):
        self.z = "Z"
    def declareProtected(self, *a,**k):
        print "++declare something+"
def foo():
    print "I'm being called"
    return _Z()
class A:
    security=foo()
    def __init__(self):
        pass
A.security.declareProtected("foo")
print dir(A)

Which works like you'd expect with the followin output::

 I'm being called
 ++declare something+
 ['__doc__', '__init__', '__module__', 'security']

What's going on [differently] in Zope? What am I missing?





--
Peter Bengtsson,
work www.fry-it.com
home www.peterbe.com
hobby www.issuetrackerproduct.com


More information about the Zope mailing list