- return args
-
-def log(title, msg, channel=logging.DEBUG_RPC, depth=None, fn=""):
- logger = logging.getLogger(title)
- if logger.isEnabledFor(channel):
- indent=''
- indent_after=' '*len(fn)
- for line in (fn+pformat(msg, depth=depth)).split('\n'):
- logger.log(channel, indent+line)
- indent=indent_after
-
-# This class is used to dispatch a RPC to a service. So it is used
-# for both XMLRPC (with a SimpleXMLRPCRequestHandler), and NETRPC.
-# The service (ExportService) will then dispatch on the method name.
-# This can be re-written as a single function
-# def dispatch(self, service_name, method, params, auth_provider).
-class OpenERPDispatcher:
- def log(self, title, msg, channel=logging.DEBUG_RPC, depth=None, fn=""):
- log(title, msg, channel=channel, depth=depth, fn=fn)
- def dispatch(self, service_name, method, params):
- try:
- auth = getattr(self, 'auth_provider', None)
- logger = logging.getLogger('result')
- start_time = end_time = 0
- if logger.isEnabledFor(logging.DEBUG_RPC_ANSWER):
- self.log('service', tuple(replace_request_password(params)), depth=None, fn='%s.%s'%(service_name,method))
- if logger.isEnabledFor(logging.DEBUG_RPC):
- start_time = time.time()
- result = ExportService.getService(service_name).dispatch(method, auth, params)
- if logger.isEnabledFor(logging.DEBUG_RPC):
- end_time = time.time()
- if not logger.isEnabledFor(logging.DEBUG_RPC_ANSWER):
- self.log('service (%.3fs)' % (end_time - start_time), tuple(replace_request_password(params)), depth=1, fn='%s.%s'%(service_name,method))
- self.log('execution time', '%.3fs' % (end_time - start_time), channel=logging.DEBUG_RPC_ANSWER)
- self.log('result', result, channel=logging.DEBUG_RPC_ANSWER)
- return result
- except Exception, e:
- self.log('exception', tools.exception_to_unicode(e))
- tb = getattr(e, 'traceback', sys.exc_info())
- tb_s = "".join(traceback.format_exception(*tb))
- if tools.config['debug_mode'] and isinstance(tb, types.TracebackType):
- import pdb
- pdb.post_mortem(tb[2])
- raise OpenERPDispatcherException(e, tb_s)
+ return tuple(args)
+
+def log(logger, level, prefix, msg, depth=None):
+ indent=''
+ indent_after=' '*len(prefix)
+ for line in (prefix+pformat(msg, depth=depth)).split('\n'):
+ logger.log(level, indent+line)
+ indent=indent_after
+
+def dispatch_rpc(service_name, method, params):
+ """ Handle a RPC call.
+
+ This is pure Python code, the actual marshalling (from/to XML-RPC or
+ NET-RPC) is done in a upper layer.
+ """
+ try:
+ rpc_request = logging.getLogger(__name__ + '.rpc.request')
+ rpc_response = logging.getLogger(__name__ + '.rpc.response')
+ rpc_request_flag = rpc_request.isEnabledFor(logging.DEBUG)
+ rpc_response_flag = rpc_response.isEnabledFor(logging.DEBUG)
+ if rpc_request_flag or rpc_response_flag:
+ start_time = time.time()
+ if rpc_request and rpc_response_flag:
+ log(rpc_request,logging.DEBUG,'%s.%s'%(service_name,method), replace_request_password(params))
+
+ threading.current_thread().uid = None
+ threading.current_thread().dbname = None
+ result = ExportService.getService(service_name).dispatch(method, params)
+
+ if rpc_request_flag or rpc_response_flag:
+ end_time = time.time()
+ if rpc_response_flag:
+ log(rpc_response,logging.DEBUG,'%s.%s time:%.3fs '%(service_name,method,end_time - start_time), result)
+ else:
+ log(rpc_request,logging.DEBUG,'%s.%s time:%.3fs '%(service_name,method,end_time - start_time), replace_request_password(params), depth=1)
+
+ return result
+ except openerp.exceptions.AccessError:
+ raise
+ except openerp.exceptions.AccessDenied:
+ raise
+ except openerp.exceptions.Warning:
+ raise
+ except openerp.exceptions.DeferredException, e:
+ _logger.error(tools.exception_to_unicode(e))
+ post_mortem(e.traceback)
+ raise
+ except Exception, e:
+ _logger.error(tools.exception_to_unicode(e))
+ post_mortem(sys.exc_info())
+ raise
+
+def post_mortem(info):
+ if tools.config['debug_mode'] and isinstance(info[2], types.TracebackType):
+ import pdb
+ pdb.post_mortem(info[2])