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: class SoftLink (SimpleItem): def __init__(self, path): self.path = path def __of__(self, parent): ob = self.restrictedTraverse(self.path) return getattr(ob, 'aq_base', ob).__of__(parent) but it fails when I try to create an instance: Traceback (innermost last): File /usr/lib/zope/lib/python/ZPublisher/Publish.py, line 171, in publish File /usr/lib/zope/lib/python/ZPublisher/mapply.py, line 160, in mapply (Object: manage_addImportedSubject) File /usr/lib/zope/lib/python/ZPublisher/Publish.py, line 112, in call_object (Object: manage_addImportedSubject) File /var/lib/zope/Products/LLEU/subjects.py, line 1129, in manage_addImportedSubject (Object: Traversable) File /usr/lib/zope/lib/python/OFS/ObjectManager.py, line 250, in _setObject (Object: Traversable) File /usr/lib/zope/lib/python/OFS/ObjectManager.py, line 236, in _getOb (Object: Traversable) AttributeError: A00 A little of debug shows that the object has been added (line 249, see below), the exception raises when it tries to get the object (line 250). The hasattr function (line 234) returns false but the object has been added (it's in the __dict__) attribute and its __off__ method is called when the hasattr function is called. What I'm doing wrong? Thanks, david ObjectManager.py: class ObjectManager( ... def _setOb(self, id, object): setattr(self, id, object) def _delOb(self, id): delattr(self, id) def _getOb(self, id, default=_marker): 234 if not hasattr(aq_base(self), id): if default is _marker: 236 raise AttributeError, id return default return getattr(self, id) def _setObject(self,id,object,roles=None,user=None, set_owner=1): v=self._checkId(id) if v is not None: id=v try: t=object.meta_type except: t=None self._objects=self._objects+({'id':id,'meta_type':t},) # Prepare the _p_jar attribute immediately. _getCopy() may need it. if hasattr(object, '_p_jar'): object._p_jar = self._p_jar 249 self._setOb(id,object) 250 object=self._getOb(id)
"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
Hi, i have read the two messages about Soft Link, and i tried to work with it, because it it very important for my Product. The problem is that the Soft Link class won't work and i don't know why. I use zope 2.2.2 and python 1.5.2. root: -myproductfolder -SoftLink to testdtmldoc -testfolder -testdtmldoc In myproduct i have the following function, the class SoftLink is the same as of Shane Hathaway. I wan't to add a SoftLink in myproductfolder which links to testdtmldoc. When i call the function manage_addSoftLink nothing happens?? def manage_addSoftLink(self, REQUEST=None): ..... obj=SoftLink('Test/link') self._setObject('TestSoftLink',obj) Whats going wrong, or did i missunderstand something? Who can help? as Shane Hathaway schrieb:
[cut] 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
_______________________________________________ Zope-Dev maillist - Zope-Dev@zope.org http://lists.zope.org/mailman/listinfo/zope-dev ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope )
Okay, I've posted a proof of concept. Please keep in mind that this could be dangerous in terms of security, although I've done a couple of things to make it safer. Also, there's currently a buglet in acquisition that makes it so that you can only perform the actions on the symlink which "anonymous" is allowed to do. http://www.zope.org/Members/hathawsh/Symlink/index_html Shane Andre Schubert wrote:
Hi,
i have read the two messages about Soft Link, and i tried to work with it, because it it very important for my Product. The problem is that the Soft Link class won't work and i don't know why. I use zope 2.2.2 and python 1.5.2. root: -myproductfolder -SoftLink to testdtmldoc -testfolder -testdtmldoc
In myproduct i have the following function, the class SoftLink is the same as of Shane Hathaway. I wan't to add a SoftLink in myproductfolder which links to testdtmldoc. When i call the function manage_addSoftLink nothing happens??
def manage_addSoftLink(self, REQUEST=None): ..... obj=SoftLink('Test/link') self._setObject('TestSoftLink',obj)
Whats going wrong, or did i missunderstand something? Who can help?
as
Shane Hathaway schrieb:
[cut] 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
_______________________________________________ Zope-Dev maillist - Zope-Dev@zope.org http://lists.zope.org/mailman/listinfo/zope-dev ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope )
_______________________________________________ Zope-Dev maillist - Zope-Dev@zope.org http://lists.zope.org/mailman/listinfo/zope-dev ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope )
On Wed, 27 Sep 2000 09:06:18 -0400, Shane Hathaway <shane@digicool.com> wrote:
Also, there's currently a buglet in acquisition that makes it so that you can only perform the actions on the symlink which "anonymous" is allowed to do.
Wooohoooo! Someone else that agrees this is a bug in Acquisition. Full report and patch at http://classic.zope.org:8080/Collector/1066/view Toby Dickenson tdickenson@geminidataloggers.com
Toby Dickenson wrote:
On Wed, 27 Sep 2000 09:06:18 -0400, Shane Hathaway <shane@digicool.com> wrote:
Also, there's currently a buglet in acquisition that makes it so that you can only perform the actions on the symlink which "anonymous" is allowed to do.
Wooohoooo! Someone else that agrees this is a bug in Acquisition.
Full report and patch at http://classic.zope.org:8080/Collector/1066/view
Not only are you 100% correct, but we were planning to do the same thing! You were several steps ahead of us. The patch works perfectly, although I added a couple of comments. Sorry the patch didn't get applied sooner. Shane
Hi Shane, and thanks for Symlink, it's a big step towards solve the problem, but remains an issue... It would be great if the symbolic link could have a different id than the object referenced. But with the __of__ based solution "link.id" is always "referenced_object.id". How this could be done?
Okay, I've posted a proof of concept. Please keep in mind that this could be dangerous in terms of security, although I've done a couple of things to make it safer. Also, there's currently a buglet in acquisition that makes it so that you can only perform the actions on the symlink which "anonymous" is allowed to do.
http://www.zope.org/Members/hathawsh/Symlink/index_html
Shane
On Fri, 29 Sep 2000, Iba�ez Palomar Juan David wrote:
It would be great if the symbolic link could have a different id than the object referenced. But with the __of__ based solution "link.id" is always "referenced_object.id".
How this could be done?
I think you'd need a special kind of wrapper. It would have the ability to act as if it were the object itself while transparently overriding specific attributes. I've pondered creating such a wrapper before, but it crashed so much that I eventually moved on to easier stuff. :-) I think the ability is all there in ExtensionClass, but the details are quite difficult. Shane
On Fri, 29 Sep 2000, Ibañez Palomar Juan David wrote:
It would be great if the symbolic link could have a different id than the object referenced. But with the __of__ based solution "link.id" is always "referenced_object.id".
How this could be done?
I think you'd need a special kind of wrapper. It would have the ability to act as if it were the object itself while transparently overriding specific attributes. I've pondered creating such a wrapper before, but it crashed so much that I eventually moved on to easier stuff. :-)
I think the ability is all there in ExtensionClass, but the details are quite difficult.
Shane
If I've understanded it right it means I must go to C risking my mental sanity (1), other possibility would be to redesign/reimplement my app (2). Ummhh... I think I'll try 1, it seems more entertaining :), so wish me luck. thanks, david
participants (4)
-
al028823@alumail.uji.es -
Andre Schubert -
Shane Hathaway -
Toby Dickenson