Zope 3 in Zope 2 Gotcha's: Unicode
Viewlets
A viewlet’s render() method needs to return unicode objects because the standard zope3 viewlet implementation concatenates the output of various viewlet render()‘s. If the output is a str, then implicit conversion-to-unicode will happen using the default python character encoding which is most often ascii (causing a utf-8 encoded str with non-ascii chars to blow up).
Archetypes Schema Fields
Archetypes (as present in Plone 2.5 and 3.0, and possibly older) stores all StringField fields as utf-8 encoded str’s irrelevant of what the Plone site encoding has been configured as. Safest way to handle this is to always feed StringField field mutators unicode objects instead of str’s. And upon retrieval, be prepared to decode the str’s using utf-8 (ie context.Title().decode(’utf-8′) => u’someval’). Remember, StringField accessors will always return utf-8 encoded str’s and Zope 3 often makes assumptions that the string values it’s dealing with are unicode objects.
Summing Up
Use unicode objects everywhere. If some Zope 2 / Plone API forces you to use str‘s or get str‘s convert them to unicode‘s before doing anything else.
Comment waiting for approval