[Zope] DTMLFile question -- half solution
tomas@fabula.de
tomas@fabula.de
Thu, 15 Aug 2002 15:38:02 +0200
On Thu, Aug 15, 2002 at 02:57:26PM +0200, Max M wrote:
> tomas@fabula.de wrote:
>
> >As a reminder: My aim was to use DTML methods on a product without
> >`declaring' them `by hand' in the product class definition.
> >
> This would probably work, but beware of security issues
>
> def __getattr__(self, attr):
> attr = HTMLFile('www/%s' % attr, globals())
> return attr(self, self.REQUEST)
I'm a bit wary of redefining __getattr__ in Python. It has bitten
me some times now (suddenly some very basic things are gone, like
comparison functions and that kind of stuff)
> But I am worried that it might be too slow, as it compiles the dtml for
> every call.
> So you could cache it in the object:
>
> def __getattr__(self, attr):
> if not self._dynPages.has_key(attr):
> self._dynPages[attr] = HTMLFile('www/%s' % attr, globals())
> return self._dynPages[attr](self, self.REQUEST)
>
>
> That should be more efficient.
That's basically what I do in the method `component(...)' I presented
in my original posting -- just I cache it as a class method, thus
harvesting two advantages:
(1) I had the impression that the DTML method expects to be called
as class method. So we do it!
(2) The class method is instantly available to all class instances
(I don't have each DTML method for each instance, but just once
for the whole class).
Thanks for your comments
-- tomas
> "klaatu verata niktu"
Just curious: what does that mean?