[Zope] Using tal:attributes in XML with non-ASCII characters
Dieter Maurer
dieter at handshake.de
Mon Mar 20 13:34:37 EST 2006
Andrew Veitch wrote at 2006-3-20 01:53 +0000:
> ...
> <input name="blah" type="text" tal:attributes="value python:chr
>(200).encode('utf-8')" />
>This gives:
>
>Error Type: UnicodeDecodeError
>Error Value: 'ascii' codec can't decode byte 0x80 in position 0:
>ordinal not in range(128)
Sure, you are using "str.encode" in a wrong way:
"str.encode('uft-8')" is equivalent to
"unicode(str, getdefaultencoding()).encode('utf-8')".
What encoding should your "200" use?
Convert it to unicode using this encoding (and let the
ZPublisher convert the unicode to "utf-8").
By the way, your exception must come from somewhere else
as "chr(200)" cannot lead to a "byte 0x80".
It is always worth to look at the traceback. It tells you
where the exception really comes from...
>...
><input name="blah" type="text" tal:attributes="value python:chr(200)" />
>
>Then this will work in HTML mode but will fail in XML mode.
You should use Unicode in XML mode...
> ...
>> I could provide patches, if useful.
>
>I would be very interested to see you patches.
Attached.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mltext.pat
Type: text/x-patch
Size: 12014 bytes
Desc: "structure" in attributes and markup language text patch
Url : http://mail.zope.org/pipermail/zope/attachments/20060320/b292577a/mltext.bin
-------------- next part --------------
--
Dieter
More information about the Zope
mailing list