[Zope3-dev] Unicode handling in Zope3 Page Templates

Sidnei da Silva sidnei at awkly.org
Tue Aug 31 09:47:38 EDT 2004


On Tue, Aug 31, 2004 at 10:40:22AM +0200, Martijn Faassen wrote:
| Sidnei da Silva wrote:
| [snip]
| >If I use sys.setdefaultencoding('utf-8') in sitecustomize.py, I get a
| >bit further, but then when the special char is displayed, I get a '?'
| >char instead. 
| 
| I'll just reiterate again (I already said it in private to you but can't 
| hurt to say it in public) that doing site.setdefaultencoding is plain 
| evil. It destroys any hope of compatibility and may well disrupt the 
| workings of some code that catches unicode errors and expects them when 
| a piece of text is non-ascii.
| 
| No code should depend on this. You're not entirely clear in the 
| following text that *aren't* depending on this.
| 
| >From poking around, It seems like what's happening is that ZPT is
| >getting a 'latin-1' encoded string, and converting to unicode using
| >'utf-8', which is the system default encoding.
| >
| >I've made some changes to tales, tal and pagetemplate and added a test
| >to confirm that if only encoded strings are returned it doesn't
| >break. And if only unicode strings are returned it also doesn't break.
| 
| Which has nothing to do with system default encoding, to make this 
| entirely clear.

Ugh you're right. Just to clarify, I used setdefaultencoding as an
experiment to see how far it would get. The result was: not far enough
:)

I should have omitted this fact, but regardless, its a warning for
people which come after me:

----------------------------------------------------------------------
DON'T PLAY WITH sys.setdefaultencoding()! IT'S EVIL AND MAY STEAL YOUR
LUNCH/KILL YOUR DOG/UPSET YOUR WIFE.
----------------------------------------------------------------------

-- 
Sidnei da Silva <sidnei at awkly.org>
http://awkly.org - dreamcatching :: making your dreams come true
http://www.enfoldsystems.com
http://plone.org/about/team#dreamcatcher

<det> glyph: why not use xml? (only because it is sort of a python standard [dont kill me])


More information about the Zope3-dev mailing list