[Zope-dev] Soft links again
Shane Hathaway
shane@digicool.com
Tue, 26 Sep 2000 15:49:21 -0400
"Ibaņez Palomar Juan David" wrote:
>
> Hi all,
>
> First, I'm using Zope 2.2.1 (Debian package).
>
> I've been trying to implement zope objects that behave like unix soft
> links. The message
>
> http://lists.zope.org/pipermail/zope-dev/2000-July/005963.html
>
> by Shane proposes an implementation based in the __of__ method:
> (snip)
> but it fails when I try to create an instance.
Try this. I failed to account for the fact that sometimes the object is
not in context and therefore the linked object will not be found.
def __of__(self, parent):
try:
ob = self.restrictedTraverse(self.path)
except:
# We're not in context or the object was not found. Default to
self.
return self
else:
return getattr(ob, 'aq_base', ob).__of__(parent)
Keep in mind, though, that there are all kinds of security
implications. Someone will have to think hard about security before
this is viable.
OTOH perhaps it's really simple. Try this as the last line instead:
return getattr(ob, 'aq_inner', ob).__of__(parent)
This way, the security context might be retained. If it doesn't work,
try changing the last line to:
return ob.__of__(parent)
Shane