monkey patched LazyString eval

migr_to_spyne
idziubenko 3 years ago
parent 9424f21e63
commit 3407d3420f

@ -16,20 +16,13 @@
from calculate.core.server.loaded_methods import LoadedMethods
# from soaplib.serializers.primitive import String, Integer, Boolean, string_encoding
from spyne import String, Integer, Boolean
# from soaplib.serializers.clazz import Array, ComplexModel
from spyne.model.primitive import string_encoding
from spyne import Array, ComplexModel
from spyne import rpc
# from soaplib.serializers import nillable_value, nillable_element
# from soaplib.serializers import string_to_xml
# from soaplib.service import rpc
from spyne import rpc
import spyne
import sys
import pickle
import os
@ -62,22 +55,6 @@ class CommonInfo(ComplexModel):
class LazyString(object):
pass
def lazyable(cl):
def to_xml(cls, value, tns, parent_elt, name='retval'):
if isinstance(value, LazyString):
value = str(value)
if not isinstance(value, unicode):
value = unicode(value, string_encoding)
# string_to_xml(cls, value, tns, parent_elt, name)
cl.to_xml = classmethod(to_xml)
return cl
String = lazyable(String)
class DataVarsSerializer(ComplexModel):
"""Serializer for datavars types"""
@ -776,14 +753,6 @@ class CoreWsdl(CoreServiceInterface):
# @rpc(_returns=String)
# def whoami_api_types(ctx): # ctx is the 'context' parameter used by Spyne
# """
# Dummy test method.
# """
# return "Hello I am " + ctx.descriptor.service_class.__name__ + "!"
class WsdlAdapter(object):
adapted_class = None

@ -228,10 +228,7 @@ def main(*args, **keywords):
# importing other modules
from func import initialization
cl_wsdl_classes = initialization(cl_wsdl)
outer_wsdl_classes = initialization(cl_wsdl)
pack = "calculate.core.server"
import importlib
@ -241,14 +238,12 @@ def main(*args, **keywords):
core_wsdl_classes.append(func_metaclass.Func_MetaClass)
from calculate.core.server.baseClass import Basic
# core_wsdl_classes.append(Basic)
# core_wsdl_classes.append(object) #why is this here?
# make server metaclass
if args.method or args.list_methods:
from local_call import local_method, LocalCall
ClService = CoreInnerWsdl("ClService",
tuple([LocalCall] + cl_wsdl_classes + [Basic] + core_wsdl_classes),
tuple([LocalCall] + outer_wsdl_classes + [Basic] + core_wsdl_classes),
{
"__metaclass__" : CoreInnerWsdl
})
@ -256,34 +251,17 @@ def main(*args, **keywords):
tc.set_comb_class_ref(tc)
return local_method(tc, args, unknown_args)
ClService = make_service(Basic, core_wsdl_classes, cl_wsdl_classes, "ClService")
# pub_methods = Basic.public_methods
# ClService = ServiceMetaAdapter("ClService", tuple(cl_wsdl_classes + core_wsdl_classes), {
# "__metaclass__" : ServiceMetaAdapter
# })
# #total hack, but those would've been overwritten in __init__
# ClService.public_methods = pub_methods
ClService = make_service(Basic, core_wsdl_classes, outer_wsdl_classes, "ClService")
# print(dir(ClService))
# print(ClService.public_methods)
from server_class import ClApplication, OpenSSLAdapter
# Cl_wsdl_service = make_service_from_wsdl_classes(cl_wsdl_classes, "Cl_wsdl_service", ClService)
#do we even need this anymore?
tc = ClService()
# print(type(tc))
App = Application([ClService], 'tns',
name="ClApplication",
# in_protocol=XmlDocument(),
# in_protocol=HttpRpc(),
# out_protocol=XmlDocument(),
# in_protocol=Soap11(validator="lxml"),
in_protocol=Soap11(),
out_protocol=Soap11(),
# out_protocol=JsonDocument(),
)
# delete all sid and pid informations fileo
# delete all sid and pid informations file
wsgi_application = ClApplication(App, log=file_logger)
cert_cmd.create_path(data_path, certbase, rights, group_rights,
local_data_path)

@ -2,6 +2,25 @@ from spyne.service import Service, ServiceMeta
from spyne import String, Integer, Array, rpc
from func import WsdlMeta
from api_types import ReturnedMessage, ViewInfo, ViewParams
from spyne.protocol._outbase import OutProtocolBase
from api_types import LazyString
#monkey patch:
#we add a check for a lazy string
def to_unicode(self, cls, value, *args, **kwargs):
if value is None:
return None
if isinstance(value, LazyString):
value = str(value)
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
@ -10,15 +29,15 @@ class ServiceMetaAdapter(ServiceMeta):
class CoreInnerWsdl(ServiceMeta, WsdlMeta):
pass
# Nevermind, following is deprecated:
#the idea is to decorate methods that need rpc with this
#and then find them in make_service and wrap them in funcs without self ref
def rpc_a():
def func(f):
f.wrap_rpc = True
return f
return func
# def rpc_a():
# def func(f):
# f.wrap_rpc = True
# return f
# return func
#wraps a func in rpc decorator
#this is needed because Spyne service does not allow self ref in function calls
@ -41,26 +60,8 @@ def make_rpc_func_caller(func_to_call):
info_class = func_to_call.info_class
return rpc(Integer, info_class, _returns=Array(ReturnedMessage))(_function)
def make_service_from_wsdl_classes(class_list, service_name, ClService):
pass
# functions_to_add = {}
# for klass in class_list:
# for meth in klass.__dict__:
# # print(meth)
# # print(getattr(klass, meth))
# if not meth.startswith("__") and not meth == "methods" and not meth.endswith("_vars"):
# # print(meth)
# # print(getattr(klass, meth))
# if meth.endswith("_view"):
# functions_to_add[meth] = make_rpc_func_view(getattr(klass, meth), ClService)
# else:
# functions_to_add[meth] = make_rpc_func_caller(getattr(klass, meth), ClService)
# return ServiceMeta(service_name, tuple([Service]), functions_to_add)
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 the others to have a single structure
#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

Loading…
Cancel
Save