Hello,<br><br>I am trying to build a safe proxy to wrap the Plone portal object in order to control what is allowed or not.<br>Here is my code:<br>class SafeProxy:<br> def __init__(self, obj):<br> self.__dict__['_obj'] = obj
<br> <br> def __getattr__(self, attr):<br> attributes_whitelist=['portal_membership', 'MailHost']<br> if attr in attributes_whitelist:<br> return getattr(self._obj, attr)
<br> else:<br> raise AttributeError, attr+" not allowed in Plomino formula context"<br> <br> def __setattr__(self, attr, val):<br> raise AttributeError, attr+" not allowed in Plomino formula context"
<br><br>Then I use it that way:<br>>>>safeportal=SafeProxy(portal)<br>>>>safeportal.portal_membership<br><MembershipTool at /myportal/portal_membership><br>>>>safeportal.portal_catalog<br>
AttributeError: portal_catalog not allowed in Plomino formula context<br><br>which is perfect.<br><br>But my problem is:<br>>>> safeportal._obj.portal_catalog<br><CatalogTool at /concerteau/portal_catalog><br>
<br>How can I hide completely the SafeProxy _obj ? How can I make sure it can only be used from the SafeProxy class code itself and nowhere else ?<br>How can I turn it private ? (in Python private attributes are supposed to start with 2 underscores: __obj, but it just mangles with the classname: _SafeProxy__obj, so it just guarantees it will not be overwrite by another class, it does not physically protect it)
<br><br>OR (if totally impossible in Python):<br>how can I do it another way ? maybe using zope.proxy.ProxyBase, but i do not find any documentation about it...<br><br>Thanks in advance,<br><br>Eric BREHAULT<br>