27
def result_to_dict(method_info,result,encoding='UTF-8',allow_unsafe_conversion=False,only_strings_to_unicode=True):
29
Convert the result of a method call to it's dictionary representation.
31
from ladon.types.typeconverter import TypeConverter
32
from ladon.tools.multiparthandler import AttachmentHandler
33
from ladon.exceptions.types import AttachmentExpected
34
response_attachments = AttachmentHandler()
35
tc = TypeConverter(encoding=encoding,allow_unsafe_conversion=allow_unsafe_conversion,only_strings_to_unicode=only_strings_to_unicode)
37
'servicename': method_info.sinfo.servicename,
38
'servicenumber': method_info.sinfo.servicenumber,
39
'method': method_info.name()}
40
typ = method_info._rtype
26
def expand_value(value,valtype, encoding='UTF-8',allow_unsafe_conversion=False,only_strings_to_unicode=True,service_name='unknown', method_name='unknown'):
28
Convert the result of a method call to it's dictionary representation.
30
from ladon.types.typeconverter import TypeConverter
31
from ladon.tools.multiparthandler import AttachmentHandler
32
from ladon.exceptions.types import AttachmentExpected
33
response_attachments = AttachmentHandler()
34
tc = TypeConverter(encoding=encoding,allow_unsafe_conversion=allow_unsafe_conversion,only_strings_to_unicode=only_strings_to_unicode)
35
type_info = get_type_info(valtype)
37
if [list,tuple].count(type(valtype)):
39
type_info = get_type_info(valtype[0])
41
# Assumption list attributes are always optional
46
ret += [item.__dict__(tc,response_attachments)]
47
elif valtype[0]==attachment:
49
if not type(item) == attachment:
50
raise AttachmentExpected(service_name,method_name,'Attachment expected got: %s' % type(item))
51
ret += [response_attachments.add_attachment(item)]
54
ret += [tc.to_unicode_string(item,valtype[0])]
55
elif valtype==attachment:
56
ret = response_attachments.add_attachment(value)
58
ret = tc.to_unicode_string(value,valtype)
60
ret = value.__dict__(tc,response_attachments)
65
def result_to_dict(method_info,result, encoding='UTF-8',allow_unsafe_conversion=False,only_strings_to_unicode=True):
67
Convert the result of a method call to it's dictionary representation.
69
from ladon.types.typeconverter import TypeConverter
70
from ladon.tools.multiparthandler import AttachmentHandler
71
from ladon.exceptions.types import AttachmentExpected
72
response_attachments = AttachmentHandler()
73
tc = TypeConverter(encoding=encoding,allow_unsafe_conversion=allow_unsafe_conversion,only_strings_to_unicode=only_strings_to_unicode)
80
'servicename': method_info.sinfo.servicename,
81
'servicenumber': method_info.sinfo.servicenumber,
82
'method': method_info.name()}
83
typ = method_info._rtype
84
servicename = method_info.sinfo.servicename
41
85
type_info = get_type_info(typ)
42
86
if type_info==None:
43
87
if [list,tuple].count(type(typ)):