[CMF-checkins] CVS: CMF/CMFDefault - MembershipTool.py:1.43
Florent Guillaume
fg at nuxeo.com
Tue Feb 10 16:02:31 EST 2004
The use case I have is for special folders (proxy folders) in CPS where
the __getitem__ behavior is designed to do other things than direct
attribute access (there is a better separation between attribute access
and subitem access).
You're right about the aq_base, but I'll code it differently:
if hasattr(aq_base(members), id):
folder = getattr(members, id)
...
Note that getattr is used in getMembersFolder and createMemberArea and
not [] so I wanted to homogenize things and at the same time fix my problem.
But if you still think it's problematic I'll remove it and monkey-patch
it from CPS.
Florent
Casey Duncan wrote:
> If you do this, you probably need to do aq_base(members) because
> otherwise you might acquire an object named id from above (getitem
> doesn't acquire). You'd then have to rewrap it. That makes it something
> pretty like:
>
> folder = getattr(aq_base(members), id).__of__(members)
>
> 8^)
>
> I'm curious, what is the motivation behind this change. What folder in
> existance doesn't support __getitem__? Frankly this seems a bit dubious.
>
> -Casey
>
> On Tue, 10 Feb 2004 15:07:58 -0500
> Florent Guillaume <fg at nuxeo.com> wrote:
>
>
>>Update of /cvs-repository/CMF/CMFDefault
>>In directory cvs.zope.org:/tmp/cvs-serv21599
>>
>>Modified Files:
>> MembershipTool.py
>>Log Message:
>>Always use getattr to access the home folder as a subobject of the
>>members folder. This is more consistent and doesn't assume that the
>>members folder has item-based access.
>>
>>
>>=== CMF/CMFDefault/MembershipTool.py 1.42 => 1.43 ===
>>--- CMF/CMFDefault/MembershipTool.py:1.42 Sun Jan 11 07:59:01 2004
>>+++ CMF/CMFDefault/MembershipTool.py Tue Feb 10 15:07:57 2004
>>@@ -276,12 +276,13 @@
>> members = self.getMembersFolder()
>> if members:
>> try:
>>- folder = members[id]
>>+ folder = getattr(members, id)
>> if verifyPermission and not _checkPermission(View,
>> folder):
>> # Don't return the folder if the user can't get
>> # to it.
>> return None
>> return folder
>>- except KeyError: pass
>>+ except AttributeError:
>>+ pass
>> return None
>>
>> def getHomeUrl(self, id=None, verifyPermission=0):
>>
>>
>>_______________________________________________
>>CMF-checkins mailing list
>>CMF-checkins at zope.org
>>http://mail.zope.org/mailman/listinfo/cmf-checkins
>
>
--
Florent Guillaume, Nuxeo (Paris, France)
+33 1 40 33 79 87 http://nuxeo.com mailto:fg at nuxeo.com
More information about the CMF-checkins
mailing list