[Twisted-Python] Sending unicode strings

Ken Kinder ken at kenkinder.com
Mon Apr 25 12:01:32 EDT 2005


Tommi Virtanen wrote:

>Personally, I think ass-u-ming Unicode is encoded as UTF-8 would have
>been sane, but I can understand that not everyone agrees; e.g. Java
>wants UCS-16 if I remember correctly. And not serializing to UTF-8
>by default catches errors that would otherwise cause mysterious things
>to happen.
>  
>
Most of the time, you should know the encoding. Instead of forcing the 
protocol to do the work, why not just have a way of setting the expected 
encoding for write() and similar methods? If the encoding is not set 
(ie, None), then raise the exception. Otherwise, use the specified 
encoding. This would have the added readability advantage in that 
unicode encoding -- uhh code -- wouldn't have to be sprinkled throughout 
the protocol classes -- only in places where the encoding is actually 
set -- in HTTP's headers for example.

-Ken





More information about the Twisted-Python mailing list