本文整理汇总了Python中spyne.server.ServerBase.get_out_string方法的典型用法代码示例。如果您正苦于以下问题:Python ServerBase.get_out_string方法的具体用法?Python ServerBase.get_out_string怎么用?Python ServerBase.get_out_string使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类spyne.server.ServerBase
的用法示例。
在下文中一共展示了ServerBase.get_out_string方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_attribute_ns
# 需要导入模块: from spyne.server import ServerBase [as 别名]
# 或者: from spyne.server.ServerBase import get_out_string [as 别名]
def test_attribute_ns(self):
class a(ComplexModel):
b = Unicode
c = XmlAttribute(Unicode, ns="spam", attribute_of="b")
class SomeService(ServiceBase):
@srpc(_returns=a)
def some_call():
return a(b="foo",c="bar")
app = Application([SomeService], "tns", in_protocol=XmlDocument(),
out_protocol=XmlDocument())
server = ServerBase(app)
initial_ctx = MethodContext(server)
initial_ctx.in_string = ['<some_call xmlns="tns"/>']
ctx, = server.generate_contexts(initial_ctx)
server.get_in_object(ctx)
server.get_out_object(ctx)
server.get_out_string(ctx)
elt = etree.fromstring(''.join(ctx.out_string))
target = elt.xpath('//s0:b', namespaces=app.interface.nsmap)[0]
print(etree.tostring(elt, pretty_print=True))
assert target.attrib['{%s}c' % app.interface.nsmap["s1"]] == "bar"
示例2: test_multiple_return_sd_0
# 需要导入模块: from spyne.server import ServerBase [as 别名]
# 或者: from spyne.server.ServerBase import get_out_string [as 别名]
def test_multiple_return_sd_0(self):
class SomeService(ServiceBase):
@srpc(_returns=Iterable(Integer))
def some_call():
return 1, 2
app = Application([SomeService], 'tns', JsonObject(), JsonObject(),
Wsdl11())
server = ServerBase(app)
initial_ctx = MethodContext(server)
initial_ctx.in_string = ['{"some_call":{}}']
ctx, = server.generate_contexts(initial_ctx)
server.get_in_object(ctx)
server.get_out_object(ctx)
server.get_out_string(ctx)
assert list(ctx.out_string) == ['{"some_callResponse": {"some_callResult": {"integer": [1, 2]}}}' ]
server = ServerBase(app)
initial_ctx = MethodContext(server)
initial_ctx.in_string = ['{"some_call":[]}']
ctx, = server.generate_contexts(initial_ctx)
server.get_in_object(ctx)
server.get_out_object(ctx)
server.get_out_string(ctx)
assert list(ctx.out_string) == ['{"some_callResponse": {"some_callResult": {"integer": [1, 2]}}}']
示例3: _dry_me
# 需要导入模块: from spyne.server import ServerBase [as 别名]
# 或者: from spyne.server.ServerBase import get_out_string [as 别名]
def _dry_me(services, d, ignore_wrappers=False, complex_as=dict,
just_ctx=False, just_in_object=False, validator=None,
polymorphic=False):
app = Application(services, 'tns',
in_protocol=_DictDocumentChild(
ignore_wrappers=ignore_wrappers, complex_as=complex_as,
polymorphic=polymorphic, validator=validator,
),
out_protocol=_DictDocumentChild(
ignore_wrappers=ignore_wrappers, complex_as=complex_as,
polymorphic=polymorphic),
)
server = ServerBase(app)
initial_ctx = MethodContext(server, MethodContext.SERVER)
in_string = serializer.dumps(d, **dumps_kwargs)
if not isinstance(in_string, bytes):
in_string = in_string.encode('utf8')
initial_ctx.in_string = [in_string]
ctx, = server.generate_contexts(initial_ctx, in_string_charset='utf8')
if not just_ctx:
server.get_in_object(ctx)
if not just_in_object:
server.get_out_object(ctx)
server.get_out_string(ctx)
return ctx
示例4: test_mandatory_elements
# 需要导入模块: from spyne.server import ServerBase [as 别名]
# 或者: from spyne.server.ServerBase import get_out_string [as 别名]
def test_mandatory_elements(self):
class SomeService(ServiceBase):
@srpc(M(Unicode), _returns=Unicode)
def some_call(s):
assert s == 'hello'
return s
app = Application([SomeService], "tns", name="test_mandatory_elements",
in_protocol=XmlDocument(validator='lxml'),
out_protocol=XmlDocument())
server = ServerBase(app)
# Valid call with all mandatory elements in
ctx = self._get_ctx(server, [
'<some_call xmlns="tns">'
'<s>hello</s>'
'</some_call>'
])
server.get_out_object(ctx)
server.get_out_string(ctx)
ret = etree.fromstring(''.join(ctx.out_string)).xpath(
'//tns:some_call%s/text()' % RESULT_SUFFIX,
namespaces=app.interface.nsmap)[0]
assert ret == 'hello'
# Invalid call
ctx = self._get_ctx(server, [
'<some_call xmlns="tns">'
# no mandatory elements here...
'</some_call>'
])
self.assertRaises(SchemaValidationError, server.get_out_object, ctx)
示例5: test_decimal
# 需要导入模块: from spyne.server import ServerBase [as 别名]
# 或者: from spyne.server.ServerBase import get_out_string [as 别名]
def test_decimal(self):
d = decimal.Decimal('1e100')
class SomeService(ServiceBase):
@srpc(Decimal(120,4), _returns=Decimal)
def some_call(p):
print(p)
print(type(p))
assert type(p) == decimal.Decimal
assert d == p
return p
app = Application([SomeService], "tns", in_protocol=XmlDocument(),
out_protocol=XmlDocument())
server = ServerBase(app)
initial_ctx = MethodContext(server)
initial_ctx.in_string = ['<some_call xmlns="tns"><p>%s</p></some_call>'
% d]
ctx, = server.generate_contexts(initial_ctx)
server.get_in_object(ctx)
server.get_out_object(ctx)
server.get_out_string(ctx)
elt = etree.fromstring(''.join(ctx.out_string))
print(etree.tostring(elt, pretty_print=True))
target = elt.xpath('//tns:some_callResult/text()',
namespaces=app.interface.nsmap)[0]
assert target == str(d)
示例6: test_primitive_only
# 需要导入模块: from spyne.server import ServerBase [as 别名]
# 或者: from spyne.server.ServerBase import get_out_string [as 别名]
def test_primitive_only(self):
class SomeComplexModel(ComplexModel):
i = Integer
s = String
class SomeService(ServiceBase):
@srpc(SomeComplexModel, _returns=SomeComplexModel)
def some_call(scm):
return SomeComplexModel(i=5, s='5x')
app = Application([SomeService], 'tns',
in_protocol=_DictObjectChild(),
out_protocol=_DictObjectChild())
server = ServerBase(app)
initial_ctx = MethodContext(server)
initial_ctx.in_string = [serializer.dumps({"some_call":[]})]
ctx, = server.generate_contexts(initial_ctx)
server.get_in_object(ctx)
server.get_out_object(ctx)
server.get_out_string(ctx)
assert list(ctx.out_string) == [serializer.dumps(
{"some_callResponse": {"some_callResult": {"i": 5, "s": "5x"}}})]
示例7: test_complex
# 需要导入模块: from spyne.server import ServerBase [as 别名]
# 或者: from spyne.server.ServerBase import get_out_string [as 别名]
def test_complex(self):
class CM(ComplexModel):
i = Integer
s = String
class CCM(ComplexModel):
c = CM
i = Integer
s = String
class SomeService(ServiceBase):
@srpc(CCM, _returns=CCM)
def some_call(ccm):
return CCM(c=ccm.c, i=ccm.i, s=ccm.s)
app = Application([SomeService], 'tns',
in_protocol=_DictObjectChild(),
out_protocol=_DictObjectChild())
server = ServerBase(app)
initial_ctx = MethodContext(server)
initial_ctx.in_string = [serializer.dumps({"some_call":{"ccm": {"c":{"i":3, "s": "3x"}, "i":4, "s": "4x"}}})]
ctx, = server.generate_contexts(initial_ctx)
server.get_in_object(ctx)
server.get_out_object(ctx)
server.get_out_string(ctx)
ret = serializer.loads(''.join(ctx.out_string))
print(ret)
assert ret['some_callResponse']['some_callResult']['i'] == 4
assert ret['some_callResponse']['some_callResult']['s'] == '4x'
assert ret['some_callResponse']['some_callResult']['c']['i'] == 3
assert ret['some_callResponse']['some_callResult']['c']['s'] == '3x'
示例8: test_multiple_return_sd_0
# 需要导入模块: from spyne.server import ServerBase [as 别名]
# 或者: from spyne.server.ServerBase import get_out_string [as 别名]
def test_multiple_return_sd_0(self):
class SomeService(ServiceBase):
@srpc(_returns=Iterable(Integer))
def some_call():
return 1, 2
app = Application([SomeService], 'tns', in_protocol=_DictObjectChild(), out_protocol=_DictObjectChild())
server = ServerBase(app)
initial_ctx = MethodContext(server)
initial_ctx.in_string = [serializer.dumps({"some_call":{}})]
ctx, = server.generate_contexts(initial_ctx)
server.get_in_object(ctx)
server.get_out_object(ctx)
server.get_out_string(ctx)
assert list(ctx.out_string) == [serializer.dumps({"some_callResponse": {"some_callResult": {"integer": [1, 2]}}})]
server = ServerBase(app)
initial_ctx = MethodContext(server)
initial_ctx.in_string = [serializer.dumps({"some_call":[]})]
ctx, = server.generate_contexts(initial_ctx)
server.get_in_object(ctx)
server.get_out_object(ctx)
server.get_out_string(ctx)
assert list(ctx.out_string) == [serializer.dumps({"some_callResponse": {"some_callResult": {"integer": [1, 2]}}})]
示例9: test_xml_data
# 需要导入模块: from spyne.server import ServerBase [as 别名]
# 或者: from spyne.server.ServerBase import get_out_string [as 别名]
def test_xml_data(self):
class C(ComplexModel):
a = XmlData(Unicode)
b = XmlAttribute(Unicode)
class SomeService(ServiceBase):
@srpc(C, _returns=C)
def some_call(c):
assert c.a == "a"
assert c.b == "b"
return c
app = Application(
[SomeService], "tns", name="test_xml_data", in_protocol=XmlDocument(), out_protocol=XmlDocument()
)
server = ServerBase(app)
initial_ctx = MethodContext(server, MethodContext.SERVER)
initial_ctx.in_string = [b'<some_call xmlns="tns">' b'<c b="b">a</c>' b"</some_call>"]
ctx, = server.generate_contexts(initial_ctx)
server.get_in_object(ctx)
server.get_out_object(ctx)
server.get_out_string(ctx)
print(ctx.out_string)
pprint(app.interface.nsmap)
ret = etree.fromstring(b"".join(ctx.out_string)).xpath(
"//tns:some_call" + RESULT_SUFFIX, namespaces=app.interface.nsmap
)[0]
print(etree.tostring(ret, pretty_print=True))
assert ret.text == "a"
assert ret.attrib["b"] == "b"
示例10: test_multiple_dict_complex_array
# 需要导入模块: from spyne.server import ServerBase [as 别名]
# 或者: from spyne.server.ServerBase import get_out_string [as 别名]
def test_multiple_dict_complex_array(self):
class CM(ComplexModel):
i = Integer
s = String
class CCM(ComplexModel):
c = CM
i = Integer
s = String
class ECM(CCM):
d = DateTime
class SomeService(ServiceBase):
@srpc(Iterable(ECM), _returns=Iterable(ECM))
def some_call(ecm):
return ecm
app = Application([SomeService], 'tns', in_protocol=_DictObjectChild(), out_protocol=_DictObjectChild())
server = ServerBase(app)
initial_ctx = MethodContext(server)
initial_ctx.in_string = [serializer.dumps(
{"some_call": {"ecm": [{
"c": {"i":3, "s": "3x"},
"i":4,
"s": "4x",
"d": "2011-12-13T14:15:16Z"
}]
}})]
ctx, = server.generate_contexts(initial_ctx)
server.get_in_object(ctx)
server.get_out_object(ctx)
print(ctx.in_object)
server.get_out_string(ctx)
ret = serializer.loads(''.join(ctx.out_string))
print(ret)
assert ret['some_callResponse']
assert ret['some_callResponse']['some_callResult']
assert ret['some_callResponse']['some_callResult']['ECM']
assert ret['some_callResponse']['some_callResult']['ECM'][0]
assert ret['some_callResponse']['some_callResult']['ECM'][0]["c"]
assert ret['some_callResponse']['some_callResult']['ECM'][0]["c"]["i"] == 3
assert ret['some_callResponse']['some_callResult']['ECM'][0]["c"]["s"] == "3x"
assert ret['some_callResponse']['some_callResult']['ECM'][0]["i"] == 4
assert ret['some_callResponse']['some_callResult']['ECM'][0]["s"] == "4x"
assert ret['some_callResponse']['some_callResult']['ECM'][0]["d"] == "2011-12-13T14:15:16+00:00"
示例11: test_multiple_dict_array
# 需要导入模块: from spyne.server import ServerBase [as 别名]
# 或者: from spyne.server.ServerBase import get_out_string [as 别名]
def test_multiple_dict_array(self):
class SomeService(ServiceBase):
@srpc(Iterable(String), _returns=Iterable(String))
def some_call(s):
return s
app = Application([SomeService], 'tns', JsonObject(), JsonObject(), Wsdl11())
server = ServerBase(app)
initial_ctx = MethodContext(server)
initial_ctx.in_string = ['{"some_call":{"s":["a","b"]}}']
ctx, = server.generate_contexts(initial_ctx)
server.get_in_object(ctx)
server.get_out_object(ctx)
server.get_out_string(ctx)
assert list(ctx.out_string) == ['{"some_callResponse": {"some_callResult": {"string": ["a", "b"]}}}']
示例12: _dry_me
# 需要导入模块: from spyne.server import ServerBase [as 别名]
# 或者: from spyne.server.ServerBase import get_out_string [as 别名]
def _dry_me(services, d, skip_depth=0, just_ctx=False,
just_in_object=False, validator=None):
app = Application(services, 'tns',
in_protocol=_DictDocumentChild(validator=validator),
out_protocol=_DictDocumentChild(skip_depth=skip_depth))
server = ServerBase(app)
initial_ctx = MethodContext(server)
initial_ctx.in_string = [serializer.dumps(d, **dumps_kwargs)]
ctx, = server.generate_contexts(initial_ctx)
if not just_ctx:
server.get_in_object(ctx)
if not just_in_object:
server.get_out_object(ctx)
server.get_out_string(ctx)
return ctx
示例13: test_fault_to_dict
# 需要导入模块: from spyne.server import ServerBase [as 别名]
# 或者: from spyne.server.ServerBase import get_out_string [as 别名]
def test_fault_to_dict(self):
class SomeService(ServiceBase):
@srpc(_returns=String)
def some_call():
raise Fault()
app = Application([SomeService], 'tns',
in_protocol=_DictObjectChild(),
out_protocol=_DictObjectChild(skip_depth=2))
server = ServerBase(app)
initial_ctx = MethodContext(server)
initial_ctx.in_string = serializer.dumps({"some_call":[]})
ctx, = server.generate_contexts(initial_ctx)
server.get_in_object(ctx)
server.get_out_object(ctx)
server.get_out_string(ctx)
示例14: test_attribute_of_multi
# 需要导入模块: from spyne.server import ServerBase [as 别名]
# 或者: from spyne.server.ServerBase import get_out_string [as 别名]
def test_attribute_of_multi(self):
class C(ComplexModel):
__namespace__ = 'tns'
e = Unicode(max_occurs='unbounded')
a = XmlAttribute(Unicode, attribute_of="e")
class SomeService(ServiceBase):
@srpc(C, _returns=C)
def some_call(c):
assert c.e == ['e0', 'e1']
assert c.a == ['a0', 'a1']
return c
app = Application([SomeService], "tns", name="test_attribute_of",
in_protocol=XmlDocument(), out_protocol=XmlDocument())
server = ServerBase(app)
initial_ctx = MethodContext(server)
initial_ctx.method_request_string = '{test_attribute_of}some_call'
initial_ctx.in_string = [
'<some_call xmlns="tns">'
'<c>'
'<e a="a0">e0</e>'
'<e a="a1">e1</e>'
'</c>'
'</some_call>'
]
ctx, = server.generate_contexts(initial_ctx)
server.get_in_object(ctx)
server.get_out_object(ctx)
server.get_out_string(ctx)
ret = etree.fromstring(''.join(ctx.out_string)).xpath('//tns:e',
namespaces=app.interface.nsmap)
print(etree.tostring(ret[0], pretty_print=True))
print(etree.tostring(ret[1], pretty_print=True))
assert ret[0].text == "e0"
assert ret[0].attrib['a'] == "a0"
assert ret[1].text == "e1"
assert ret[1].attrib['a'] == "a1"
示例15: test_primitive_with_skip_depth
# 需要导入模块: from spyne.server import ServerBase [as 别名]
# 或者: from spyne.server.ServerBase import get_out_string [as 别名]
def test_primitive_with_skip_depth(self):
class SomeService(ServiceBase):
@srpc(_returns=String)
def some_call():
return "foo"
app = Application([SomeService], 'tns',
in_protocol=_DictDocumentChild(),
out_protocol=_DictDocumentChild(skip_depth=2)
)
server = ServerBase(app)
initial_ctx = MethodContext(server)
initial_ctx.in_string = [serializer.dumps({"some_call":[]})]
ctx, = server.generate_contexts(initial_ctx)
server.get_in_object(ctx)
server.get_out_object(ctx)
server.get_out_string(ctx)