Skip to content

Commit

Permalink
Add Python 2 / 3 compatibilityJ
Browse files Browse the repository at this point in the history
  • Loading branch information
vincero committed Jan 25, 2018
1 parent ad4456d commit 6c1c886
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ Bug fixes:
(Fixes https://github.com/plone/plone.protect/issues/15)
[fRiSi]

- Add Python 2 / 3 compatibility
[vincero]


3.1.1 (2017-08-27)
------------------
Expand Down
3 changes: 2 additions & 1 deletion plone/protect/authenticator.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from ZPublisher.HTTPRequest import HTTPRequest

import hmac
import six


try:
Expand All @@ -35,7 +36,7 @@ def _is_equal(val1, val2):
"""
constant time comparison
"""
if not isinstance(val1, basestring) or not isinstance(val2, basestring):
if not isinstance(val1, six.string_types) or not isinstance(val2, six.string_types):
return False
if len(val1) != len(val2):
return False
Expand Down
7 changes: 4 additions & 3 deletions plone/protect/auto.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
from Products.CMFCore.utils import getToolByName
from repoze.xmliter.serializer import XMLSerializer
from repoze.xmliter.utils import getHTMLSerializer
from urllib import urlencode
from urlparse import urlparse
from six.moves.urllib.parse import urlencode
from six.moves.urllib.parse import urlparse
from zExceptions import Forbidden
from zope.component import adapts
from zope.component import ComponentLookupError
Expand All @@ -32,6 +32,7 @@
import logging
import os
import pkg_resources
import six
import traceback
import transaction
import types
Expand Down Expand Up @@ -125,7 +126,7 @@ def parseTree(self, result, encoding):
return None

def transformBytes(self, result, encoding):
result = unicode(result, encoding, 'ignore')
result = six.text_type(result, encoding, 'ignore')
return self.transformIterable([result], encoding)

def transformString(self, result, encoding):
Expand Down
2 changes: 1 addition & 1 deletion plone/protect/tests/testAuto.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def test_forbidden_raised_if_auth_failure(self):
# XXX: plone.transformchain don't reraise exceptions
# try:
# self.browser.getControl('submit1').click()
# except Exception, ex:
# except Exception as ex:
# self.assertEquals(ex.getcode(), 403)
self.browser.getControl('submit1').click()
self.assertFalse(hasattr(self.portal, "foo"))
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
install_requires=[
'setuptools',
'plone.keyring >= 3.0dev',
'six',
'zope.component',
'zope.interface',
'Zope2',
Expand Down

0 comments on commit 6c1c886

Please sign in to comment.