From b1746ce9637ad37082637585aa23c255aadd1add Mon Sep 17 00:00:00 2001 From: Davi Lima Date: Fri, 26 Jan 2018 12:22:11 +0100 Subject: [PATCH] Add Python 2 / 3 compatibility --- CHANGES.rst | 2 +- .../DefaultWorkflowPolicy.py | 17 +++++++------ .../WorkflowPolicyConfig.py | 24 +++++++++++-------- Products/CMFPlacefulWorkflow/adapter.py | 8 ++++--- setup.py | 1 + 5 files changed, 31 insertions(+), 21 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 04ba43f..c077099 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -10,7 +10,7 @@ Breaking changes: New features: -- *add item here* +- Add Python 2 / 3 compatibility [davilima6] Bug fixes: diff --git a/Products/CMFPlacefulWorkflow/DefaultWorkflowPolicy.py b/Products/CMFPlacefulWorkflow/DefaultWorkflowPolicy.py index f875a44..22af4c8 100644 --- a/Products/CMFPlacefulWorkflow/DefaultWorkflowPolicy.py +++ b/Products/CMFPlacefulWorkflow/DefaultWorkflowPolicy.py @@ -23,17 +23,20 @@ from AccessControl.requestmethod import postonly from Acquisition import aq_base from App.class_init import InitializeClass +from os.path import join as path_join from Persistence import PersistentMapping -from Products.CMFCore.utils import SimpleItemWithProperties from Products.CMFCore.utils import getToolByName -from Products.CMFPlacefulWorkflow.PlacefulWorkflowTool import addWorkflowPolicyFactory +from Products.CMFCore.utils import SimpleItemWithProperties from Products.CMFPlacefulWorkflow.global_symbols import Log from Products.CMFPlacefulWorkflow.interfaces import IWorkflowPolicyDefinition from Products.CMFPlacefulWorkflow.permissions import ManageWorkflowPolicies +from Products.CMFPlacefulWorkflow.PlacefulWorkflowTool import addWorkflowPolicyFactory from Products.PageTemplates.PageTemplateFile import PageTemplateFile -from os.path import join as path_join from zope.interface import implementer +import six + + DEFAULT_CHAIN = '(Default)' _MARKER = '_MARKER' @@ -197,7 +200,7 @@ def getChainFor(self, ob, managescreen=False): """ cbt = self._chains_by_type - if isinstance(ob, basestring): + if isinstance(ob, six.string_types): pt = ob elif hasattr(aq_base(ob), '_getPortalTypeName'): pt = ob._getPortalTypeName() @@ -212,7 +215,7 @@ def getChainFor(self, ob, managescreen=False): chain = cbt.get(pt, _MARKER) # Backwards compatibility: before chain was a string, not a list - if chain is not _MARKER and isinstance(chain, basestring): + if chain is not _MARKER and isinstance(chain, six.string_types): chain = map(lambda x: x.strip(), chain.split(',')) Log.debug('Chain founded in policy %s', chain) @@ -236,7 +239,7 @@ def setDefaultChain(self, default_chain, REQUEST=None): """ Sets the default chain for this tool. """ wftool = getToolByName(self, 'portal_workflow') - if isinstance(default_chain, basestring): + if isinstance(default_chain, six.string_types): default_chain = map(lambda x: x.strip(), default_chain.split(',')) ids = [] for wf_id in default_chain: @@ -276,7 +279,7 @@ def setChain(self, portal_type, chain, REQUEST=None): if portal_type not in [pt.id for pt in self._listTypeInfo()]: raise ValueError("'%s' is not a valid portal type." % portal_type) - if isinstance(chain, basestring): + if isinstance(chain, six.string_types): chain = map(lambda x: x.strip(), chain.split(',')) wftool = getToolByName(self, 'portal_workflow') diff --git a/Products/CMFPlacefulWorkflow/WorkflowPolicyConfig.py b/Products/CMFPlacefulWorkflow/WorkflowPolicyConfig.py index 9d5dd04..8a19927 100644 --- a/Products/CMFPlacefulWorkflow/WorkflowPolicyConfig.py +++ b/Products/CMFPlacefulWorkflow/WorkflowPolicyConfig.py @@ -19,19 +19,22 @@ Workflow Policy config """ -from os.path import join as path_join - +from AccessControl import ClassSecurityInfo +from Acquisition import aq_base +from Acquisition import aq_inner +from Acquisition import aq_parent from App.class_init import InitializeClass from OFS.SimpleItem import SimpleItem -from AccessControl import ClassSecurityInfo -from Acquisition import aq_base, aq_inner, aq_parent - -from Products.PageTemplates.PageTemplateFile import PageTemplateFile -from Products.CMFCore.utils import getToolByName +from os.path import join as path_join from PlacefulWorkflowTool import WorkflowPolicyConfig_id +from Products.CMFCore.utils import getToolByName from Products.CMFPlacefulWorkflow.global_symbols import Log from Products.CMFPlacefulWorkflow.permissions import ManageWorkflowPolicies +from Products.PageTemplates.PageTemplateFile import PageTemplateFile + +import six + manage_addWorkflowPolicyConfigForm = PageTemplateFile( path_join('www', 'add_workflow_policy_config_form'), globals()) @@ -107,8 +110,8 @@ def getPolicyBelow(self): security.declareProtected(ManageWorkflowPolicies, 'setPolicyIn') def setPolicyIn(self, policy, update_security=False): - if not isinstance(policy, basestring): - raise ValueError("Policy must be a basestring") + if not isinstance(policy, six.string_types): + raise ValueError("Policy must be a six.string_types") self.workflow_policy_in = policy if update_security: wtool = getToolByName(self, 'portal_workflow') @@ -129,7 +132,7 @@ def setPolicyIn(self, policy, update_security=False): security.declareProtected(ManageWorkflowPolicies, 'setPolicyBelow') def setPolicyBelow(self, policy, update_security=False): - if not isinstance(policy, basestring): + if not isinstance(policy, six.string_types): raise ValueError("Policy must be a string") self.workflow_policy_below = policy if update_security: @@ -178,4 +181,5 @@ def getPlacefulChainFor(self, portal_type, start_here=False): return chain + InitializeClass(WorkflowPolicyConfig) diff --git a/Products/CMFPlacefulWorkflow/adapter.py b/Products/CMFPlacefulWorkflow/adapter.py index 0b7f806..d9abdf7 100644 --- a/Products/CMFPlacefulWorkflow/adapter.py +++ b/Products/CMFPlacefulWorkflow/adapter.py @@ -19,14 +19,16 @@ from Acquisition import aq_inner from Acquisition import aq_parent from Products.CMFCore.utils import getToolByName -from Products.CMFPlacefulWorkflow.PlacefulWorkflowTool import WorkflowPolicyConfig_id from Products.CMFPlacefulWorkflow.interfaces import IPlacefulMarker +from Products.CMFPlacefulWorkflow.PlacefulWorkflowTool import WorkflowPolicyConfig_id from Products.CMFPlone.interfaces import IWorkflowChain from Products.CMFPlone.utils import base_hasattr from Products.CMFPlone.workflow import ToolWorkflowChain from zope.component import adapter -from zope.interface import Interface from zope.interface import implementer +from zope.interface import Interface + +import six @adapter(Interface, IPlacefulMarker) @@ -43,7 +45,7 @@ def PlacefulWorkflowChain(ob, tool): 4. if the parent is the portal object or None we stop and ask portal_workflow """ - if isinstance(ob, basestring): + if isinstance(ob, six.string_types): # We are not in an object, then we can only get default from # portal_workflow return ToolWorkflowChain(ob, tool) diff --git a/setup.py b/setup.py index 08eda03..fdbd2aa 100644 --- a/setup.py +++ b/setup.py @@ -31,6 +31,7 @@ ), install_requires=[ 'setuptools', + 'six', 'zope.component', 'zope.interface', 'zope.i18nmessageid',