[Twisted-web] nevow/stan + pregenerated HTML

Mike Warren spam at mike-warren.com
Wed Jun 2 16:59:11 MDT 2004

Mike Warren <spam at mike-warren.com> writes:

> Is there any way to do this? Ideas?

Of course, I got an idea right after I sent this. But, I think I might
have found a bug in Nevow (although I'm pretty new at this; *please*
correct me if I'm wrong).

I figured I could make my own class implementing
nevow.inevow.ISerializable and skip the whole "quoting" phase
altogether. I did this:

| class RawString(str):
|     __implements__ = nevow.inevow.ISerializable
|     def serialize(self, context):
|         return str(self)

...however, in nevow/flat/ten.py:

| # FIXME: hack!
| # and the way serialize is implemented is possibly an
| # abuse of the compy system, but hey, it WORKS. :)
| cachedAdapters = {}
| def getSerializer(obj):
|     if hasattr(obj, '__class__'):
|         klas = obj.__class__
|     else:
|         klas = type(obj)
|     adapter = cachedAdapters.get(klas, None)
|     if adapter is not None:
|         return adapter
|     #print "Adding cache entry for ",klas
|     registry = compy.getRegistry(None)
|     fromInterfaces = compy.classToInterfaces(klas)
|     for fromInterface in fromInterfaces:
|         #print " trying: ", fromInterface
|         adapter = registry.getAdapterFactory(
|             fromInterface,
|             inevow.ISerializable,
|             None)
|         if adapter is not None:
|             cachedAdapters[klas] = adapter
|             return adapter
|     return None

...it appears that this code presumes that one needs an adaptor to the
ISerializable interface. My object already implements this, however,
so I added these two lines (after the " trying:" print statement):

|         if fromInterface == inevow.ISerializable:      
|             return lambda object,x: object.serialize(x)

...which makes everything do exactly what I want (namely, in my
original code, I return a RawString for my pregenerated HTML and it
makes it through fine). [Of course, I realise I might end up with
non-conforming XHTML if I fuck up my pregeneration, but hey...]

Am I right? Should I file a patch? (After adding code to cache the
lambda, too)


mike [at] mike [dash] warren [dot] com
gpg --keyserver --recv-key 579911BD
87F2 4D98 BDB0 0E90 EE2A 0CF9 1087 0884 5799 11BD

More information about the Twisted-web mailing list