[Python-Dev] Object customization (was: Arbitrary attributes on funcs and methods)
Vladimir Marangozov
Vladimir.Marangozov@inrialpes.fr
Fri, 14 Apr 2000 17:30:31 +0200 (CEST)
Skip Montanaro wrote:
>
> Barry's proposal would allow the Spam.eggs author to attach an attribute to
> it:
>
> class Spam:
> def eggs(self, a):
> "doc"
> return a
> eggs.__zope_access__ = "private"
>
> I think the solution you're proposing is
>
> class Spam:
> class EggsMethod:
> def __call__(self, a):
> "doc"
> return a
> __zope_access__ = "private"
> eggs = EggsMethod()
>
> This seems to work, but also seems like a lot of extra baggage (and a
> performance hit to boot) to arrive at what seems like a very simple concept.
>
If you prefer embedded definitions, among other things, you could do:
__zope_access__ = { 'Spam' : 'public' }
class Spam:
__zope_access__ = { 'eggs' : 'private',
'eats' : 'public' }
def eggs(self, ...): ...
def eats(self, ...): ...
or have a completely separate class/structure for access control
(which is what you would do it in C, btw, for existing objects
to which you can't add slots, ex: file descriptors, mem segments, etc).
--
Vladimir MARANGOZOV | Vladimir.Marangozov@inrialpes.fr
http://sirac.inrialpes.fr/~marangoz | tel:(+33-4)76615277 fax:76615252