[ZCM] [ZC] 2275/ 3 Comment "Unicode error in Page Templates"

"Collector: Zope Bugs, Features, and Patches ..." <[email protected]> Sat, 10 Mar 2007 17:26:15 -0500
Newsgroups gmane.comp.web.zope.devel.collector-monitor
Message-ID <[email protected]>
Issue #2275 Update (Comment) "Unicode error in Page Templates"
 Status Pending, Zope/bug+solution medium
To followup, visit:
  http://www.zope.org/Collectors/Zope/2275

==============================================================
= Comment - Entry #3 by smt on Mar 10, 2007 5:26 pm

I ran into a similar problem after updating from 2.10.1 to 2.10.2. When I tried to save the contents of an existing ZPT object containing an Atom feed (content type is "application/atom+xml") I also got the TypeError "decoding Unicode is not supported" from convertToUnicode(). After changing content type to "text/xml" I was able to change the contents without problems.

My first try to solve the problem was to replace line 66 of PageTemplates/utils.py from

> if content_type.startswith('text/xml'):

to 

> if content_type.startswith('text/xml') or content_type.endswith('+xml'):

but that didn't help. So as quick fix I added an additional check to the top of convertToUnicode in PageTemplates/utils.py:

> if isinstance(source, unicode):
>     return source, None

which solved the problem for now.

________________________________________
= Comment - Entry #2 by ajung on Feb 5, 2007 6:55 am

Could you please work on a unittest?
________________________________________
= Request - Entry #1 by don on Feb 5, 2007 6:39 am

I add Page Template, set Content-Type to text/plain, output-encofing to koi8-r, write text with cyrillic characters and try to save it. And get an error:
Error Type: TypeError
Error Value: decoding Unicode is not supported
Environment:
management_page_charset property set to "koi8-r"
environment variable ZPT_PREFERRED_ENCODING="koi8-r"
overrides.zcml in /Products/PageTemplates with ReplacingUnicodeEncodingConflictResolver
Error was gone after adding 2 lines in /Products/PageTemplates/utils.py in function convertToUnicode:
replace
        try:
            return unicode(source, enc), enc
        except UnicodeDecodeError:
                continue

with

        try:
            return unicode(source, enc), enc
        except UnicodeDecodeError:
                continue
        except TypeError:
                continue

==============================================================