|
|
|
@ -25,29 +25,29 @@ from .api_types import LazyString
|
|
|
|
|
|
|
|
|
|
#monkey patch:
|
|
|
|
|
def to_unicode(self, cls, value, *args, **kwargs):
|
|
|
|
|
if value is None:
|
|
|
|
|
return None
|
|
|
|
|
if value is None:
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
#### PATCH ####################
|
|
|
|
|
if isinstance(value, LazyString):
|
|
|
|
|
value = str(value)
|
|
|
|
|
###############################
|
|
|
|
|
#### PATCH ####################
|
|
|
|
|
if isinstance(value, LazyString):
|
|
|
|
|
value = str(value)
|
|
|
|
|
###############################
|
|
|
|
|
|
|
|
|
|
handler = self._to_unicode_handlers[cls]
|
|
|
|
|
retval = handler(cls, value, *args, **kwargs)
|
|
|
|
|
|
|
|
|
|
return retval
|
|
|
|
|
handler = self._to_unicode_handlers[cls]
|
|
|
|
|
retval = handler(cls, value, *args, **kwargs)
|
|
|
|
|
|
|
|
|
|
return retval
|
|
|
|
|
|
|
|
|
|
OutProtocolBase.to_unicode = to_unicode
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ServiceMetaAdapter(ServiceMeta):
|
|
|
|
|
#ref to the created class
|
|
|
|
|
#ref to the created class
|
|
|
|
|
global_class_ref = None
|
|
|
|
|
|
|
|
|
|
#this is used for a localCall
|
|
|
|
|
class CoreInnerWsdl(ServiceMeta, WsdlMeta):
|
|
|
|
|
pass
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
# Nevermind, following is deprecated:
|
|
|
|
|
|
|
|
|
@ -62,45 +62,45 @@ class CoreInnerWsdl(ServiceMeta, WsdlMeta):
|
|
|
|
|
#wraps a func in rpc decorator
|
|
|
|
|
#this is needed because Spyne service does not allow self ref in function calls
|
|
|
|
|
def make_rpc_func_view(func_to_call):
|
|
|
|
|
def _function(ctx, sid, params):
|
|
|
|
|
return func_to_call(ServiceMetaAdapter.global_class_ref, sid, params)
|
|
|
|
|
_function.__name__ = func_to_call.__name__
|
|
|
|
|
return rpc(Integer, ViewParams, _returns=ViewInfo)(_function)
|
|
|
|
|
def _function(ctx, sid, params):
|
|
|
|
|
return func_to_call(ServiceMetaAdapter.global_class_ref, sid, params)
|
|
|
|
|
_function.__name__ = func_to_call.__name__
|
|
|
|
|
return rpc(Integer, ViewParams, _returns=ViewInfo)(_function)
|
|
|
|
|
|
|
|
|
|
def make_rpc_func_vars(func_to_call):
|
|
|
|
|
def _function(ctx, dv=None, params=None):
|
|
|
|
|
return func_to_call(ServiceMetaAdapter.global_class_ref, dv, params)
|
|
|
|
|
_function.__name__ = func_to_call.__name__
|
|
|
|
|
return staticmethod(_function)
|
|
|
|
|
def _function(ctx, dv=None, params=None):
|
|
|
|
|
return func_to_call(ServiceMetaAdapter.global_class_ref, dv, params)
|
|
|
|
|
_function.__name__ = func_to_call.__name__
|
|
|
|
|
return staticmethod(_function)
|
|
|
|
|
|
|
|
|
|
def make_rpc_func_caller(func_to_call):
|
|
|
|
|
def _function(ctx, sid, params):
|
|
|
|
|
return func_to_call(ServiceMetaAdapter.global_class_ref, sid, params)
|
|
|
|
|
_function.__name__ = func_to_call.__name__
|
|
|
|
|
info_class = func_to_call.info_class
|
|
|
|
|
return rpc(Integer, info_class, _returns=Array(ReturnedMessage))(_function)
|
|
|
|
|
def _function(ctx, sid, params):
|
|
|
|
|
return func_to_call(ServiceMetaAdapter.global_class_ref, sid, params)
|
|
|
|
|
_function.__name__ = func_to_call.__name__
|
|
|
|
|
info_class = func_to_call.info_class
|
|
|
|
|
return rpc(Integer, info_class, _returns=Array(ReturnedMessage))(_function)
|
|
|
|
|
|
|
|
|
|
def make_service(basic_class, wsdl_core_class_list, outer_wsdl_class_list, service_name):
|
|
|
|
|
#for Core, rpc methods only present in basic_class, we need others just to have a mono class
|
|
|
|
|
#for outer wsdl classes, we have to add stateless wrap methods on our own
|
|
|
|
|
|
|
|
|
|
saved_pub_methods = basic_class.public_methods
|
|
|
|
|
|
|
|
|
|
functions_to_add = {}
|
|
|
|
|
for klass in outer_wsdl_class_list:
|
|
|
|
|
for meth in klass.__dict__:
|
|
|
|
|
if not meth.startswith("__") and not meth == "methods":
|
|
|
|
|
if meth.endswith("_view"):
|
|
|
|
|
functions_to_add[meth] = make_rpc_func_view(getattr(klass, meth))
|
|
|
|
|
elif meth.endswith("_vars"):
|
|
|
|
|
functions_to_add[meth] = make_rpc_func_vars(getattr(klass, meth))
|
|
|
|
|
else:
|
|
|
|
|
functions_to_add[meth] = make_rpc_func_caller(getattr(klass, meth))
|
|
|
|
|
|
|
|
|
|
functions_to_add.update({"__metaclass__" : ServiceMetaAdapter})
|
|
|
|
|
ClService = ServiceMetaAdapter(service_name, tuple([basic_class] + wsdl_core_class_list), functions_to_add)
|
|
|
|
|
ClService.public_methods.update(saved_pub_methods)
|
|
|
|
|
#TODO replace with a single ref
|
|
|
|
|
ServiceMetaAdapter.global_class_ref = ClService
|
|
|
|
|
basic_class.set_comb_class_ref(ClService)
|
|
|
|
|
return ClService
|
|
|
|
|
#for Core, rpc methods only present in basic_class, we need others just to have a mono class
|
|
|
|
|
#for outer wsdl classes, we have to add stateless wrap methods on our own
|
|
|
|
|
|
|
|
|
|
saved_pub_methods = basic_class.public_methods
|
|
|
|
|
|
|
|
|
|
functions_to_add = {}
|
|
|
|
|
for klass in outer_wsdl_class_list:
|
|
|
|
|
for meth in klass.__dict__:
|
|
|
|
|
if not meth.startswith("__") and not meth == "methods":
|
|
|
|
|
if meth.endswith("_view"):
|
|
|
|
|
functions_to_add[meth] = make_rpc_func_view(getattr(klass, meth))
|
|
|
|
|
elif meth.endswith("_vars"):
|
|
|
|
|
functions_to_add[meth] = make_rpc_func_vars(getattr(klass, meth))
|
|
|
|
|
else:
|
|
|
|
|
functions_to_add[meth] = make_rpc_func_caller(getattr(klass, meth))
|
|
|
|
|
|
|
|
|
|
functions_to_add.update({"__metaclass__" : ServiceMetaAdapter})
|
|
|
|
|
ClService = ServiceMetaAdapter(service_name, tuple([basic_class] + wsdl_core_class_list), functions_to_add)
|
|
|
|
|
ClService.public_methods.update(saved_pub_methods)
|
|
|
|
|
#TODO replace with a single ref
|
|
|
|
|
ServiceMetaAdapter.global_class_ref = ClService
|
|
|
|
|
basic_class.set_comb_class_ref(ClService)
|
|
|
|
|
return ClService
|
|
|
|
|