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

Python 2 / 3 compatible imports. #10

Merged
merged 3 commits into from
Jan 22, 2018
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Change Log
- Do not fail when our base profiles are already registered.
This may happen in tests if our ``initialize`` code is called twice.

- Improve Python 3 support using six.

1.11.0 (2016-03-01)
-------------------
Expand Down
4 changes: 3 additions & 1 deletion Products/PluggableAuthService/UserPropertySheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
from types import InstanceType
from types import BooleanType

StringTypes = (str, unicode, )
import six

StringTypes = (str, six.text_type, )
_SequenceTypes = (tuple, list, )

from DateTime.DateTime import DateTime
Expand Down
2 changes: 1 addition & 1 deletion Products/PluggableAuthService/plugins/CookieAuthHelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

from base64 import encodestring, decodestring
from binascii import Error
from urllib import quote, unquote
from six.moves.urllib.parse import quote, unquote

from AccessControl.SecurityInfo import ClassSecurityInfo
from AccessControl.Permissions import view
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

# General Python imports
import copy, os
from urllib import quote_plus

# Zope imports
from Acquisition import aq_base
Expand Down
1 change: 0 additions & 1 deletion Products/PluggableAuthService/plugins/InlineAuthHelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
"""

from base64 import encodestring, decodestring
from urllib import quote

from AccessControl.SecurityInfo import ClassSecurityInfo
from OFS.Folder import Folder
Expand Down
12 changes: 8 additions & 4 deletions Products/PluggableAuthService/plugins/ScriptablePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@

$Id$
"""
from sets import Set
from urllib import quote_plus
try:
from sets import Set as set
except ImportError:
pass

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just remove the import and always use the built-in set type.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

from OFS.Folder import Folder
from AccessControl import ClassSecurityInfo
from AccessControl.Permissions import manage_users as ManageUsers
Expand All @@ -38,6 +41,7 @@ class IScriptablePlugin(Interface):

import Products


manage_addScriptablePluginForm = PageTemplateFile(
'www/spAdd', globals(), __name__='manage_addScriptablePluginForm' )

Expand Down Expand Up @@ -115,9 +119,9 @@ def _delOb( self, id ):
myId = self.getId()
pas_instance = self._getPAS()
plugins = pas_instance._getOb( 'plugins' )
curr_interfaces = Set(providedBy(self))
curr_interfaces = set(providedBy(self))

del_interfaces = Set([x for x in providedBy(self) if id in x.names()])
del_interfaces = set([x for x in providedBy(self) if id in x.names()])

for interface in del_interfaces:
if myId in plugins.listPluginIds( interface ):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@

# General Python imports
import copy, os
from urllib import quote_plus

# Zope imports
from Acquisition import aq_base
from OFS.Folder import Folder
Expand All @@ -38,6 +36,7 @@
from Products.PluggableAuthService.plugins.BasePlugin import BasePlugin
from Products.PluggableAuthService.utils import classImplements


class ISearchPrincipalsPlugin(Interface):
""" Marker interface.
"""
Expand Down
3 changes: 2 additions & 1 deletion Products/PluggableAuthService/plugins/exportimport.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"""
import os, sys

import six
from xml.dom.minidom import parseString

from Acquisition import Implicit
Expand Down Expand Up @@ -142,7 +143,7 @@ def _getNodeAttr(self, node, attrname, default=None):
if attr is None:
return default
value = attr.value
if isinstance(value, unicode) and self.encoding is not None:
if isinstance(value, six.text_type) and self.encoding is not None:
value = value.encode(self.encoding)
return value

Expand Down
2 changes: 1 addition & 1 deletion Products/PluggableAuthService/plugins/tests/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def getGroups( self ):

def makeRequestAndResponse():
# the POST checking requires a real HTTPRequest
from cStringIO import StringIO
from six import StringIO
from ZPublisher.HTTPRequest import HTTPRequest
from ZPublisher.HTTPResponse import HTTPResponse

Expand Down
2 changes: 1 addition & 1 deletion Products/PluggableAuthService/tests/test_exportimport.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"""
import unittest
from csv import reader
from StringIO import StringIO
from six import StringIO

try:
import Products.GenericSetup
Expand Down
6 changes: 4 additions & 2 deletions Products/PluggableAuthService/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
##############################################################################
import unittest

import six


class Test_createViewName(unittest.TestCase):

Expand Down Expand Up @@ -264,10 +266,10 @@ def _createHashedValue(items):
items = list(items)
items.sort()
for k, v in items:
if isinstance(k, unicode):
if isinstance(k, six.text_type):
k = k.encode('utf-8')
hasher.update(k)
if isinstance(v, unicode):
if isinstance(v, six.text_type):
v = v.encode('utf-8')
hasher.update(v)
return hasher.hexdigest()
Expand Down
3 changes: 2 additions & 1 deletion Products/PluggableAuthService/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
except:
from sha import new as sha

import six

from AccessControl import ClassSecurityInfo
from App.Common import package_home
Expand Down Expand Up @@ -162,7 +163,7 @@ def allTests( from_dir=product_dir, test_prefix='test' ):

def makestr(s):
"""Converts 's' to a non-Unicode string"""
if isinstance(s, unicode):
if isinstance(s, six.text_type):
s = s.encode('utf-8')
return str(s)

Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def _package_doc(name):
zip_safe=False,
install_requires=[
'setuptools',
'six',
'Zope2 >= 4.0a4',
'Products.PluginRegistry >= 1.5',
'Products.GenericSetup >= 1.9.0',
Expand Down