[Zope-dev] Re: proxies

2008-01-16 Thread Philipp von Weitershausen

Chris Withers wrote:

Hi All,

I saw the zope.proxies module and wondered if it might be able to help 
me with two problems I need to solve:


- can these proxies be used to keep track of a traversal path in much 
the same way (although no seperate containment and context chains 
needed) as the old Zope 2 acquisition wrappers did?


We generally assign a __parent__ attribute to objects that have a 
hierarchical parent object. Objects have to explicitly allow this by 
providing ILocation (or the derived IContained). If they're not ok with 
having __parent__ assigned, we wrap them in a persistent containment 
proxy [1]. It will make the original object behave normally, except for 
the ILocation/IContained API (__parent__, __name__ attributes). It will 
intercept those values and store them inside the pickled proxy. THat way 
the object won't ever see the __parent__ attribute assigned to itself.


- once a proxy has been created, the the object it's proxying for be 
replaced?


I don't understand this question.

You'll have to explicitly do the wrapping and then continue to work with 
the wrapped object. Container implementations use the following kind of 
code in __setitem__ [2]:


if not IContained.providedBy(object):
if ILocation.providedBy(object):
zope.interface.alsoProvides(object, IContained)
else:
object = ContainedProxy(object)

and then they add 'object' to their datastructure (e.g. a BTree) and 
assign object.__parent__ and object.__name__.



[1] zope.app.container.contained.ContainedProxy
[2] zope.app.container.contained.containedEvent
___
Zope-Dev maillist  -  Zope-Dev@zope.org
http://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
http://mail.zope.org/mailman/listinfo/zope-announce

http://mail.zope.org/mailman/listinfo/zope )


[Zope-dev] Re: proxies

2008-01-16 Thread Philipp von Weitershausen

P.S.: This is explained in detail in my book, chapter on containers.


___
Zope-Dev maillist  -  Zope-Dev@zope.org
http://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
http://mail.zope.org/mailman/listinfo/zope-announce

http://mail.zope.org/mailman/listinfo/zope )


[Zope-dev] Re: proxies

2008-01-16 Thread Chris Withers

Philipp von Weitershausen wrote:
- can these proxies be used to keep track of a traversal path in much 
the same way (although no seperate containment and context chains 
needed) as the old Zope 2 acquisition wrappers did?


We generally assign a __parent__ attribute to objects that have a 
hierarchical parent object. 


Okay, but I'm talking about a context-based chain, ie: keeping track of 
what objects were traversed through to obtain the current object.
Traversed here does *not* mean Zope 3 url traversal which si why I'm 
looking for something akin to Zope 2's acquisition wrappers, but without 
the weird containment/context dual wrapping.


- once a proxy has been created, the the object it's proxying for be 
replaced?


I don't understand this question.


 x = proxy(y)
 a.x = x
 b.x = x

I now want to do something like:

 x.replace(y,z)

...so a and b will still keep their references, but the object being 
proxied for has been changed.


cheers,

Chris

--
Simplistix - Content Management, Zope  Python Consulting
   - http://www.simplistix.co.uk
___
Zope-Dev maillist  -  Zope-Dev@zope.org
http://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
http://mail.zope.org/mailman/listinfo/zope-announce

http://mail.zope.org/mailman/listinfo/zope )


AW: [Zope-dev] Re: proxies

2008-01-16 Thread Roger Ineichen
Hi Chris

Probably take a look at the z3c.proxy package.
This implements a IContainer proxy which will proxy
items of a (proxyfied) container. This could give you 
some ideas how you can proxy items on the fly to 
your needs.

The z3c.proxy package contains a README.txt file with some samples.

Also note that you will need the proxy aware copierer and mover if
your objects support copy/paste.

Regards
Roger Ineichen

 Betreff: [Zope-dev] Re: proxies
 
 Philipp von Weitershausen wrote:
  - can these proxies be used to keep track of a traversal 
 path in much 
  the same way (although no seperate containment and context chains
  needed) as the old Zope 2 acquisition wrappers did?
  
  We generally assign a __parent__ attribute to objects that have a 
  hierarchical parent object.
 
 Okay, but I'm talking about a context-based chain, ie: 
 keeping track of what objects were traversed through to 
 obtain the current object.
 Traversed here does *not* mean Zope 3 url traversal which si 
 why I'm looking for something akin to Zope 2's acquisition 
 wrappers, but without the weird containment/context dual wrapping.
 
  - once a proxy has been created, the the object it's 
 proxying for be 
  replaced?
  
  I don't understand this question.
 
   x = proxy(y)
   a.x = x
   b.x = x
 
 I now want to do something like:
 
   x.replace(y,z)
 
 ...so a and b will still keep their references, but the 
 object being proxied for has been changed.
 
 cheers,
 
 Chris
 
 --
 Simplistix - Content Management, Zope  Python Consulting
 - http://www.simplistix.co.uk 
 ___
 Zope-Dev maillist  -  Zope-Dev@zope.org
 http://mail.zope.org/mailman/listinfo/zope-dev
 **  No cross posts or HTML encoding!  ** (Related lists -  
 http://mail.zope.org/mailman/listinfo/zope-announce
  http://mail.zope.org/mailman/listinfo/zope )
 

___
Zope-Dev maillist  -  Zope-Dev@zope.org
http://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope )


Re: [Zope-dev] Re: proxies

2008-01-16 Thread Gary Poster


On Jan 16, 2008, at 3:19 AM, Chris Withers wrote:


Philipp von Weitershausen wrote:
- can these proxies be used to keep track of a traversal path in  
much the same way (although no seperate containment and context  
chains needed) as the old Zope 2 acquisition wrappers did?
We generally assign a __parent__ attribute to objects that have a  
hierarchical parent object.


Okay, but I'm talking about a context-based chain, ie: keeping track  
of what objects were traversed through to obtain the current object.
Traversed here does *not* mean Zope 3 url traversal which si why I'm  
looking for something akin to Zope 2's acquisition wrappers, but  
without the weird containment/context dual wrapping.


Although I'm not quite sure which Zope 2 issue you mean by the weird  
containment/context dual wrapping, I suspect that zc.shortcut's  
traversal proxies do exactly what you want.  An old task of mine is to  
split out this functionality into something like zc.traversed.  But  
it does what you want, and you don't have to use the shortcuts, and it  
has the necessary bits for it all to work out.


Gary

___
Zope-Dev maillist  -  Zope-Dev@zope.org
http://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
http://mail.zope.org/mailman/listinfo/zope-announce

http://mail.zope.org/mailman/listinfo/zope )