[Checkins] Re: SVN: Zope3/trunk/src/zope/app/module/ Use normal
strings for ModuleManager names
Philipp von Weitershausen
philipp at weitershausen.de
Tue Feb 6 08:58:02 EST 2007
Ross Patterson wrote:
> Log message for revision 72386:
> Use normal strings for ModuleManager names
>
> When unicode strings are used for manager names, interfaces break. As
> such, convert unicode values to ascii values on manager registration
> to solve this problem.
...
> def setNameOnActivation(manager, event):
> """Set the module name upon registration activation."""
> - manager.name = event.object.name
> + # Convert the name to a normal string to avoid problems with
> + # unicode module names
> + manager.name = str(event.object.name)
Using str(some_unicode) isn't exactly a safe conversion to ASCII. In
fact, str(some_unicode) is one of the most magical things in Python
because it's installation dependent (because of the most evil
sys.setdefaultencoding thing). I don't understand the context of this
code completely, but if event.object.name can be any kind of unicode and
manager.name can only be ASCII, the only way to be completely safe is to
do one of the following:
* explicitly mention the 'ascii' output encoding. If you do that, you
will want to replace or ignore non-ASCII characters in the unicode
string, like
>>> event.object.name.encode('ascii', errors='ignore').
This transformation is obviously lossy.
* use an ASCII-only encoding such as UTF-7 or Quoted Printable. This
isn't lossy but pretty wordy and sometimes ugly.
--
http://worldcookery.com -- Professional Zope documentation and training
Next Zope 3 training at Camp5: http://trizpug.org/boot-camp/camp5
More information about the Checkins
mailing list