Re: [Zope3-Users] Persistent obj with attr hooks

2009-07-23 Thread Marius Gedminas
On Thu, Jul 23, 2009 at 01:41:57PM -0400, Jim Pharis wrote:
> I have a class that inherits from Persistent but also needs to hook into
> setattr and getattribute.
> 
> class Test(Persistent)
>...
>   def __setattr__(self, name, val)
>   def __getattribute__(self, name)
> 
> Before when this class inherited from object the __setattr__ and
> __getattribute__ calls were simple and straight forward with
> object.__getattribute__(name). However, now that I inherent from Persistent,
> the equivalent Persistent.__getattribute__ and Persisent.__setattr__ don't
> seem to set/get my attributes.
> 
> Can someone help me out. What call should I be using instead?

Works For Me(TM):

>>> from persistent import Persistent
>>> class Test(Persistent):
... def __setattr__(self, name, value):
... print "setting %s to %r" % (name, value)
... super(Test, self).__setattr__(name, value)
... def __getattribute__(self, name):
... print "getting %s" % (name)
... return super(Test, self).__getattribute__(name)
...
>>> apple = Test()
>>> apple.color = 'green'
setting color to 'green'
>>> apple.color
getting color
'green'

Show us your code if you want more advice.

Marius Gedminas
-- 
IBM motto: "TEN vowels? Don't you know vowels are scrd?"
-- Linus Torvalds


signature.asc
Description: Digital signature
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


[Zope3-Users] Persistent obj with attr hooks

2009-07-23 Thread Jim Pharis
I have a class that inherits from Persistent but also needs to hook into
setattr and getattribute.

class Test(Persistent)
   ...
  def __setattr__(self, name, val)
  def __getattribute__(self, name)

Before when this class inherited from object the __setattr__ and
__getattribute__ calls were simple and straight forward with
object.__getattribute__(name). However, now that I inherent from Persistent,
the equivalent Persistent.__getattribute__ and Persisent.__setattr__ don't
seem to set/get my attributes.

Can someone help me out. What call should I be using instead?

- Jim
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users