[ZCM] [ZC] 2274/ 2 Comment "UnicodeDecodeError saving Page Template"

Collector: Zope Bugs, Features, and Patches ... zope-coders-admin at zope.org
Mon Feb 5 06:57:11 EST 2007


Issue #2274 Update (Comment) "UnicodeDecodeError saving Page Template"
 Status Pending, Zope/bug+solution medium
To followup, visit:
  http://www.zope.org/Collectors/Zope/2274

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

Could you please work on a unittest?
________________________________________
= Request - Entry #1 by gercon on Feb 5, 2007 2:53 am


Uploaded:  "ZopePageTemplate.diff"
 - http://www.zope.org/Collectors/Zope/2274/ZopePageTemplate.diff/view
We user koi8-r enconding in zope. management_page_charset property set to "koi8-r".
After instaling zope 2.10.2 we added environment variable ZPT_PREFERRED_ENCODING="koi8-r" and overrides.zcml in /Products/PageTemplates with ReplacingUnicodeEncodingConflictResolver.
Rendering of page templates works fine, but when i try to change page template with cyrillic charactres in text or title, I getting an error:
UnicodeDecodeError: 'utf8' codec can't decode bytes in position 0-3: invalid data
The error is in lines 193-194 of /Products/PageTemplates/ZopePageTemplate.py
        # The ZMI edit view uses utf-8! So we can safely assume
        # that 'title' and 'text' are utf-8 encoded strings - hopefully

        self.pt_setTitle(title, 'utf-8')
        text = unicode(text, 'utf-8')
Indeed The ZMI edit view uses utf-8 only if management_page_charset not available.
Replacing string 
       self.pt_setTitle(title, 'utf-8')
       text = unicode(text, 'utf-8')
to 
        text, encoding = convertToUnicode(text,
                                         content_type,
                                         preferred_encodings)
       self.pt_setTitle(title, encoding)
solved the problem.
Diff file fo ZopePageTemplate.py attached.
==============================================================



More information about the Zope-Collector-Monitor mailing list