I want to move my Localizer "LocalContent" instances from Localizer 0.8.1 to Localizer 1.0.1 My Zope 2.5.1 was updated with all necessary unicode patches. The problem: After converting LocalContent instances in one folder to Unicode, I cannot access the management screen. The error message is: Error Type: UnicodeError Error Value: ASCII encoding error: ordinal not in range(128) The same error is triggered when displaying the titles in that folder: script_1: for x in context.objectValues('LocalContent'): print x.id, ":" x.title return printed ... and is not trigered if I only list the ids. I believe that this kind of error appears when Zope is trying to display Unicode characters and legacy-encoded characters (such as ISO-8859-2 or Win1250) at the same time. The title attribute of LocalContent objects is displayed in the ZMI. Of course, the title attribute of LocalContent objects has many language versions, and Zope (I presume) displays in the ZMI the language version according to my browser's language setting. I do not understand why script_1 triggers it. But most importantly I do not know how to get out of this mess. This is the External script used to do the conversion to Unicode: def cvt(objVal): # for x in context.objectValues('LocalContent'): log = [] for x in objVal: log_line = x.id + ': ' local_properties = {} for id, v in x._local_properties.items(): log_line += ' ' + id local_properties[id] = {} for lang, v in v.items(): local_properties[id][lang] = unicode(v, 'cp1250') x._local_properties = local_properties log.append(log_line) return log -- Milos Prudek
Milos Prudek wrote at 2003-12-16 17:38 +0100:
... Error Type: UnicodeError Error Value: ASCII encoding error: ordinal not in range(128)
The same error is triggered when displaying the titles in that folder:
script_1:
for x in context.objectValues('LocalContent'): print x.id, ":" x.title return printed
... and is not trigered if I only list the ids.
I believe that this kind of error appears when Zope is trying to display Unicode characters and legacy-encoded characters (such as ISO-8859-2 or Win1250) at the same time.
You are almost right: Whenever Python (thus, this is not restricted to Zope) combines a normal string and a unicode string, it tries to convert the normal string into unicode. In this conversion, it uses Python's "defaultencoding" (defaults to ASCII). When the normal string contains characters not supported by this encoding, you get error like the above. The general advice is: "Unicode everywhere or nowhere". Because I live in a "Latin-1" environment (with no other encodings around), I can live with a hack (frowned upon by many Python gods): I set Python's default encoding to "iso-8859-15". This can only be done in Python's initialization because later "sys.setdefaultencoding" is no longer available. As you want to specifically support many languages, this is probably no option for you. Therefore: go for the "Unicode everywhere" option... -- Dieter
participants (2)
-
Dieter Maurer -
Milos Prudek