[Erp5-report] r45756 vincent - in /erp5/trunk/products/ERP5Type: ./ patches/

nobody at svn.erp5.org nobody at svn.erp5.org
Fri Apr 29 16:07:18 CEST 2011


Author: vincent
Date: Fri Apr 29 16:07:18 2011
New Revision: 45756

URL: http://svn.erp5.org?rev=45756&view=rev
Log:
Make a monkeypatch out of LP Bug #706946.

Uses slightly modified version of Kazuhiko's patch, as attached on comment #1.
See https://bugs.launchpad.net/zope2/+bug/706946

Added:
    erp5/trunk/products/ERP5Type/patches/ZopePageTemplateUtils.py
Modified:
    erp5/trunk/products/ERP5Type/ZopePatch.py

Modified: erp5/trunk/products/ERP5Type/ZopePatch.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/ZopePatch.py?rev=45756&r1=45755&r2=45756&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/ZopePatch.py [utf8] (original)
+++ erp5/trunk/products/ERP5Type/ZopePatch.py [utf8] Fri Apr 29 16:07:18 2011
@@ -71,6 +71,7 @@ from Products.ERP5Type.patches import ZO
 # dropped support for older versions.
 from Products.ERP5Type.patches import TransactionAddBeforeCommitHook
 from Products.ERP5Type.patches import ZopePageTemplate
+from Products.ERP5Type.patches import ZopePageTemplateUtils
 
 # These symbols are required for backward compatibility
 from Products.ERP5Type.patches.PropertyManager import ERP5PropertyManager

Added: erp5/trunk/products/ERP5Type/patches/ZopePageTemplateUtils.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/patches/ZopePageTemplateUtils.py?rev=45756&view=auto
==============================================================================
--- erp5/trunk/products/ERP5Type/patches/ZopePageTemplateUtils.py (added)
+++ erp5/trunk/products/ERP5Type/patches/ZopePageTemplateUtils.py [utf8] Fri Apr 29 16:07:18 2011
@@ -0,0 +1,71 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+# Copyright (c) 2002 Zope Foundation and Contributors.
+# Copyright (c) 2011 Nexedi SA and Contributors. All Rights Reserved.
+#          Vincent Pelletier <vincent at nexedi.com>
+#
+# WARNING: This program as such is intended to be used by professional
+# programmers who take the whole responsability of assessing all potential
+# consequences resulting from its eventual inadequacies and bugs
+# End users who are looking for a ready-to-use solution with commercial
+# garantees and support are strongly adviced to contract a Free Software
+# Service Company
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE
+##############################################################################
+
+NEED_PATCH = False
+try:
+    from Products.PageTemplates.utils import convertToUnicode
+except ImportError:
+    # Not present in Zope 2.8
+    pass
+else:
+    try:
+        convertToUnicode(u'')
+    except TypeError:
+        NEED_PATCH = True
+
+def patched_convertToUnicode(source, content_type, preferred_encodings):
+    """ Convert 'source' to unicode.
+        Returns (unicode_str, source_encoding).
+    """
+
+# PATCH BEGINING
+# See https://bugs.launchpad.net/zope2/+bug/706946
+    if isinstance(source, unicode):
+        return source, 'utf-8'
+# PATCH END
+    if content_type.startswith('text/xml'):
+        encoding = encodingFromXMLPreamble(source)
+        return unicode(source, encoding), encoding
+
+    elif content_type.startswith('text/html'):
+        encoding = charsetFromMetaEquiv(source)
+        if encoding:
+            return unicode(source, encoding), encoding
+
+    # Try to detect the encoding by converting it unicode without raising
+    # exceptions. There are some smarter Python-based sniffer methods
+    # available however we have to check their licenses first before
+    # including them into the Zope 2 core
+
+    for enc in preferred_encodings:
+        try:
+            return unicode(source, enc), enc
+        except UnicodeDecodeError:
+                continue
+
+    return unicode(source), None
+
+if NEED_PATCH:
+    # We need to monkey patch in-place, as it is a top-level function and
+    # already imported in other places.
+    convertToUnicode.func_code = patched_convertToUnicode.func_code
+



More information about the Erp5-report mailing list