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>&nbsp;&nbsp;&nbsp; def __init__(self, obj):<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; self.__dict__[&#39;_obj&#39;] = obj
<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; def __getattr__(self, attr):<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; attributes_whitelist=[&#39;portal_membership&#39;, &#39;MailHost&#39;]<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if attr in attributes_whitelist:<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return getattr(self._obj, attr)
<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else:<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; raise AttributeError, attr+&quot; not allowed in Plomino formula context&quot;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; def __setattr__(self, attr, val):<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; raise AttributeError, attr+&quot; not allowed in Plomino formula context&quot;
<br><br>Then I use it that way:<br>&gt;&gt;&gt;safeportal=SafeProxy(portal)<br>&gt;&gt;&gt;safeportal.portal_membership<br>&lt;MembershipTool at /myportal/portal_membership&gt;<br>&gt;&gt;&gt;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>&gt;&gt;&gt; safeportal._obj.portal_catalog<br>&lt;CatalogTool at /concerteau/portal_catalog&gt;<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:&nbsp; __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>