Skip to content
This repository has been archived by the owner on Apr 9, 2019. It is now read-only.

Commit

Permalink
Add Python 2 / 3 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
pbauer committed Jan 25, 2018
1 parent 7f3a742 commit fefbc94
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 6 deletions.
3 changes: 2 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ Bug fixes:

New features:

- * Add item here *
- Add Python 2 / 3 compatibility
[pbauer]


0.9.1 (2017-09-03)
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def description():
install_requires=[
'setuptools',
'plone.batching',
'six',
'z3c.form',
'zope.i18n>=3.4',
'zope.browserpage',
Expand Down
4 changes: 3 additions & 1 deletion src/plone/z3cform/fieldsets/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
from z3c.form.field import Fields
from z3c.form.util import expandPrefix

import six


def add(form, *args, **kwargs):
"""Add one or more fields. Keyword argument 'index' can be used to
Expand All @@ -15,7 +17,7 @@ def add(form, *args, **kwargs):

new_fields = Fields(*args, **kwargs)

if not group or isinstance(group, basestring):
if not group or isinstance(group, six.string_types):
source = find_source(form, group=group)
else:
source = group
Expand Down
7 changes: 4 additions & 3 deletions src/plone/z3cform/textlines/textlines.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"""
__docformat__ = "reStructuredText"

import six
import zope.component
import zope.interface
import zope.schema.interfaces
Expand Down Expand Up @@ -65,7 +66,7 @@ def toWidgetValue(self, value):
# produced.
if value is self.field.missing_value:
return u''
return u'\n'.join(unicode(v) for v in value)
return u'\n'.join(six.text_type(v) for v in value)

def toFieldValue(self, value):
"""See interfaces.IDataConverter"""
Expand Down Expand Up @@ -93,7 +94,7 @@ def toWidgetValue(self, value):
# if the value is the missing value, then an empty list is produced.
if value is self.field.missing_value:
return u''
return u'\n'.join(unicode(v) for v in sorted(value))
return u'\n'.join(six.text_type(v) for v in sorted(value))


class TextLinesFrozenSetConverter(TextLinesConverter):
Expand All @@ -107,4 +108,4 @@ def toWidgetValue(self, value):
# if the value is the missing value, then an empty list is produced.
if value is self.field.missing_value:
return u''
return u'\n'.join(unicode(v) for v in sorted(value))
return u'\n'.join(six.text_type(v) for v in sorted(value))
5 changes: 4 additions & 1 deletion src/plone/z3cform/z2.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# -*- coding: utf-8 -*-
from zope import interface
from zope.i18n.interfaces import IUserPreferredCharsets
from zope.publisher.browser import isCGI_NAME
from zope.publisher.interfaces.browser import IBrowserApplicationRequest

import six
import z3c.form.interfaces


Expand Down Expand Up @@ -56,7 +59,7 @@ def processInputs(request, charsets=None):
def _decode(text, charsets):
for charset in charsets:
try:
text = unicode(text, charset)
text = six.text_type(text, charset)
break
except UnicodeError:
pass
Expand Down

0 comments on commit fefbc94

Please sign in to comment.