[Zope] How to override DTMLFile? (solved)

Peter Bengtsson mail@peterbe.com
Fri, 23 May 2003 15:41:16 +0100


I got it!

class CTDTMLFile(DTMLFile):
     def __init__(self, name, _prefix=None, **kw):
         " doc string "
         <do whatever needs to be done>
         apply(DTMLFile.__init__, (self, name, _prefix), kw)

     def _exec(self, bound_data, args, kw):
         " doc string "
         zope = bound_data['context']
         <do whatever needs to be done>
         return apply(DTMLFile._exec, (self, bound_data, args, kw))


The aim of this hack is for me to be able to control whether DTML Methods 
should be run from the filesystem or as DTML Method objects.
This will hopefully lead to a all-purpose product for whatever reasons one 
might have.


At 12:57 2003-05-23 +0100, you wrote:
>I want to override DTMLFile from Globals in my own special product.
>I managed to do this::
>
>class PeterDTMLFile(DTMLFile):
>     def foo(self):
>         return "works"
>
>
>Then from somewhere else I do::
>
>manage_edit = PeterDTMLFile('dtml/manage_edit', globals())
>
>This works but doing <dtml-var foo> raises a KeyError.
>
>I've looked at Localizer and how they override DTMLFile's __init__ and 
>_exec method.
>But if I try to do::
>
># pointless inheritance hack but for testing
>class PeterDTMLFile(DTMLFile):
>     def __init__(self, name, _prefix=None, **kw):
>         apply(DTMLFile.inheritedAttribute('__init__'),
>               (self, name, _prefix), kw)
>
>Which in effect is pretty pointless, I get the following error when trying 
>my manage_edit::
>
>
>Traceback (innermost last):
>   Module ZPublisher.Publish, line 98, in publish
>   Module ZPublisher.mapply, line 62, in mapply
>AttributeError: 'None' object has no attribute 'co_varnames'
>
>
>So, can anybody tell me how to override the DTMLFile class (and possible 
>also the PageTemplateFile)
>
>Grateful,
>Peter
>
>_______________________________________________
>Zope maillist  -  Zope@zope.org
>http://mail.zope.org/mailman/listinfo/zope
>**   No cross posts or HTML encoding!  **
>(Related lists - http://mail.zope.org/mailman/listinfo/zope-announce
>http://mail.zope.org/mailman/listinfo/zope-dev )