[Checkins] Re: SVN: Zope3/trunk/src/zope/app/module/ Use normal strings for ModuleManager names

Ross Patterson me at rpatterson.net
Tue Feb 6 13:31:09 EST 2007


Philipp von Weitershausen <philipp at weitershausen.de> writes:

> 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').

Made this change in r72401.  Thanks for the feedback.

Ross


More information about the Checkins mailing list