diff --git a/CHANGES.rst b/CHANGES.rst index d88a3d6..89a29af 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -15,7 +15,8 @@ New features: Bug fixes: -- *add item here* +- Fix static portlet for py3 + [pbauer] 3.1.2 (2018-02-05) diff --git a/plone/portlet/static/static.py b/plone/portlet/static/static.py index b533e88..35ca86d 100644 --- a/plone/portlet/static/static.py +++ b/plone/portlet/static/static.py @@ -1,8 +1,5 @@ # -*- coding: utf-8 -*- from Acquisition import aq_inner -from Products.CMFCore.utils import getToolByName -from Products.CMFPlone.utils import getFSVersionTuple -from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile from plone.app.portlets.portlets import base from plone.app.textfield import RichText from plone.app.textfield.value import RichTextValue @@ -11,9 +8,14 @@ from plone.i18n.normalizer.interfaces import IIDNormalizer from plone.portlet.static import PloneMessageFactory as _ from plone.portlets.interfaces import IPortletDataProvider +from Products.CMFCore.utils import getToolByName +from Products.CMFPlone.utils import getFSVersionTuple +from Products.CMFPlone.utils import safe_unicode +from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile from zope import schema from zope.component import getUtility from zope.interface import implementer + import logging import re import six @@ -164,14 +166,15 @@ def transformed(self, mt='text/x-html-safe'): # utf-8 text. There were bugs in earlier versions of this portlet # which stored text directly as sent by the browser, which could # be any encoding in the world. - orig = six.text_type(orig, 'utf-8', 'ignore') + orig = safe_unicode(orig) logger.warn( - "Static portlet at %s has stored non-six.text_type text. " + "Static portlet at %s has not stored text/unicode. " "Assuming utf-8 encoding." % context.absolute_url() ) - # Portal transforms needs encoded strings - orig = orig.encode('utf-8') + # Portal transforms on py2 needs encoded strings + if six.PY2 and isinstance(orig, six.text_type): + orig = orig.encode('utf-8') transformer = getToolByName(context, 'portal_transforms') transformer_context = context @@ -185,9 +188,7 @@ def transformed(self, mt='text/x-html-safe'): context=transformer_context, mimetype='text/html') result = data.getData() if result: - if isinstance(result, str): - return six.text_type(result, 'utf-8') - return result + return safe_unicode(result) return None diff --git a/setup.py b/setup.py index a83cbc2..243600c 100644 --- a/setup.py +++ b/setup.py @@ -25,11 +25,14 @@ def read(*rnames): "Framework :: Plone", "Framework :: Plone :: 5.0", "Framework :: Plone :: 5.1", + "Framework :: Plone :: 5.2", "Framework :: Zope2", "License :: OSI Approved :: GNU General Public License v2 (GPLv2)", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 2.7", + "Programming Language :: Python :: 3.6", + "Programming Language :: Python :: 3.7", ], keywords='plone portlet static', author='Plone Foundation',