[Twisted-web] twisted.web.template output encoding

Phil Mayers p.mayers at imperial.ac.uk
Sun Nov 27 04:43:15 EST 2011

On 11/26/2011 04:52 PM, exarkun at twistedmatrix.com wrote:

> as ` �. Consequently, callers of `formatFailure� will probably
> mishandle the result - the caller in `twisted.web.server� does, at
> least, including the bytes in a page with a content type of "text/html".

Amusingly for a unicode-related email, Thunderbird mangled your 
close-quotes for me ;o)

> One solution is to add support for named entities or numeric character
> references to twisted.web.template. Very likely this is a good idea
> regardless (Nevow supported these).

Always useful.

> Perhaps another question is whether the encoding used by
> `twisted.web.template� should be a parameter. A related question raised
> might be whether `twisted.web.template� should encoded to bytes at all,
> or delegate the responsibility for that to code closer to a socket.

FWIW that would be my instinct. If t.w.template emitted unicode, then 
code closer to the socket could decide on the encoding. Presumably the 
default would be to encode to utf-8, but there are cases where you might 
want to do otherwise e.g. some HTML has already been streamed to the 
client with no encoding specified - which equates to iso-8859-1 IIRC? - 
and you want to match that.

Conceptually, HTML is better treated as unicode too.

More information about the Twisted-web mailing list