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.
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.
Andrew Bennetts andrew-twisted@puzzling.org writes:
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 ;)
I feared that that was indeed the case.
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 :)
I'll probably implement such a thing to get things going.
On Jan 28, 2004, at 5:11 AM, 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.
It's simple enough to implement. Here is what quotient does:
def render(self, request): request.setHeader("Content-type", 'text/html; charset=UTF-8')
return renderer.Renderer.render(self, request)
And then, when it wants to present a unicode string, it does:
theStr.encode('utf8')
dp
Donovan Preston dp@divmod.org writes:
It's simple enough to implement. Here is what quotient does:
def render(self, request): request.setHeader("Content-type", 'text/html; charset=UTF-8') return renderer.Renderer.render(self, request)
And then, when it wants to present a unicode string, it does:
theStr.encode('utf8')
I have a host of places that writes out string data, and which does so via woven, so I thought that wrapping the request output stream with an encoding wrapper would do nicely instead of having to find everywhere there could come a unicode string and then convert it explicitly.
What about input? Form data and query strings.