本文整理汇总了Python中spyne.model.complex.ComplexModel类的典型用法代码示例。如果您正苦于以下问题:Python ComplexModel类的具体用法?Python ComplexModel怎么用?Python ComplexModel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ComplexModel类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _produce_input_message
def _produce_input_message(f, params, kparams, _in_message_name,
_in_variable_names, no_ctx, no_self, args):
_body_style = _validate_body_style(kparams)
arg_start = 0
if no_ctx is False:
arg_start += 1
if no_self is False:
arg_start += 1
if args is None:
try:
argcount = f.__code__.co_argcount
args = f.__code__.co_varnames[arg_start:argcount]
except AttributeError:
raise TypeError(
"It's not possible to instrospect builtins. You must pass a "
"sequence of argument names as the '_args' argument to the "
"rpc decorator to manually denote the arguments that this "
"function accepts."
)
if len(params) != len(args):
raise Exception("%r function has %d argument(s) but its decorator "
"has %d." % (f.__name__, len(args), len(params)))
else:
args = copy(args)
if len(params) != len(args):
raise Exception("%r function has %d argument(s) but the _args "
"argument has %d." % (f.__name__, len(args), len(params)))
in_params = TypeInfo()
for k, v in zip(args, params):
k = _in_variable_names.get(k, k)
in_params[k] = v
ns = spyne.const.xml_ns.DEFAULT_NS
if _in_message_name.startswith("{"):
ns, _, _in_message_name = _in_message_name[1:].partition("}")
if _body_style == 'bare':
if len(in_params) > 1:
raise Exception("body_style='bare' can handle at most one function "
"argument.")
if len(in_params) == 0:
message = ComplexModel.produce(type_name=_in_message_name,
namespace=ns, members=in_params)
else:
message, = in_params.values()
message = message.customize(sub_name=_in_message_name, sub_ns=ns)
assert message.Attributes.sub_name is not None
else:
message = ComplexModel.produce(type_name=_in_message_name,
namespace=ns, members=in_params)
message.__namespace__ = ns
return message
示例2: _produce_output_message
def _produce_output_message(func_name, kparams):
"""Generate an output message for "rpc"-style API methods.
This message is a wrapper to the declared return type.
"""
_returns = kparams.get('_returns')
_body_style = _validate_body_style(kparams)
_out_message_name = kparams.get('_out_message', '%s%s' %
(func_name, RESPONSE_SUFFIX))
out_params = TypeInfo()
if _returns and _body_style == 'wrapped':
if isinstance(_returns, (list, tuple)):
default_names = ['%s%s%d' % (func_name, RESULT_SUFFIX, i) for i in
range(len(_returns))]
_out_variable_names = kparams.get('_out_variable_names',
default_names)
assert (len(_returns) == len(_out_variable_names))
var_pair = zip(_out_variable_names, _returns)
out_params = TypeInfo(var_pair)
else:
_out_variable_name = kparams.get('_out_variable_name',
'%s%s' % (func_name, RESULT_SUFFIX))
out_params[_out_variable_name] = _returns
ns = DEFAULT_NS
if _out_message_name.startswith("{"):
ns = _out_message_name[1:].partition("}")[0]
if _body_style == 'bare' and _returns is not None:
message = ComplexModel.alias(_out_message_name, ns, _returns)
else:
message = ComplexModel.produce(type_name=_out_message_name,
namespace=ns,
members=out_params)
message.Attributes._wrapper = True
message.__namespace__ = ns # FIXME: is this necessary?
return message
示例3: test_to_parent_element_nested
def test_to_parent_element_nested(self):
m = ComplexModel.produce(
namespace=None,
type_name='myMessage',
members={'p':Person}
)
m.resolve_namespace(m, "m")
p = Person()
p.name = 'steve-o'
p.age = 2
p.addresses = []
for i in range(0, 100):
a = Address()
a.street = '123 happy way'
a.zip = i
a.laditude = '45.22'
a.longitude = '444.234'
p.addresses.append(a)
m_inst = m(p=p)
element=etree.Element('test')
Soap11().to_parent_element(m, m_inst, m.get_namespace(), element)
element=element[0]
self.assertEquals('{%s}myMessage' % m.get_namespace(), element.tag)
addresses = element[0].find('{%s}addresses' % Person.get_namespace())
self.assertEquals(100, len(addresses))
self.assertEquals('0', addresses[0].find('{%s}zip' % Address.get_namespace()).text)
示例4: test_class_to_parent_element
def test_class_to_parent_element(self):
m = ComplexModel.produce(
namespace=None,
type_name='myMessage',
members={'p': Person}
)
m.resolve_namespace(m, "punk")
m_inst = m()
m_inst.p = Person()
m_inst.p.name = 'steve-o'
m_inst.p.age = 2
m_inst.p.addresses = []
element=etree.Element('test')
Soap11().to_parent_element(m, m_inst, m.get_namespace(), element)
element=element[0]
self.assertEquals(element.tag, '{%s}myMessage' % m.get_namespace())
self.assertEquals(element[0].find('{%s}name' % Person.get_namespace()).text,
'steve-o')
self.assertEquals(element[0].find('{%s}age' % Person.get_namespace()).text, '2')
self.assertEquals(
len(element[0].find('{%s}addresses' % Person.get_namespace())), 0)
p1 = Soap11().from_element(m,element)[0]
self.assertEquals(p1.name, m_inst.p.name)
self.assertEquals(p1.age, m_inst.p.age)
self.assertEquals(p1.addresses, [])
示例5: test_namespaces
def test_namespaces(self):
m = ComplexModel.produce(
namespace="some_namespace",
type_name='myMessage',
members={'s': String, 'i': Integer},
)
mi = m()
mi.s = 'a'
e = etree.Element('test')
Soap11().to_parent_element(m, mi, m.get_namespace(), e)
e=e[0]
self.assertEquals(e.tag, '{some_namespace}myMessage')
示例6: test_simple_message
def test_simple_message(self):
m = ComplexModel.produce(
namespace=None,
type_name='myMessage',
members={'s': String, 'i': Integer}
)
m.resolve_namespace(m, 'test')
m_inst = m(s="a", i=43)
e = etree.Element('test')
Soap11().to_parent_element(m, m_inst, m.get_namespace(), e)
e=e[0]
self.assertEquals(e.tag, '{%s}myMessage' % m.get_namespace())
self.assertEquals(e.find('{%s}s' % m.get_namespace()).text, 'a')
self.assertEquals(e.find('{%s}i' % m.get_namespace()).text, '43')
values = Soap11().from_element(m, e)
self.assertEquals('a', values.s)
self.assertEquals(43, values.i)
示例7: len
message = None
if _body_style == 'bare':
if len(in_params) > 1:
raise Exception("body_style='bare' can handle at most one function "
"argument.")
in_param = None
if len(in_params) == 1:
message, = in_params.values()
message = message.customize(sub_name=_in_message_name, sub_ns=ns)
assert message.Attributes.sub_name is not None
# This dates from a time when body_style='bare' could support more
# than one parameter. Maybe one day someone will bring that back.
else:
message = ComplexModel.produce(type_name=_in_message_name,
namespace=ns, members=in_params)
else:
message = ComplexModel.produce(type_name=_in_message_name,
namespace=ns, members=in_params)
message.__namespace__ = ns
return message
def _validate_body_style(kparams):
_body_style = kparams.get('_body_style')
_soap_body_style = kparams.get('_soap_body_style')
if _body_style is None:
_body_style = 'wrapped'