Commit a162f0a5 authored by Julien Muchembled's avatar Julien Muchembled

Remove a few uses of 'apply' builtin function

- 'apply' causes a break in cProfile results
- 'apply' is deprecated (removed in Python 3)
parent 117bee10
...@@ -179,7 +179,7 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -179,7 +179,7 @@ class CategoryTool( UniqueObject, Folder, Base ):
return filt return filt
def _buildQuery(self, spec, filter, kw): def _buildQuery(self, spec, filter, kw):
return apply( ContentFilter, (), self._buildFilter(spec, filter, kw) ) return ContentFilter(**self._buildFilter(spec, filter, kw))
# Category accessors # Category accessors
security.declareProtected(Permissions.AccessContentsInformation, 'getBaseCategoryList') security.declareProtected(Permissions.AccessContentsInformation, 'getBaseCategoryList')
......
...@@ -203,7 +203,7 @@ class WorkflowMethod(Method): ...@@ -203,7 +203,7 @@ class WorkflowMethod(Method):
# Try to return immediately if there are no transition to invoke # Try to return immediately if there are no transition to invoke
if not candidate_transition_item_list: if not candidate_transition_item_list:
return apply(self.__dict__['_m'], (instance,) + args, kw) return self.__dict__['_m'](instance, *args, **kw)
# Prepare a list of transitions which should be invoked. # Prepare a list of transitions which should be invoked.
# This list is based on the results of isWorkflowMethodSupported. # This list is based on the results of isWorkflowMethodSupported.
...@@ -240,7 +240,7 @@ class WorkflowMethod(Method): ...@@ -240,7 +240,7 @@ class WorkflowMethod(Method):
wf[wf_id].notifyBefore(instance, transition_list, args=args, kw=kw) wf[wf_id].notifyBefore(instance, transition_list, args=args, kw=kw)
# Compute expected result # Compute expected result
result = apply(self.__dict__['_m'], (instance,) + args, kw) result = self.__dict__['_m'](instance, *args, **kw)
# Change the state of statefull workflows # Change the state of statefull workflows
for wf_id, transition_list in valid_transition_item_list: for wf_id, transition_list in valid_transition_item_list:
......
...@@ -25,7 +25,6 @@ from AccessControl import ClassSecurityInfo, getSecurityManager ...@@ -25,7 +25,6 @@ from AccessControl import ClassSecurityInfo, getSecurityManager
from Products.ERP5Type.Globals import InitializeClass from Products.ERP5Type.Globals import InitializeClass
from Acquisition import aq_base, aq_parent from Acquisition import aq_base, aq_parent
from zLOG import LOG, INFO, ERROR from zLOG import LOG, INFO, ERROR
from string import find
from cStringIO import StringIO from cStringIO import StringIO
from Products.ERP5Type import Permissions from Products.ERP5Type import Permissions
import sys import sys
...@@ -208,14 +207,15 @@ def DA__call__(self, REQUEST=None, __ick__=None, src__=0, test__=0, **kw): ...@@ -208,14 +207,15 @@ def DA__call__(self, REQUEST=None, __ick__=None, src__=0, test__=0, **kw):
security=getSecurityManager() security=getSecurityManager()
security.addContext(self) security.addContext(self)
try: try:
try: query=apply(self.template, (p,), argdata) query = self.template(p, **argdata)
except TypeError, msg: except TypeError, msg:
msg = str(msg) msg = str(msg)
if find(msg,'client') >= 0: if 'client' in msg:
raise NameError("'client' may not be used as an " + raise NameError("'client' may not be used as an "
"argument name in this context") "argument name in this context")
else: raise raise
finally: security.removeContext(self) finally:
security.removeContext(self)
if src__: return query if src__: return query
......
...@@ -150,7 +150,6 @@ def DCWorkflowDefinition_listGlobalActions(self, info): ...@@ -150,7 +150,6 @@ def DCWorkflowDefinition_listGlobalActions(self, info):
dict = {} dict = {}
# Patch for ERP5 by JP Smets in order # Patch for ERP5 by JP Smets in order
# to implement worklists and search of local roles # to implement worklists and search of local roles
searchres_len = 0
var_match_keys = qdef.getVarMatchKeys() var_match_keys = qdef.getVarMatchKeys()
if var_match_keys: if var_match_keys:
# Check the catalog for items in the worklist. # Check the catalog for items in the worklist.
...@@ -175,9 +174,11 @@ def DCWorkflowDefinition_listGlobalActions(self, info): ...@@ -175,9 +174,11 @@ def DCWorkflowDefinition_listGlobalActions(self, info):
dict['local_roles'] = guard.roles dict['local_roles'] = guard.roles
# Patch to use ZSQLCatalog and get high speed # Patch to use ZSQLCatalog and get high speed
# LOG("PatchedDCWorkflowDefinition", 0, dict) # LOG("PatchedDCWorkflowDefinition", 0, dict)
searchres_len = int(apply(catalog.countResults, (), dict)[0][0]) searchres_len = catalog.countResults(**dict)[0][0]
if searchres_len == 0: if not searchres_len:
continue continue
else:
searchres_len = 0
if fmt_data is None: if fmt_data is None:
fmt_data = TemplateDict() fmt_data = TemplateDict()
fmt_data._push(info) fmt_data._push(info)
......
...@@ -1088,7 +1088,7 @@ class ZCatalog(Folder, Persistent, Implicit): ...@@ -1088,7 +1088,7 @@ class ZCatalog(Folder, Persistent, Implicit):
""" """
catalog = self.getSQLCatalog(sql_catalog_id) catalog = self.getSQLCatalog(sql_catalog_id)
if catalog is not None: if catalog is not None:
return apply(catalog.searchResults, (REQUEST, ), kw) return catalog.searchResults(REQUEST, **kw)
return [] return []
__call__=searchResults __call__=searchResults
...@@ -1100,7 +1100,7 @@ class ZCatalog(Folder, Persistent, Implicit): ...@@ -1100,7 +1100,7 @@ class ZCatalog(Folder, Persistent, Implicit):
""" """
catalog = self.getSQLCatalog(sql_catalog_id) catalog = self.getSQLCatalog(sql_catalog_id)
if catalog is not None: if catalog is not None:
return apply(catalog.countResults, (REQUEST, ), kw) return catalog.countResults(REQUEST, **kw)
return [] return []
## this stuff is so the find machinery works ## this stuff is so the find machinery works
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment