diff --git a/product/CMFActivity/Activity/Queue.py b/product/CMFActivity/Activity/Queue.py index 542590ae95dd60bb45e2887d65ee505ea091449d..0e282556c33f9f251a270a980e4927041d3df7a4 100644 --- a/product/CMFActivity/Activity/Queue.py +++ b/product/CMFActivity/Activity/Queue.py @@ -26,7 +26,7 @@ # ############################################################################## -import cPickle, sys +import sys from hashlib import sha1 from DateTime import DateTime from zLOG import LOG, WARNING, ERROR @@ -202,14 +202,6 @@ class Queue(object): def flush(self, activity_tool, object, **kw): pass - def loadMessage(self, s, **kw): - m = cPickle.load(StringIO(s)) - m.__dict__.update(kw) - return m - - def dumpMessage(self, m): - return cPickle.dumps(m) - def getOrderValidationText(self, message): # Return an identifier of validators related to ordering. order_validation_item_list = [] diff --git a/product/CMFActivity/Activity/SQLBase.py b/product/CMFActivity/Activity/SQLBase.py index 71096bd218212ecd8c9443f2ee47f975b79e12e1..f7fc7f42b1efbcac439314a9fb2bbd311ce057ca 100644 --- a/product/CMFActivity/Activity/SQLBase.py +++ b/product/CMFActivity/Activity/SQLBase.py @@ -33,7 +33,7 @@ from Shared.DC.ZRDB.Results import Results from zLOG import LOG, TRACE, INFO, WARNING, ERROR, PANIC from ZODB.POSException import ConflictError from Products.CMFActivity.ActivityTool import ( - MESSAGE_NOT_EXECUTED, MESSAGE_EXECUTED) + Message, MESSAGE_NOT_EXECUTED, MESSAGE_EXECUTED) from Products.CMFActivity.ActiveObject import INVOKE_ERROR_STATE from Products.CMFActivity.ActivityRuntimeEnvironment import ( ActivityRuntimeEnvironment, getTransactionalVariable) @@ -122,7 +122,7 @@ class SQLBase(Queue): if type(result) is str: # src__ == 1 return result, class_name = self.__class__.__name__ - return [self.loadMessage(line.message, + return [Message.load(line.message, activity=class_name, uid=line.uid, processing_node=line.processing_node, @@ -221,7 +221,7 @@ class SQLBase(Queue): # do not merge anything def load(line): uid = line.uid - m = self.loadMessage(line.message, uid=uid, line=line) + m = Message.load(line.message, uid=uid, line=line) return m, uid, () return load @@ -546,6 +546,6 @@ class SQLBase(Queue): **({'method_id': method_id} if method_id else {})): uid_list.append(line.uid) if invoke: - invoke(self.loadMessage(line.message, uid=line.uid, line=line)) + invoke(Message.load(line.message, uid=line.uid, line=line)) if uid_list: activity_tool.SQLBase_delMessage(table=self.sql_table, uid=uid_list) diff --git a/product/CMFActivity/Activity/SQLDict.py b/product/CMFActivity/Activity/SQLDict.py index 2a9eb0f3875e06b9f14d5d2030508445ea9c4840..bab33f6411f0cae9ff4ae334abd91831012c659b 100644 --- a/product/CMFActivity/Activity/SQLDict.py +++ b/product/CMFActivity/Activity/SQLDict.py @@ -26,7 +26,7 @@ # ############################################################################## -from Products.CMFActivity.ActivityTool import registerActivity, MESSAGE_NOT_EXECUTED, MESSAGE_EXECUTED +from Products.CMFActivity.ActivityTool import Message, registerActivity import sys #from time import time from SQLBase import SQLBase, sort_message_key @@ -73,7 +73,7 @@ class SQLDict(SQLBase): # schema, and much code can be merged into SQLBase. order_validation_text_list.append(x) processing_node_list.append(0 if x == 'none' else -1) - dumped_message_list = map(self.dumpMessage, message_list) + dumped_message_list = map(Message.dump, message_list) # The uid_list also is store in the ZODB uid_list = activity_tool.getPortalObject().portal_ids.generateNewIdList( id_generator='uid', id_group='portal_activity', @@ -128,7 +128,7 @@ class SQLDict(SQLBase): uid = line.uid original_uid = path_and_method_id_dict.get(key) if original_uid is None: - m = self.loadMessage(line.message, uid=uid, line=line) + m = Message.load(line.message, uid=uid, line=line) merge_parent = m.activity_kw.get('merge_parent') try: if merge_parent: @@ -154,7 +154,7 @@ class SQLDict(SQLBase): line = result[0] key = line.path, method_id uid = line.uid - m = self.loadMessage(line.message, uid=uid, line=line) + m = Message.load(line.message, uid=uid, line=line) # return unreserved similar children result = activity_tool.SQLDict_selectChildMessageList( path=line.path, @@ -208,7 +208,7 @@ class SQLDict(SQLBase): if dumpMessageList is not None: result = dumpMessageList() for line in result: - m = self.loadMessage(line.message, uid=line.uid, line=line) + m = Message.load(line.message, uid=line.uid, line=line) message_list.append(m) return message_list @@ -229,7 +229,7 @@ class SQLDict(SQLBase): validation_text_dict = {'none': 1} message_dict = {} for line in result: - message = self.loadMessage(line.message, uid=line.uid, line=line) + message = Message.load(line.message, uid=line.uid, line=line) if not hasattr(message, 'order_validation_text'): # BBB message.order_validation_text = line.order_validation_text self.getExecutableMessageList(activity_tool, message, message_dict, @@ -307,7 +307,7 @@ class SQLDict(SQLBase): serialization_tag=serialization_tag) message_list = [] for line in result: - m = self.loadMessage(line.message, + m = Message.load(line.message, line=line, uid=line.uid, date=line.date, diff --git a/product/CMFActivity/Activity/SQLQueue.py b/product/CMFActivity/Activity/SQLQueue.py index 2d25c2ad27daf30c5daa84ba9c2f718e689346a6..94c1dad985e32435c240d4b373de1a36c3543c48 100644 --- a/product/CMFActivity/Activity/SQLQueue.py +++ b/product/CMFActivity/Activity/SQLQueue.py @@ -26,7 +26,7 @@ # ############################################################################## -from Products.CMFActivity.ActivityTool import registerActivity, MESSAGE_NOT_EXECUTED, MESSAGE_EXECUTED +from Products.CMFActivity.ActivityTool import Message, registerActivity from ZODB.POSException import ConflictError from SQLBase import SQLBase, sort_message_key from zExceptions import ExceptionFormatter @@ -71,7 +71,7 @@ class SQLQueue(SQLBase): for m in message_list: m.order_validation_text = x = self.getOrderValidationText(m) processing_node_list.append(0 if x == 'none' else -1) - dumped_message_list = map(self.dumpMessage, message_list) + dumped_message_list = map(Message.dump, message_list) activity_tool.SQLQueue_writeMessageList( uid_list=uid_list, path_list=path_list, @@ -127,7 +127,7 @@ class SQLQueue(SQLBase): if dumpMessageList is not None: result = dumpMessageList() for line in result: - m = self.loadMessage(line.message, uid=line.uid, line=line) + m = Message.load(line.message, uid=line.uid, line=line) message_list.append(m) return message_list @@ -148,7 +148,7 @@ class SQLQueue(SQLBase): validation_text_dict = {'none': 1} message_dict = {} for line in result: - message = self.loadMessage(line.message, uid=line.uid, line=line) + message = Message.load(line.message, uid=line.uid, line=line) if not hasattr(message, 'order_validation_text'): # BBB message.order_validation_text = self.getOrderValidationText(message) self.getExecutableMessageList(activity_tool, message, message_dict, @@ -202,7 +202,7 @@ class SQLQueue(SQLBase): serialization_tag=serialization_tag) message_list = [] for line in result: - m = self.loadMessage(line.message, + m = Message.load(line.message, line=line, uid=line.uid, date=line.date, diff --git a/product/CMFActivity/ActivityTool.py b/product/CMFActivity/ActivityTool.py index 8eefbed022cad5d2fcec2b869f32e9e12e5fc36d..58207e0b49059cc695e919d42b56247bd1837fe6 100644 --- a/product/CMFActivity/ActivityTool.py +++ b/product/CMFActivity/ActivityTool.py @@ -32,7 +32,7 @@ import threading import sys from types import StringType import re - +from cPickle import dumps, loads from Products.CMFCore import permissions as CMFCorePermissions from Products.ERP5Type.Core.Folder import Folder from Products.CMFActivity.ActiveResult import ActiveResult @@ -214,6 +214,14 @@ class Message(BaseMessage): request.environ['HTTP_ACCEPT_LANGUAGE'] self.request_info['_script'] = list(request._script) + @staticmethod + def load(s, **kw): + self = loads(s) + self.__dict__.update(kw) + return self + + dump = dumps + def getGroupId(self): get = self.activity_kw.get group_method_id = get('group_method_id', '')