[Zope-dev] __setattr__ and acquisition ( was RE: __getattr__ and acquisition)

Nicholas Henke henken@seas.upenn.edu
Sun, 9 Jun 2002 15:32:27 -0400


On Friday 07 June 2002 06:44 pm, Julien Jalon wrote:
Beautiful -- thanks a ton ~~

nic
>=20
> import ExtensionClass
> import Acquisition
>=20
> class Outer(ExtensionClass.Base):
>=20
>     thing =3D ('help', 'donthelp')
>=20
> class Inner_base(Acquisition.Implicit):
>     # here the real declaration of the class
>=20
>     def aMethod(self):
>         print self.help
>=20
> class Inner(Inner_base):
>     # here the class to use
>=20
>     def __of__(self, parent):
>         real_object =3D Inner_wrapper()
>         real_object.__dict__['_parent'] =3D parent
>         real_object.__dict__['_inner'] =3D self
>         return real_object.__of__(parent)=20
>=20
> class Inner_wrapper(Inner_base):
>=20
>     def __setattr__(self,name,value):
>         if name in self.__of__(self._parent).thing:
>             self.__dict__['_inner'].__dict__[name] =3D value
>         else:
>             print "Bad attribute"
>=20
>     def __getattr__(self,name):
>         return getattr(self.__dict__['_inner'], name)
>=20
> O =3D Outer()
> I =3D Inner()
> O.I =3D I
>=20
> O.I.help =3D 'me rhonda'
> O.I.aMethod()
> I.aMethod()
> print I.__dict__
> print O.I.__dict__
> O.I.badattr =3D 'blah'
>=20
> --=20
> Julien Jalon
> <http://nuxeo.com/>
>=20
>=20
> _______________________________________________
> Zope-Dev maillist  -  Zope-Dev@zope.org
> http://lists.zope.org/mailman/listinfo/zope-dev
> **  No cross posts or HTML encoding!  **
> (Related lists -=20
>  http://lists.zope.org/mailman/listinfo/zope-announce
>  http://lists.zope.org/mailman/listinfo/zope )
>=20
>=20