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


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?



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):
        if v is not None: id=v
        try:    t=object.meta_type
        except: t=None
        # 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)

Zope-Dev maillist  -  [EMAIL PROTECTED]
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope )

Reply via email to