Skip to content

Commit

Permalink
Merge pull request #16 from plone/python3
Browse files Browse the repository at this point in the history
fix static portlet for py3
  • Loading branch information
pbauer authored Sep 21, 2018
2 parents cc7c26e + c868bff commit 2efdbd3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
3 changes: 2 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ New features:

Bug fixes:

- *add item here*
- Fix static portlet for py3
[pbauer]


3.1.2 (2018-02-05)
Expand Down
21 changes: 11 additions & 10 deletions plone/portlet/static/static.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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


Expand Down
3 changes: 3 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 2efdbd3

Please sign in to comment.