Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Python 2 / 3 compatibility #19

Merged
merged 1 commit into from
Jan 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@ New features:

Bug fixes:

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


3.0.7 (2017-05-16)
------------------

Bug fixes:

- Add missing entries to requirements in setup.py.
- Add missing entries to requirements in setup.py.
[dhavlik]


Expand Down
127 changes: 0 additions & 127 deletions bootstrap.py

This file was deleted.

9 changes: 0 additions & 9 deletions buildout.cfg

This file was deleted.

4 changes: 3 additions & 1 deletion plone/i18n/locales/countries.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from plone.i18n.locales.interfaces import ICountryAvailability
from zope.interface import implementer

import six


@implementer(ICountryAvailability)
class CountryAvailability(object):
Expand Down Expand Up @@ -292,4 +294,4 @@ def getCountryListing(self):
for code in _countrylist:
value = _countrylist[code]
if u'name' in value:
value[u'name'] = unicode(value[u'name'], 'utf-8')
value[u'name'] = six.text_type(value[u'name'], 'utf-8')
11 changes: 6 additions & 5 deletions plone/i18n/locales/languages.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# -*- coding: UTF-8 -*-

from plone.i18n.locales.interfaces import IContentLanguageAvailability
from plone.i18n.locales.interfaces import ILanguageAvailability
from plone.i18n.locales.interfaces import IMetadataLanguageAvailability
from zope.interface import implementer

import six


@implementer(ILanguageAvailability)
class LanguageAvailability(object):
Expand Down Expand Up @@ -251,9 +252,9 @@ class MetadataLanguageAvailability(LanguageAvailability):
for code in _languagelist:
value = _languagelist[code]
if u'name' in value:
value[u'name'] = unicode(value[u'name'], 'utf-8')
value[u'name'] = six.text_type(value[u'name'], 'utf-8')
if u'native' in value:
value[u'native'] = unicode(value[u'native'], 'utf-8')
value[u'native'] = six.text_type(value[u'native'], 'utf-8')

_combinedlanguagelist = {
u'ar-ae' : {u'name' : 'Arabic (United Arab Emirates)', u'flag' : u'/++resource++country-flags/ae.gif'},
Expand Down Expand Up @@ -488,6 +489,6 @@ class MetadataLanguageAvailability(LanguageAvailability):
for code in _combinedlanguagelist:
value = _combinedlanguagelist[code]
if u'name' in value:
value[u'name'] = unicode(value[u'name'], 'utf-8')
value[u'name'] = six.text_type(value[u'name'], 'utf-8')
if u'native' in value:
value[u'native'] = unicode(value[u'native'], 'utf-8')
value[u'native'] = six.text_type(value[u'native'], 'utf-8')
3 changes: 2 additions & 1 deletion plone/i18n/normalizer/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from unicodedata import decomposition
from unicodedata import normalize

import six
import string


Expand Down Expand Up @@ -51,7 +52,7 @@ def baseNormalize(text):
>>> baseNormalize(u"\u5317\u4EB0")
'53174eb0'
"""
if not isinstance(text, basestring):
if not isinstance(text, six.string_types):
# This most surely ends up in something the user does not expect
# to see. But at least it does not break.
return repr(text)
Expand Down
32 changes: 17 additions & 15 deletions plone/i18n/normalizer/tests/test_normalizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
from zope.component import queryUtility

import doctest
import six
import unittest



def testIDNormalizer():
"""
>>> util = queryUtility(IIDNormalizer)
Expand All @@ -30,7 +32,7 @@ def testIDNormalizer():
>>> util.normalize(u">>>here'!--s yet another!!!")
'here-s-yet-another'

>>> util.normalize(unicode("umläut.doc", 'utf-8'))
>>> util.normalize(six.text_type("umläut.doc", 'utf-8'))
'umlaut-doc'

>>> from plone.i18n.normalizer import MAX_LENGTH
Expand All @@ -53,7 +55,7 @@ def testIDNormalizer():
>>> len(util.normalize(testString)) <= MAX_LENGTH
True

>>> util.normalize(unicode("rest `n` peace", 'utf-8'))
>>> util.normalize(six.text_type("rest `n` peace", 'utf-8'))
'rest-n-peace'

>>> util.normalize(u"short-hello-version", max_length=10)
Expand Down Expand Up @@ -81,13 +83,13 @@ def testLocaleAwareIDNormalizer():
>>> util.normalize(u'simpleandsafe', locale='de')
'simpleandsafe'

>>> util.normalize(unicode('text with umläut', 'utf-8'), locale='de')
>>> util.normalize(six.text_type('text with umläut', 'utf-8'), locale='de')
'text-with-umlaeut'

Make sure we get the de normalizer as there's no special one for de-DE
registered.

>>> util.normalize(unicode('text with umläut', 'utf-8'), locale='de-DE')
>>> util.normalize(six.text_type('text with umläut', 'utf-8'), locale='de-DE')
'text-with-umlaeut'

>>> util.normalize(u'simpleandsafe', locale='pt-BR')
Expand All @@ -105,7 +107,7 @@ def testLocaleAwareIDNormalizer():
Make sure we also handle POSIX-format locale identifiers,
for backwards-compatibility with an earlier version of plone.i18n.

>>> util.normalize(unicode('text with umläut', 'utf-8'), locale='de_DE')
>>> util.normalize(six.text_type('text with umläut', 'utf-8'), locale='de_DE')
'text-with-umlaeut'

"""
Expand Down Expand Up @@ -135,13 +137,13 @@ def testFileNameNormalizer():
>>> util.normalize("pseudo_filename,pot,#1.doc")
'pseudo_filename-pot-#1.doc'

>>> util.normalize(unicode("umläut.doc", 'utf-8'))
>>> util.normalize(six.text_type("umläut.doc", 'utf-8'))
'umlaut.doc'

>>> len(util.normalize(u'aa' * 2000))
1023

>>> util.normalize(unicode("rest `n` peace", 'utf-8'))
>>> util.normalize(six.text_type("rest `n` peace", 'utf-8'))
'rest -n- peace'

>>> util.normalize(u"short-hello-version", max_length=10)
Expand All @@ -164,13 +166,13 @@ def testLocaleAwareFileNameNormalizer():
>>> util.normalize(u'simpleandsafe', locale='de')
'simpleandsafe'

>>> util.normalize(unicode('text with umläut', 'utf-8'), locale='de')
>>> util.normalize(six.text_type('text with umläut', 'utf-8'), locale='de')
'text with umlaeut'

Make sure we get the de normalizer as there's no special one for de-DE
registered.

>>> util.normalize(unicode('text with umläut', 'utf-8'), locale='de-DE')
>>> util.normalize(six.text_type('text with umläut', 'utf-8'), locale='de-DE')
'text with umlaeut'

>>> util.normalize(u'simpleandsafe', locale='pt-BR')
Expand All @@ -188,7 +190,7 @@ def testLocaleAwareFileNameNormalizer():
Make sure we also handle POSIX-format locale identifiers,
for backwards-compatibility with an earlier version of plone.i18n.

>>> util.normalize(unicode('text with umläut', 'utf-8'), locale='de_DE')
>>> util.normalize(six.text_type('text with umläut', 'utf-8'), locale='de_DE')
'text with umlaeut'

"""
Expand All @@ -215,7 +217,7 @@ def testURLNormalizer():
>>> util.normalize(u"Doe, Joe")
'doe-joe'

>>> util.normalize(unicode("umläut.doc", 'utf-8'))
>>> util.normalize(six.text_type("umläut.doc", 'utf-8'))
'umlaut.doc'

>>> util.normalize('quote "this"!')
Expand All @@ -230,7 +232,7 @@ def testURLNormalizer():
>>> util.normalize("I'm a big file.TXT")
'im-a-big-file.txt'

>>> util.normalize(unicode("rest `n` peace", 'utf-8'))
>>> util.normalize(six.text_type("rest `n` peace", 'utf-8'))
'rest-n-peace'

>>> len(util.normalize(u'aa' * 2000))
Expand All @@ -255,13 +257,13 @@ def testLocaleAwareURLNormalizer():
>>> util.normalize(u'simpleandsafe', locale='de')
'simpleandsafe'

>>> util.normalize(unicode('text with umläut', 'utf-8'), locale='de')
>>> util.normalize(six.text_type('text with umläut', 'utf-8'), locale='de')
'text-with-umlaeut'

Make sure we get the de normalizer as there's no special one for de-DE
registered.

>>> util.normalize(unicode('text with umläut', 'utf-8'), locale='de-DE')
>>> util.normalize(six.text_type('text with umläut', 'utf-8'), locale='de-DE')
'text-with-umlaeut'

>>> util.normalize(u'simpleandsafe', locale='pt-BR')
Expand All @@ -276,7 +278,7 @@ def testLocaleAwareURLNormalizer():
Make sure we also handle POSIX-format locale identifiers,
for backwards-compatibility with an earlier version of plone.i18n.

>>> util.normalize(unicode('text with umläut', 'utf-8'), locale='de_DE')
>>> util.normalize(six.text_type('text with umläut', 'utf-8'), locale='de_DE')
'text-with-umlaeut'

"""
Expand Down
2 changes: 0 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ ignore =
.coveragerc
.editorconfig
.gitattributes
bootstrap.py
buildout.cfg

[isort]
# for details see
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
'Products.CMFCore',
'Products.CMFPlone',
'setuptools',
'six',
'Unidecode',
'zope.component',
'zope.i18n',
Expand Down