You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the Python version, when called using complex Python object with __str__ method the rpc fails as the object converted to its string representation.
The fix is relatively simple:
Modify the FunctionCall object:
1.1. Change the __init__ function
1.2. Created a function call call that first get the function attrbute name of the object and then pass the args and kwargs
class FunctionCall(dict):
"""Encapsulates a function call as a Python dictionary."""
@staticmethod
def from_dict(dictionary):
"""Return a new FunctionCall from a Python dictionary."""
name = dictionary.get('name')
args = dictionary.get('args')
kwargs = dictionary.get('kwargs')
return FunctionCall(name, args, kwargs)
def __init__(self, name, args=None, kwargs=None):
"""Create a new FunctionCall from a method name, an optional argument tuple, and an optional keyword argument
dictionary."""
self['name'] = name
if not args:
self['args'] = []
else:
self['args'] = args
if not kwargs:
self['kwargs'] = [{}]
else:
self['kwargs'] = kwargs
def call(self, local_object):
func = getattr(local_object, self['name'])
return func(*self['args'], **self['kwargs'])
def as_python_code(self):
"""Return a string representation of this object that can be evaled to execute the function call."""
argstring = '' if 'args' not in self else \
','.join(str(arg) for arg in self['args'])
kwargstring = '' if 'kwargs' not in self else \
','.join('%s=%s' % (key,val) for (key,val) in list(self['kwargs'].items()))
if len(argstring) == 0:
params = kwargstring
elif len(kwargstring) == 0:
params = argstring
else:
params = ','.join([argstring,kwargstring])
return '%s(%s)' % (self['name'], params)
The Server class also needs to be modified to replace the exec statement with function_call.call(self.local_object)
In the Python version, when called using complex Python object with
__str__
method therpc
fails as the object converted to its string representation.The fix is relatively simple:
1.1. Change the
__init__
function1.2. Created a function call
call
that first get the function attrbutename
of the object and then pass theargs
andkwargs
exec
statement withfunction_call.call(self.local_object)
The text was updated successfully, but these errors were encountered: