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

2001-12-06 Thread John Ziniti

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  -  [EMAIL PROTECTED]
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 )



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

2001-12-06 Thread Wolfram Kerber

__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 [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
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  -  [EMAIL PROTECTED]
 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  -  [EMAIL PROTECTED]
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 )



Re: [Zope-dev] getPhysicalPath?

2001-03-18 Thread richard

Brian Lloyd wrote:
   Is there a simple method like getAcquistionPath() that tells
  me how I was
   required without having to do some sub optimal REQUEST
  variable hacking /
   string matching?
  
 
  I don't know of any (but that doesn't mean there isn't one).  But
  couldn't you walk up the aq_parent?
 
 Acquisition tip-o-the-day: you can use:
 
 print object.aq_chain
 
 The aq_chain attribute (computed at time of access) provides
 a list (in reverse order) of the objects in the acquisition
 path.

   Is this *cough* documented anywhere?

   grep -r on the Zope source comes up with (not counting test_AqAlg.py):

./lib/Components/ExtensionClass/src/Acquisition.c:module_aq_chain(PyObject
*ignored, PyObject *args)
./lib/Components/ExtensionClass/src/Acquisition.c:  {"aq_chain",
(PyCFunction)module_aq_chain, METH_VARARGS, 
./lib/Components/ExtensionClass/src/Acquisition.c:   "aq_chain(ob [,
containment]) -- "

   So nobody (including the various Products I have installed) uses this
incredibly useful attribute. I have numerous places in my source where I
loop through aq_parent attributes.

   It'd be nice to have even a mention in the acquisition documentation.
Poking around the Acquisition C source tells me that there's another
attribute, aq_inner, that isn't documented either.


  Richard

-- 
Richard Jones
[EMAIL PROTECTED]
Senior Software Developer, Bizar Software (www.bizarsoftware.com.au)

___
Zope-Dev maillist  -  [EMAIL PROTECTED]
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 )



Re: [Zope-dev] getPhysicalPath?

2001-03-16 Thread Tom Jenkins

 
 Is there a simple method like getAcquistionPath() that tells me how I was
 required without having to do some sub optimal REQUEST variable hacking /
 string matching?
 

I don't know of any (but that doesn't mean there isn't one).  But 
couldn't you walk up the aq_parent?

-- 
Tom Jenkins
devIS - Development Infostructure
http://www.devis.com


___
Zope-Dev maillist  -  [EMAIL PROTECTED]
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 )



RE: [Zope-dev] getPhysicalPath?

2001-03-16 Thread Brian Lloyd

  Is there a simple method like getAcquistionPath() that tells 
 me how I was
  required without having to do some sub optimal REQUEST 
 variable hacking /
  string matching?
  
 
 I don't know of any (but that doesn't mean there isn't one).  But 
 couldn't you walk up the aq_parent?

Acquisition tip-o-the-day: you can use:

print object.aq_chain

The aq_chain attribute (computed at time of access) provides 
a list (in reverse order) of the objects in the acquisition 
path.

Hope this helps!


Brian Lloyd[EMAIL PROTECTED]
Software Engineer  540.371.6909  
Digital Creations  http://www.digicool.com 




___
Zope-Dev maillist  -  [EMAIL PROTECTED]
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 )



Re: [Zope-dev] getPhysicalPath?

2001-03-16 Thread Christian Scholz

Hi!

 Ahh... thanks Brian. Thats a new one to me :)

To me, aswell. Is this documented somewhere? ;-)

And can someone explain to us where the differences between
aq_chain and getPhysicalPath() are? Actually getPhysicalPath()
seems also to walk up aq_parent. Or am I missing something?

regards,
  Christian
  

 
  The aq_chain attribute (computed at time of access) provides 
  a list (in reverse order) of the objects in the acquisition 
  path.
  
  Hope this helps!
  
  
  Brian Lloyd[EMAIL PROTECTED]
  Software Engineer  540.371.6909  
  Digital Creations  http://www.digicool.com 
  
  
  
  
  ___
  Zope-Dev maillist  -  [EMAIL PROTECTED]
  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  -  [EMAIL PROTECTED]
 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 )

-- 
COM.lounge  http://comlounge.net/
communication  design [EMAIL PROTECTED]

___
Zope-Dev maillist  -  [EMAIL PROTECTED]
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 )



RE: [Zope-dev] getPhysicalPath?

2001-03-16 Thread Brian Lloyd

 To me, aswell. Is this documented somewhere? ;-)

It's not in the Acquisition.stx in the ExtensionClass docs - 
probably they were never updated when it was added. I think 
that aq_chain is most useful as a debugging aid rather than 
something one would use in an application (which is not to 
say that it shouldn't be documented). It would be a good idea 
to add this to the Collector as a documentation issue.


 And can someone explain to us where the differences between
 aq_chain and getPhysicalPath() are? Actually getPhysicalPath()
 seems also to walk up aq_parent. Or am I missing something?

The sequence returned by aq_chain is the actual chain of 
'acquisition contexts', or the 'access path' rather than 
the actual containment path. For example, given the object 
hierarchy:

app
  FolderA
index_html
  FolderB

If you say: ob = app.FolderA.FolderB.FolderA.index_html
then the aq_chain will be:

[index_html, FolderA, FolderB, FolderA, app]

This list is created by basically taking the 'aq_parent' of 
each object from 'ob' on up until there are no more aq_parents.

The actual *containment* path is different; in our example 
the containment path would be: 

[index_html, FolderA, app]

To derive the containment path, instead of just walking up 
the aq_parents you have to take the aq_inner (to get the 
innermost wrapping of the object) for each object and then 
take the aq_parent of that. For example (not tested, but 
should work):

def containment_chain(object):
  # return a list similar to aq_chain, but consisting
  # only of the actual containment path.
  result = []
  result.append(object)
  while hasattr(object, 'aq_inner'):
  innermost_wrapping = object.aq_inner
  true_parent = innermost_wrapping.aq_parent
  result.append(true_parent)
  object = true_parent
  return result

Hope this helps!

Brian Lloyd[EMAIL PROTECTED]
Software Engineer  540.371.6909  
Digital Creations  http://www.digicool.com 




___
Zope-Dev maillist  -  [EMAIL PROTECTED]
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 )



Re: [Zope-dev] getPhysicalPath?

2001-03-16 Thread Evan Simpson

From: "Christian Scholz" [EMAIL PROTECTED]
 And can someone explain to us where the differences between
 aq_chain and getPhysicalPath() are? Actually getPhysicalPath()
 seems also to walk up aq_parent. Or am I missing something?

"aq_chain" gives you a list of the objects traversed to get to your object,
in reverse order.

"getPhysicalPath" gives you a tuple of the Ids of all objects on the
shortest path from the root to your object.

So, given a hierarchy like this:

A__B__C
|_D
|_E

Object C has physical path ('', 'A', 'B', 'C') no matter how you get to it.
Its acquisition chain, on the other hand, depends completely on the path you
use to access it:

A/B/C = [C, B, A]
A/D/B/C = [C, B, D, A]
A/B/D/E/C = [C, E, D, B, A]

*WARNING*: "aq_chain" does *not* tell you the order in which acquisition
will search the objects.  That is more complicated.

Cheers,

Evan @ digicool


___
Zope-Dev maillist  -  [EMAIL PROTECTED]
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 )



RE: [Zope-dev] getPhysicalPath?

2001-03-16 Thread Michel Pelletier



On Fri, 16 Mar 2001, Brian Lloyd wrote:

  To me, aswell. Is this documented somewhere? ;-)

 It's not in the Acquisition.stx in the ExtensionClass docs -
 probably they were never updated when it was added. I think
 that aq_chain is most useful as a debugging aid rather than
 something one would use in an application (which is not to
 say that it shouldn't be documented). It would be a good idea
 to add this to the Collector as a documentation issue.

A better place would be the sourceforge issue tracker for the dev guide:

http://sourceforge.net/projects/zope-devel

-Michel


___
Zope-Dev maillist  -  [EMAIL PROTECTED]
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] getPhysicalPath?

2001-03-15 Thread Andy McKay

getPhysicalPath returns the physical path to an object ignoring how I got
there through Acquistion. There are a bunch of variables in the REQUEST that
tell me how I got to an object, but we have an object that is messing around
with traversal, so the REQUEST variables arent ideal.

Is there a simple method like getAcquistionPath() that tells me how I was
required without having to do some sub optimal REQUEST variable hacking /
string matching?

Thanks.

--
  Andy McKay.




___
Zope-Dev maillist  -  [EMAIL PROTECTED]
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 )



Re: [Zope-dev] getPhysicalPath?

2001-03-15 Thread Andy McKay

Should be "how I was acquired" not required. Duh.
--
  Andy McKay.


- Original Message -
From: "Andy McKay" [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Thursday, March 15, 2001 6:26 PM
Subject: [Zope-dev] getPhysicalPath?


 getPhysicalPath returns the physical path to an object ignoring how I got
 there through Acquistion. There are a bunch of variables in the REQUEST
that
 tell me how I got to an object, but we have an object that is messing
around
 with traversal, so the REQUEST variables arent ideal.

 Is there a simple method like getAcquistionPath() that tells me how I was
 required without having to do some sub optimal REQUEST variable hacking /
 string matching?

 Thanks.

 --
   Andy McKay.




 ___
 Zope-Dev maillist  -  [EMAIL PROTECTED]
 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  -  [EMAIL PROTECTED]
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 )