/usr/lib/python2.7/dist-packages/trytond/rpc.py is in tryton-server 3.0.2-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | #This file is part of Tryton. The COPYRIGHT file at the top level of
#this repository contains the full copyright notices and license terms.
__all__ = ['RPC']
class RPC(object):
'''Define RPC behavior
readonly: The transaction mode
instantiate: The position of the argument to be instanciated
result: The function to transform the result
'''
__slots__ = ('readonly', 'instantiate', 'result')
def __init__(self, readonly=True, instantiate=None, result=None):
self.readonly = readonly
self.instantiate = instantiate
if result is None:
result = lambda r: r
self.result = result
def convert(self, obj, *args, **kwargs):
args = list(args)
kwargs = kwargs.copy()
if 'context' in kwargs:
context = kwargs.pop('context')
else:
context = args.pop()
timestamp = None
if '_timestamp' in context:
timestamp = context['_timestamp']
del context['_timestamp']
if self.instantiate is not None:
def instance(data):
if isinstance(data, (int, long)):
return obj(data)
elif isinstance(data, dict):
return obj(**data)
else:
return obj.browse(data)
data = args[self.instantiate]
args[self.instantiate] = instance(data)
return args, kwargs, context, timestamp
|