[Zope] overload __getattr__ in brains-class?
Fri, 19 Jul 2002 01:29:31 +0200
Am 18.07.2002, 21:54 Uhr
schrub Dieter Maurer <firstname.lastname@example.org>:
> > objects=Results.Results(result,brain,parent,None)
> > Now whatever I try, either some other __getattr__ seems to be called
> > since I can get none of my "simulated" attributes to show up.
> It should work with modern Zope versions.
> I once tried and failed with an older version (Zope 2.1.6).
> My "__getattr__" led to an infinite loop.
I'm using 2.5.1 with python 2.1.3. AFAIK this is fairly recent.
So either I'm making a some tragically stupid mistake or something
really strange is going on... Let me elaborate a bit (sorry for what
follows, it's rather longish):
The standard procedure for simulating class attributes in Python I
normally use is (set discussions of efficiency aside for a moment):
self.realattrib_a="this is real"
if key in self.__dict__.keys():
return "simulated attribute"
where "realattrib_a" is the only genuine attribute of class a and
everything else should have a value of "simulated attribute"
This - of course - works perfectly when called with Python from the
Now I take this definition and use it as my brain-class. In my parent
class (which is a CMF class derived from PortalContent and
DefaultDublinCoreImpl and essentially represents an arbitrary list of
results of a RDBMS-Query) I do the following:
<some logic to construct a query string from params>
Next I have a DTML-Method that essentially contains:
And to my astonishment this already barfs on
'<dtml-with expr="result">' with a traceback
telling me that the __init__ of class a is flawed since there is no
??? How can an __init__-method complain about nonexisting attributes
when all I'm trying to do is define some? Ok, I tell myself, if Zope
wants me to live without sensible __init__-methods on brain-classes, I
can cope with that. I completely remove the __init__-method and the next
traceback I get is:
File /usr/lib/zope/lib/python/DocumentTemplate/DT_With.py, line 76, in render (Object: result)
File /usr/lib/zope/lib/python/DocumentTemplate/DT_Util.py, line 169, in eval (Object: realattrib_a)
File <string>, line 2, in f NameError: global name 'realattrib_a' is not defined
I really don't know what to try next. I know there has to be a really
simple solution to this problem, since it is such a simple thing to come
up with. But I have to admit, I'm completely lost. No ideas left to try,
no hope, no sunshine...
Perhaps I just didn't follow standard procedures for this situation, but
then I'm guilty of not having tried the appropriate search term with
zope.org or google. I'm stumped.
Internetmanufaktur Jo Meder ---------------------- Berlin, Germany
http://www.meder.de/ ------------------- fon: ++49-30-417 17 63 33
Kollwitzstr. 75 ------------------------ fax: ++49-30-417 17 63 45
10435 Berlin --------------------------- mob: ++49-170- 2 98 89 97
Public GnuPG-Key ---------- http://www.meder.de/keys/jo-pubkey.txt