本文整理汇总了Python中spyne.server.wsgi.WsgiApplication.get_out_object方法的典型用法代码示例。如果您正苦于以下问题:Python WsgiApplication.get_out_object方法的具体用法?Python WsgiApplication.get_out_object怎么用?Python WsgiApplication.get_out_object使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类spyne.server.wsgi.WsgiApplication
的用法示例。
在下文中一共展示了WsgiApplication.get_out_object方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_multiple_return
# 需要导入模块: from spyne.server.wsgi import WsgiApplication [as 别名]
# 或者: from spyne.server.wsgi.WsgiApplication import get_out_object [as 别名]
def test_multiple_return(self):
class SomeNotSoComplexModel(ComplexModel):
s = String
class SomeService(ServiceBase):
@srpc(_returns=[Integer, String])
def some_call():
return 1, 's'
app = Application([SomeService], 'tns', in_protocol=HttpRpc(), out_protocol=HtmlMicroFormat())
server = WsgiApplication(app)
initial_ctx = WsgiMethodContext(server, {
'QUERY_STRING': '',
'PATH_INFO': '/some_call',
'REQUEST_METHOD': 'GET',
'SERVER_NAME': 'localhost',
}, 'some-content-type')
ctx, = server.generate_contexts(initial_ctx)
server.get_in_object(ctx)
server.get_out_object(ctx)
server.get_out_string(ctx)
assert ''.join(ctx.out_string) == '<div class="some_callResponse"><div class="some_callResult0">1</div><div class="some_callResult1">s</div></div>'
示例2: test_multiple
# 需要导入模块: from spyne.server.wsgi import WsgiApplication [as 别名]
# 或者: from spyne.server.wsgi.WsgiApplication import get_out_object [as 别名]
def test_multiple(self):
class SomeService(ServiceBase):
@srpc(String(max_occurs='unbounded'), _returns=String)
def some_call(s):
return '\n'.join(s)
app = Application([SomeService], 'tns', HttpRpc(), HtmlMicroFormat(), Wsdl11())
server = WsgiApplication(app)
initial_ctx = WsgiMethodContext(server, {
'QUERY_STRING': 's=1&s=2',
'PATH_INFO': '/some_call',
'REQUEST_METHOD': 'GET',
}, 'some-content-type')
ctx, = server.generate_contexts(initial_ctx)
server.get_in_object(ctx)
server.get_out_object(ctx)
server.get_out_string(ctx)
assert ''.join(ctx.out_string) == '<div class="some_callResponse"><div class="some_callResult">1\n2</div></div>'
ctx, = server.generate_contexts(initial_ctx)
server.get_in_object(ctx)
server.get_out_object(ctx)
server.get_out_string(ctx)
assert ''.join(ctx.out_string) == '<div class="some_callResponse"><div class="some_callResult">1\n2</div></div>'
示例3: test_simple
# 需要导入模块: from spyne.server.wsgi import WsgiApplication [as 别名]
# 或者: from spyne.server.wsgi.WsgiApplication import get_out_object [as 别名]
def test_simple(self):
class SomeService(ServiceBase):
@srpc(String, _returns=String)
def some_call(s):
return s
app = Application([SomeService], 'tns',
in_protocol=HttpRpc(hier_delim='_'),
out_protocol=HtmlMicroFormat())
server = WsgiApplication(app)
initial_ctx = WsgiMethodContext(server, {
'QUERY_STRING': 's=s',
'PATH_INFO': '/some_call',
'REQUEST_METHOD': 'GET',
'SERVER_NAME': 'localhost',
}, 'some-content-type')
ctx, = server.generate_contexts(initial_ctx)
assert ctx.in_error is None
server.get_in_object(ctx)
server.get_out_object(ctx)
server.get_out_string(ctx)
assert ''.join(ctx.out_string) == '<div class="some_callResponse"><div class="some_callResult">s</div></div>'
示例4: _test
# 需要导入模块: from spyne.server.wsgi import WsgiApplication [as 别名]
# 或者: from spyne.server.wsgi.WsgiApplication import get_out_object [as 别名]
def _test(services, qs, validator='soft'):
app = Application(services, 'tns', in_protocol=HttpRpc(validator=validator),
out_protocol=HttpRpc())
server = WsgiApplication(app)
initial_ctx = WsgiMethodContext(server, {
'QUERY_STRING': qs,
'PATH_INFO': '/some_call',
'REQUEST_METHOD': 'GET',
'SERVER_NAME': "localhost",
}, 'some-content-type')
ctx, = server.generate_contexts(initial_ctx)
server.get_in_object(ctx)
if ctx.in_error is not None:
raise ctx.in_error
server.get_out_object(ctx)
if ctx.out_error is not None:
raise ctx.out_error
server.get_out_string(ctx)
return ctx
示例5: _test
# 需要导入模块: from spyne.server.wsgi import WsgiApplication [as 别名]
# 或者: from spyne.server.wsgi.WsgiApplication import get_out_object [as 别名]
def _test(services, qs, validator="soft", strict_arrays=False):
app = Application(
services, "tns", in_protocol=HttpRpc(validator=validator, strict_arrays=strict_arrays), out_protocol=HttpRpc()
)
server = WsgiApplication(app)
initial_ctx = WsgiMethodContext(
server,
{"QUERY_STRING": qs, "PATH_INFO": "/some_call", "REQUEST_METHOD": "GET", "SERVER_NAME": "localhost"},
"some-content-type",
)
ctx, = server.generate_contexts(initial_ctx)
server.get_in_object(ctx)
if ctx.in_error is not None:
raise ctx.in_error
server.get_out_object(ctx)
if ctx.out_error is not None:
raise ctx.out_error
server.get_out_string(ctx)
return ctx
示例6: test_multiple
# 需要导入模块: from spyne.server.wsgi import WsgiApplication [as 别名]
# 或者: from spyne.server.wsgi.WsgiApplication import get_out_object [as 别名]
def test_multiple(self):
class SomeService(ServiceBase):
@srpc(String(max_occurs='unbounded'), _returns=String)
def some_call(s):
print(s)
return '\n'.join(s)
app = Application([SomeService], 'tns',
in_protocol=HttpRpc(hier_delim='_'),
out_protocol=HtmlMicroFormat())
server = WsgiApplication(app)
initial_ctx = WsgiMethodContext(server, {
'QUERY_STRING': 's=1&s=2',
'PATH_INFO': '/some_call',
'REQUEST_METHOD': 'GET',
'SERVER_NAME': 'localhost',
}, 'some-content-type')
ctx, = server.generate_contexts(initial_ctx)
server.get_in_object(ctx)
server.get_out_object(ctx)
server.get_out_string(ctx)
assert b''.join(ctx.out_string) == (b'<div class="some_callResponse">'
b'<div class="some_callResult">1\n2</div></div>')
ctx, = server.generate_contexts(initial_ctx)
server.get_in_object(ctx)
server.get_out_object(ctx)
server.get_out_string(ctx)
assert b''.join(ctx.out_string) == b'<div class="some_callResponse">' \
b'<div class="some_callResult">1\n2</div></div>'
示例7: test_complex
# 需要导入模块: from spyne.server.wsgi import WsgiApplication [as 别名]
# 或者: from spyne.server.wsgi.WsgiApplication import get_out_object [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=HttpRpc(), out_protocol=HttpRpc())
server = WsgiApplication(app)
initial_ctx = WsgiMethodContext(server, {
'QUERY_STRING': '',
'PATH_INFO': '/some_call',
'REQUEST_METHOD': 'GET',
}, 'some-content-type')
ctx, = server.generate_contexts(initial_ctx)
server.get_in_object(ctx)
server.get_out_object(ctx)
server.get_out_string(ctx)
示例8: test_primitive_only
# 需要导入模块: from spyne.server.wsgi import WsgiApplication [as 别名]
# 或者: from spyne.server.wsgi.WsgiApplication import get_out_object [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=HttpRpc(), out_protocol=HttpRpc())
server = WsgiApplication(app)
initial_ctx = WsgiMethodContext(server, {
'QUERY_STRING': '',
'PATH_INFO': '/some_call',
'REQUEST_METHOD': 'GET',
}, 'some-content-type')
ctx, = server.generate_contexts(initial_ctx)
server.get_in_object(ctx)
server.get_out_object(ctx)
try:
server.get_out_string(ctx)
except:
pass
else:
raise Exception("Must fail with: HttpRpc does not support complex "
"return types.")
示例9: test_multiple_return
# 需要导入模块: from spyne.server.wsgi import WsgiApplication [as 别名]
# 或者: from spyne.server.wsgi.WsgiApplication import get_out_object [as 别名]
def test_multiple_return(self):
class SomeNotSoComplexModel(ComplexModel):
s = String
class SomeService(ServiceBase):
@srpc(_returns=[Integer, String])
def some_call():
return 1, 's'
app = Application([SomeService], 'tns', in_protocol=HttpRpc(), out_protocol=HttpRpc())
server = WsgiApplication(app)
initial_ctx = WsgiMethodContext(server, {
'QUERY_STRING': '',
'PATH_INFO': '/some_call',
'QUERY_STRING': '?s=a',
'REQUEST_METHOD': 'GET',
}, 'some-content-type')
try:
ctx, = server.generate_contexts(initial_ctx)
server.get_in_object(ctx)
server.get_out_object(ctx)
server.get_out_string(ctx)
except ValueError:
pass
else:
raise Exception("Must fail with: HttpRpc does not support complex "
"return types.")
示例10: test_multiple
# 需要导入模块: from spyne.server.wsgi import WsgiApplication [as 别名]
# 或者: from spyne.server.wsgi.WsgiApplication import get_out_object [as 别名]
def test_multiple(self):
class SomeService(ServiceBase):
@srpc(String(max_occurs='unbounded'), _returns=String)
def some_call(s):
return '\n'.join(s)
app = Application([SomeService], 'tns', in_protocol=HttpRpc(), out_protocol=HttpRpc())
server = WsgiApplication(app)
initial_ctx = WsgiMethodContext(server, {
'QUERY_STRING': 's=1&s=2',
'PATH_INFO': '/some_call',
'REQUEST_METHOD': 'GET',
}, 'some-content-type')
ctx, = server.generate_contexts(initial_ctx)
server.get_in_object(ctx)
server.get_out_object(ctx)
server.get_out_string(ctx)
assert ctx.out_string == ['1\n2']
示例11: test_rules
# 需要导入模块: from spyne.server.wsgi import WsgiApplication [as 别名]
# 或者: from spyne.server.wsgi.WsgiApplication import get_out_object [as 别名]
def test_rules(self):
_int = 5
_fragment = 'some_fragment'
class SomeService(ServiceBase):
@srpc(Integer, _returns=Integer, _patterns=[
HttpPattern('/%s/<some_int>'% _fragment)])
def some_call(some_int):
assert some_int == _int
app = Application([SomeService], 'tns', in_protocol=HttpRpc(), out_protocol=HttpRpc())
server = WsgiApplication(app)
environ = {
'QUERY_STRING': '',
'PATH_INFO': '/%s/%d' % (_fragment, _int),
'SERVER_PATH':"/",
'SERVER_NAME': "localhost",
'wsgi.url_scheme': 'http',
'SERVER_PORT': '9000',
'REQUEST_METHOD': 'GET',
}
initial_ctx = WsgiMethodContext(server, environ, 'some-content-type')
ctx, = server.generate_contexts(initial_ctx)
foo = []
for i in server._http_patterns.iter_rules():
foo.append(i)
assert len(foo) == 1
print foo
assert ctx.descriptor is not None
server.get_in_object(ctx)
assert ctx.in_error is None
server.get_out_object(ctx)
assert ctx.out_error is None
示例12: test_rules
# 需要导入模块: from spyne.server.wsgi import WsgiApplication [as 别名]
# 或者: from spyne.server.wsgi.WsgiApplication import get_out_object [as 别名]
def test_rules(self):
_int = 5
_fragment = "some_fragment"
class SomeService(ServiceBase):
@srpc(Integer, _returns=Integer, _patterns=[HttpPattern("/%s/<some_int>" % _fragment)])
def some_call(some_int):
assert some_int == _int
app = Application([SomeService], "tns", in_protocol=HttpRpc(), out_protocol=HttpRpc())
server = WsgiApplication(app)
environ = {
"QUERY_STRING": "",
"PATH_INFO": "/%s/%d" % (_fragment, _int),
"SERVER_PATH": "/",
"SERVER_NAME": "localhost",
"wsgi.url_scheme": "http",
"SERVER_PORT": "9000",
"REQUEST_METHOD": "GET",
}
initial_ctx = WsgiMethodContext(server, environ, "some-content-type")
ctx, = server.generate_contexts(initial_ctx)
foo = []
for i in server._http_patterns:
foo.append(i)
assert len(foo) == 1
print(foo)
assert ctx.descriptor is not None
server.get_in_object(ctx)
assert ctx.in_error is None
server.get_out_object(ctx)
assert ctx.out_error is None
示例13: test_nested_flatten
# 需要导入模块: from spyne.server.wsgi import WsgiApplication [as 别名]
# 或者: from spyne.server.wsgi.WsgiApplication import get_out_object [as 别名]
def test_nested_flatten(self):
class CM(ComplexModel):
i = Integer
s = String
class CCM(ComplexModel):
c = CM
i = Integer
s = String
class SomeService(ServiceBase):
@srpc(CCM, _returns=String)
def some_call(ccm):
return repr(ccm)
app = Application([SomeService], 'tns', in_protocol=HttpRpc(), out_protocol=HttpRpc())
server = WsgiApplication(app)
initial_ctx = WsgiMethodContext(server, {
'QUERY_STRING': 'ccm_i=1&ccm_s=s&ccm_c_i=3&ccm_c_s=cs',
'PATH_INFO': '/some_call',
'REQUEST_METHOD': 'GET',
'SERVER_NAME': "localhost",
}, 'some-content-type')
ctx, = server.generate_contexts(initial_ctx)
server.get_in_object(ctx)
assert ctx.in_error is None
server.get_out_object(ctx)
assert ctx.out_error is None
server.get_out_string(ctx)
print(ctx.out_string)
assert ctx.out_string == ["CCM(i=1, c=CM(i=3, s='cs'), s='s')"]
示例14: test_complex
# 需要导入模块: from spyne.server.wsgi import WsgiApplication [as 别名]
# 或者: from spyne.server.wsgi.WsgiApplication import get_out_object [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=HttpRpc(hier_delim='_'),
out_protocol=HtmlMicroFormat())
server = WsgiApplication(app)
initial_ctx = WsgiMethodContext(server, {
'QUERY_STRING': 'ccm_c_s=abc&ccm_c_i=123&ccm_i=456&ccm_s=def',
'PATH_INFO': '/some_call',
'REQUEST_METHOD': 'GET',
'SERVER_NAME': 'localhost',
}, 'some-content-type')
ctx, = server.generate_contexts(initial_ctx)
server.get_in_object(ctx)
server.get_out_object(ctx)
server.get_out_string(ctx)
#
# Here's what this is supposed to return:
#
# <div class="some_callResponse">
# <div class="some_callResult">
# <div class="i">456</div>
# <div class="c">
# <div class="i">123</div>
# <div class="s">abc</div>
# </div>
# <div class="s">def</div>
# </div>
# </div>
#
elt = html.fromstring(''.join(ctx.out_string))
print(html.tostring(elt, pretty_print=True))
resp = elt.find_class('some_callResponse')
assert len(resp) == 1
res = resp[0].find_class('some_callResult')
assert len(res) == 1
i = res[0].findall('div[@class="i"]')
assert len(i) == 1
assert i[0].text == '456'
c = res[0].findall('div[@class="c"]')
assert len(c) == 1
c_i = c[0].findall('div[@class="i"]')
assert len(c_i) == 1
assert c_i[0].text == '123'
c_s = c[0].findall('div[@class="s"]')
assert len(c_s) == 1
assert c_s[0].text == 'abc'
s = res[0].findall('div[@class="s"]')
assert len(s) == 1
assert s[0].text == 'def'
示例15: test_rpc
# 需要导入模块: from spyne.server.wsgi import WsgiApplication [as 别名]
# 或者: from spyne.server.wsgi.WsgiApplication import get_out_object [as 别名]
def test_rpc(self):
import sqlalchemy
from sqlalchemy import sql
class KeyValuePair(TableModel, self.DeclarativeBase):
__tablename__ = 'key_value_store'
__namespace__ = 'punk'
key = Column(sqlalchemy.String(100), nullable=False, primary_key=True)
value = Column(sqlalchemy.String, nullable=False)
self.metadata.create_all(self.engine)
import hashlib
session = self.Session()
for i in range(1, 10):
key = str(i)
m = hashlib.md5()
m.update(key)
value = m.hexdigest()
session.add(KeyValuePair(key=key, value=value))
session.commit()
from spyne.service import ServiceBase
from spyne.model.complex import Array
from spyne.model.primitive import String
class Service(ServiceBase):
@rpc(String(max_occurs='unbounded'),
_returns=Array(KeyValuePair),
_in_variable_names={
'keys': 'key'
}
)
def get_values(ctx, keys):
session = self.Session()
return session.query(KeyValuePair).filter(sql.and_(
KeyValuePair.key.in_(keys)
)).order_by(KeyValuePair.key)
application = Application([Service],
in_protocol=HttpRpc(),
out_protocol=Soap11(),
name='Service', tns='tns'
)
server = WsgiApplication(application)
initial_ctx = WsgiMethodContext(server, {
'REQUEST_METHOD': 'GET',
'QUERY_STRING': 'key=1&key=2&key=3',
'PATH_INFO': '/get_values',
'SERVER_NAME': 'localhost',
}, 'some-content-type')
ctx, = server.generate_contexts(initial_ctx)
server.get_in_object(ctx)
server.get_out_object(ctx)
server.get_out_string(ctx)
i = 0
for e in ctx.out_document[0][0][0]:
i+=1
key = str(i)
m = hashlib.md5()
m.update(key)
value = m.hexdigest()
_key = e.find('{%s}key' % KeyValuePair.get_namespace())
_value = e.find('{%s}value' % KeyValuePair.get_namespace())
print((_key, _key.text))
print((_value, _value.text))
self.assertEquals(_key.text, key)
self.assertEquals(_value.text, value)