本文整理汇总了Python中spyne.server.ServerBase.generate_contexts方法的典型用法代码示例。如果您正苦于以下问题:Python ServerBase.generate_contexts方法的具体用法?Python ServerBase.generate_contexts怎么用?Python ServerBase.generate_contexts使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类spyne.server.ServerBase
的用法示例。
在下文中一共展示了ServerBase.generate_contexts方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_multiple_return_sd_0
# 需要导入模块: from spyne.server import ServerBase [as 别名]
# 或者: from spyne.server.ServerBase import generate_contexts [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]}}})]
示例2: test_multiple_return_sd_0
# 需要导入模块: from spyne.server import ServerBase [as 别名]
# 或者: from spyne.server.ServerBase import generate_contexts [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: test_decimal
# 需要导入模块: from spyne.server import ServerBase [as 别名]
# 或者: from spyne.server.ServerBase import generate_contexts [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)
示例4: _dry_me
# 需要导入模块: from spyne.server import ServerBase [as 别名]
# 或者: from spyne.server.ServerBase import generate_contexts [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
示例5: test_basic
# 需要导入模块: from spyne.server import ServerBase [as 别名]
# 或者: from spyne.server.ServerBase import generate_contexts [as 别名]
def test_basic(self):
class SomeService(ServiceBase):
@srpc(String(pattern='a'))
def some_method(s):
pass
application = Application([SomeService],
in_protocol=Soap11(validator='soft'),
out_protocol=Soap11(),
name='Service', tns='tns',
)
server = ServerBase(application)
ctx = MethodContext(server)
ctx.in_string = [u"""
<SOAP-ENV:Envelope xmlns:ns0="tns"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Body>
<ns0:some_method>
<ns0:s>OK</ns0:s>
</ns0:some_method>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
"""]
ctx, = server.generate_contexts(ctx)
server.get_in_object(ctx)
self.assertEquals(isinstance(ctx.in_error, ValidationError), True)
示例6: test_soap_input_header_order_and_missing
# 需要导入模块: from spyne.server import ServerBase [as 别名]
# 或者: from spyne.server.ServerBase import generate_contexts [as 别名]
def test_soap_input_header_order_and_missing(self):
"""
Test that header ordering logic also works when an input header
element is missing. Confirm that it returns None for the missing
parameter.
"""
server = ServerBase(self.app)
initial_ctx = MethodContext(server)
initial_ctx.in_string = [
'<senv:Envelope xmlns:tns="tns"'
'xmlns:wsa="http://www.w3.org/2005/08/addressing"'
'xmlns:senv="http://schemas.xmlsoap.org/soap/envelope/">'
'<senv:Header>'
'<wsa:MessageID>SomeMessageID</wsa:MessageID>'
'<wsa:Action>/SomeAction</wsa:Action>'
'</senv:Header>'
'<senv:Body>'
'<tns:someRequest>'
'<tns:status>OK</tns:status>'
'</tns:someRequest>'
'</senv:Body>'
'</senv:Envelope>'
]
ctx, = server.generate_contexts(initial_ctx)
server.get_in_object(ctx)
self.assertEquals(ctx.in_header[0], '/SomeAction')
self.assertEquals(ctx.in_header[1], 'SomeMessageID')
self.assertEquals(ctx.in_header[2], None)
示例7: test_soap_input_header
# 需要导入模块: from spyne.server import ServerBase [as 别名]
# 或者: from spyne.server.ServerBase import generate_contexts [as 别名]
def test_soap_input_header(self):
server = ServerBase(self.app)
initial_ctx = MethodContext(server)
initial_ctx.in_string = [
'<senv:Envelope xmlns:tns="tns"'
'xmlns:wsa="http://www.w3.org/2005/08/addressing"'
'xmlns:senv="http://schemas.xmlsoap.org/soap/envelope/">'
'<senv:Header>'
'<wsa:Action>/SomeAction</wsa:Action>'
'<wsa:MessageID>SomeMessageID</wsa:MessageID>'
'<wsa:RelatesTo>SomeRelatesToID</wsa:RelatesTo>'
'</senv:Header>'
'<senv:Body>'
'<tns:someRequest>'
'<tns:status>OK</tns:status>'
'</tns:someRequest>'
'</senv:Body>'
'</senv:Envelope>'
]
ctx, = server.generate_contexts(initial_ctx)
server.get_in_object(ctx)
self.assertEquals(ctx.in_header[0], '/SomeAction')
self.assertEquals(ctx.in_header[1], 'SomeMessageID')
self.assertEquals(ctx.in_header[2], 'SomeRelatesToID')
示例8: test_soap_input_header_order
# 需要导入模块: from spyne.server import ServerBase [as 别名]
# 或者: from spyne.server.ServerBase import generate_contexts [as 别名]
def test_soap_input_header_order(self):
"""
Tests supports for input headers whose elements are provided in
different order than that defined in rpc declaration _in_header parameter.
"""
server = ServerBase(self.app)
initial_ctx = MethodContext(server)
initial_ctx.in_string = [
'<senv:Envelope xmlns:tns="tns"'
'xmlns:wsa="http://www.w3.org/2005/08/addressing"'
'xmlns:senv="http://schemas.xmlsoap.org/soap/envelope/">'
'<senv:Header>'
'<wsa:MessageID>SomeMessageID</wsa:MessageID>'
'<wsa:RelatesTo>SomeRelatesToID</wsa:RelatesTo>'
'<wsa:Action>/SomeAction</wsa:Action>'
'</senv:Header>'
'<senv:Body>'
'<tns:someRequest>'
'<tns:status>OK</tns:status>'
'</tns:someRequest>'
'</senv:Body>'
'</senv:Envelope>'
]
ctx, = server.generate_contexts(initial_ctx)
server.get_in_object(ctx)
self.assertEquals(ctx.in_header[0], '/SomeAction')
self.assertEquals(ctx.in_header[1], 'SomeMessageID')
self.assertEquals(ctx.in_header[2], 'SomeRelatesToID')
示例9: test_attribute_ns
# 需要导入模块: from spyne.server import ServerBase [as 别名]
# 或者: from spyne.server.ServerBase import generate_contexts [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"
示例10: test_complex
# 需要导入模块: from spyne.server import ServerBase [as 别名]
# 或者: from spyne.server.ServerBase import generate_contexts [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'
示例11: test_primitive_only
# 需要导入模块: from spyne.server import ServerBase [as 别名]
# 或者: from spyne.server.ServerBase import generate_contexts [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"}}})]
示例12: test_xml_data
# 需要导入模块: from spyne.server import ServerBase [as 别名]
# 或者: from spyne.server.ServerBase import generate_contexts [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"
示例13: deserialize_request_string
# 需要导入模块: from spyne.server import ServerBase [as 别名]
# 或者: from spyne.server.ServerBase import generate_contexts [as 别名]
def deserialize_request_string(string, app):
"""Deserialize request string using in_protocol in application definition.
Returns the corresponding native python object.
"""
server = ServerBase(app)
initial_ctx = MethodContext(server)
initial_ctx.in_string = [string]
ctx = server.generate_contexts(initial_ctx)[0]
server.get_in_object(ctx)
return ctx.in_object
示例14: test_invalid_input
# 需要导入模块: from spyne.server import ServerBase [as 别名]
# 或者: from spyne.server.ServerBase import generate_contexts [as 别名]
def test_invalid_input(self):
class SomeService(ServiceBase):
@srpc()
def yay():
pass
app = Application([SomeService], 'tns', JsonObject(), JsonObject(), Wsdl11())
server = ServerBase(app)
initial_ctx = MethodContext(server)
initial_ctx.in_string = ['{"some_call": {"yay": ]}}']
ctx, = server.generate_contexts(initial_ctx)
assert ctx.in_error.faultcode == 'Client.JsonDecodeError'
示例15: test_invalid_input
# 需要导入模块: from spyne.server import ServerBase [as 别名]
# 或者: from spyne.server.ServerBase import generate_contexts [as 别名]
def test_invalid_input(self):
class SomeService(ServiceBase):
@srpc()
def yay():
pass
app = Application([SomeService], "tns", in_protocol=JsonDocument(), out_protocol=JsonDocument())
server = ServerBase(app)
initial_ctx = MethodContext(server)
initial_ctx.in_string = ["{"]
ctx, = server.generate_contexts(initial_ctx)
assert ctx.in_error.faultcode == "Client.JsonDecodeError"