[Twisted-web] Rendering unicode instances.

Andrew Bennetts twisted-web@twistedmatrix.com
Wed, 28 Jan 2004 22:12:56 +1100


On Wed, Jan 28, 2004 at 11:11:43AM +0100, Syver Enstad wrote:
> 
> What does one do to render Unicode objects with twisted.web (I am
> using woven also). I get UnicodeError's if I try to pass a unicode
> object that contains characters not in ASCII today.
> 
> It would be nice if it was as simple as calling a method on the
> request setting output encoding which set the encoding in the HTTP
> headers and wrapped the output stream with an encoder that
> transparently encoded Unicode objects with the chosen encoding. If
> such a method is not implemented (I haven't seen one) what would be a good
> way to solve this problem.

Well, there's no explicit unicode support in Twisted Web that I know of.

However, the workaround should be as simple as calling a method to set the
response header for your desired encoding, and making sure you encode your
unicode objects with that encoding before passing them to Twisted Web ;)

Perhaps Twisted Web should default to UTF-8, and automatically encode
unicode objects with that encoding, unless a 'setUnicodeEncoding' method is
called.  Obviously this would need to make sure the appropriate header is
set.  Patches for this sort of thing are probably welcome :)

-Andrew.