[Zope-dev] getPhysicalPath differs for function vs. __getattr__

Wolfram Kerber wk@gallileus.de
Thu, 6 Dec 2001 17:46:17 +0100


__getattr__ gets the 'true self' as argument while other methods always get
an acquisition wrapped self, this is by design. Usually it's not a good idea
to override __getattr__ of acquisition aware objects.


----- Original Message -----
From: "John Ziniti" <jziniti@speakeasy.org>
To: <zope-dev@zope.org>
Sent: Thursday, December 06, 2001 5:06 PM
Subject: [Zope-dev] getPhysicalPath differs for function vs. __getattr__


> Sorry the subject is not so discriptive, but
> here is the issue I am dealing with.  I wonder
> whether this has to do with the way Zope deals
> with objects or has something to do with Python:
>
> I have an Python Product class "Object".  With
> the following bits of code, I get different results
> from a <dtml-var>, depending on what I use.
>
> class Object(PropertyManager, Implicit, Item):
>      def get_path(self):
>          """Return a path to myself"""
>          path=string.join(self.getPhysicalPath()[1:], '/')
>          return path
>
>      def __getattr(self, attr):
>          """Return a path to myself"""
>          if attr == 'path':
>              path=string.join(self.getPhysicalPath()[1:], '/')
>              return path
>          else:
>              raise AttributeError, attr
>
> Now the following two dtml tags yield:
>
> <dtml-var "get_path()"> => /path/to/object
>
> <dtml-var "path"> => object
>
> Hopefully you see what I mean.  Why does this happen?
> Can I put it in the collector as a bug?
>
> TIA,
>
> Ziniti
>
>
> _______________________________________________
> 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 )