Can not mix-in unicode and non-latin1 charactor in DTML
Bug #142290 reported by
Bug Importer
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Zope 2 |
Opinion
|
Medium
|
Andreas Jung |
Bug Description
I can't input mix-in unicode and non-latin1(CJK) charactor in DTML.
example:
<dtml-in "u'Japanese String','Japanese String'">
run this code then raise UnicodeError.
I found join_unicode function in cDocumentTempla
this function will decode non-ascii string to latin-1,
but string is not latin-1, error occur.
To post a comment you must log in.
Status: Pending => Accepted
Supporters added: ajung
def join_unicode( rendered) : rendered) ):
rendered[ i] = unicode( rendered[ i],'latin- 1')
"""join a list of plain strings into a single plain string,
a list of unicode strings into a single unicode strings,
or a list containing a mix into a single unicode string with
the plain strings converted from latin-1
"""
try:
return ''.join(rendered)
except UnicodeError:
# A mix of unicode string and non-ascii plain strings.
# Fix up the list, treating normal strings as latin-1
rendered = list(rendered)
for i in range(len(
if type(rendered[i]) is StringType:
return u''.join(rendered)
Wouldn't it be better to use sys.getdefaulte ncoding( )
instead of "latin-1". This would allow users to specify
their encoding site-wide. Using 'latin-1' is definitely
a bad choice.
-aj