[Zope] How to override DTMLFile?

Passin, Tom tpassin@mitretek.org
Fri, 23 May 2003 10:40:04 -0400


[ Peter Bengtsson]
>=20
> I want to override DTMLFile from Globals in my own special product.
> I managed to do this::
>=20
> class PeterDTMLFile(DTMLFile):
>      def foo(self):
>          return "works"
>=20
>=20

I have not tried it in Zope, but it seems to me that you ought be be
able to create new class methods just by assignment to the class
(outside of the class definition).  This works with normal Python
classes, but I do not know how far a DTMLFile class differs from a
normal class, nor how restricted product code might be compared with
normal Python code. =20

Here is an example -

class Class1:
    pass

def foo(self):
    print 'This is "foo"'

Class1.foo =3D foo

obj =3D Class1()
obj.foo()
# prints This is "foo"

Of course, this would affect all instances of DTMLFile and I am not
clear if you really intend that or not.

Cheers,

Tom P