本文整理汇总了Python中rpclib.server.ServerBase类的典型用法代码示例。如果您正苦于以下问题:Python ServerBase类的具体用法?Python ServerBase怎么用?Python ServerBase使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ServerBase类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_basic
def test_basic(self):
class SomeService(ServiceBase):
@srpc(String(pattern='a'))
def some_method(s):
pass
application = Application([SomeService],
interface=Wsdl11(),
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>
"""]
server.get_in_object(ctx)
self.assertEquals(isinstance(ctx.in_error, ValidationError), True)
示例2: __init__
def __init__(self, app, app_url, wsdl_url=None):
ServerBase.__init__(self, app)
self.app_url = app_url
self.wsdl_url = wsdl_url
self.soap_socket = context.socket(zmq.REP)
self.soap_socket.bind(app_url)
示例3: __init__
def __init__(self, app):
ServerBase.__init__(self, app)
self._allowed_http_verbs = app.in_protocol.allowed_http_verbs
self._verb_handlers = {
"GET": self.handle_rpc,
"POST": self.handle_rpc,
}
示例4: __init__
def __init__(self, app):
ServerBase.__init__(self, app)
self._allowed_http_verbs = app.in_protocol.allowed_http_verbs
self._verb_handlers = {
"GET": self.handle_rpc,
"POST": self.handle_rpc,
}
self._mtx_build_interface_document = threading.Lock()
示例5: __get_ctx
def __get_ctx(self, mn, qs):
server = ServerBase(self.application)
ctx = WsgiMethodContext(server, {
'QUERY_STRING': qs,
'PATH_INFO': '/%s' % mn,
}, 'some-content-type')
server.get_in_object(ctx)
return ctx
示例6: __init__
def __init__(self, app, chunked=False,
max_content_length=2 * 1024 * 1024,
block_length=8 * 1024):
ServerBase.__init__(self, app)
self._allowed_http_verbs = app.in_protocol.allowed_http_verbs
self.chunked = chunked
self.max_content_length = max_content_length
self.block_length = block_length
示例7: __init__
def __init__(self, db, app, consumer_id):
ServerBase.__init__(self, app)
self.session = sessionmaker(bind=db)()
self.id = consumer_id
try:
self.session.query(WorkerStatus) \
.filter_by(worker_id=self.id).one()
except NoResultFound:
self.session.add(WorkerStatus(worker_id=self.id, task_id=0))
self.session.commit()
示例8: test_invalid_input
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'
示例9: test_multiple
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', Wsdl11(), HttpRpc(), HttpRpc())
from rpclib.server.wsgi import WsgiMethodContext
initial_ctx = WsgiMethodContext(app, {
'QUERY_STRING': 's=1&s=2',
'PATH_INFO': '/some_call',
'REQUEST_METHOD': 'GET',
}, 'some-content-type')
from rpclib.server import ServerBase
server = ServerBase(app)
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']
示例10: test_primitive_only
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', Wsdl11(), HttpRpc(), HttpRpc())
from rpclib.server.wsgi import WsgiMethodContext
initial_ctx = WsgiMethodContext(app, {
'QUERY_STRING': '',
'PATH_INFO': '/some_call',
}, 'some-content-type')
from rpclib.server import ServerBase
server = ServerBase(app)
ctx, = server.generate_contexts(initial_ctx)
server.get_in_object(ctx)
print "!", ctx.in_object
server.get_out_object(ctx)
try:
server.get_out_string(ctx)
except:
pass
else:
raise Exception("Must Fail")
示例11: test_multiple_return
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', Wsdl11(), HttpRpc(), HtmlMicroFormat())
from rpclib.server.wsgi import WsgiMethodContext
initial_ctx = WsgiMethodContext(app, {
'QUERY_STRING': '',
'PATH_INFO': '/some_call',
'REQUEST_METHOD': 'GET',
}, 'some-content-type')
from rpclib.server import ServerBase
server = ServerBase(app)
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>'
示例12: test_simple
def test_simple(self):
class SomeService(ServiceBase):
@srpc(String, _returns=String)
def some_call(s):
return s
app = Application([SomeService], 'tns', Wsdl11(), HttpRpc(), HtmlMicroFormat())
from rpclib.server.wsgi import WsgiMethodContext
initial_ctx = WsgiMethodContext(app, {
'QUERY_STRING': 's=s',
'PATH_INFO': '/some_call',
'REQUEST_METHOD': 'GET',
}, 'some-content-type')
from rpclib.server import ServerBase
server = ServerBase(app)
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>'
示例13: test_complex
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', JsonObject(), JsonObject(),
Wsdl11())
server = ServerBase(app)
initial_ctx = MethodContext(server)
initial_ctx.in_string = ['{"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 = json.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'
示例14: test_complex
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', Wsdl11(), HttpRpc(), HttpRpc())
from rpclib.server.wsgi import WsgiMethodContext
initial_ctx = WsgiMethodContext(app, {
'QUERY_STRING': '',
'PATH_INFO': '/some_call',
'REQUEST_METHOD': 'GET',
}, 'some-content-type')
from rpclib.server import ServerBase
server = ServerBase(app)
ctx, = server.generate_contexts(initial_ctx)
server.get_in_object(ctx)
server.get_out_object(ctx)
server.get_out_string(ctx)
示例15: test_multiple_return
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', Wsdl11(), HttpRpc(), HttpRpc())
from rpclib.server.wsgi import WsgiMethodContext
initial_ctx = WsgiMethodContext(app, {
'QUERY_STRING': '',
'PATH_INFO': '/some_call',
'QUERY_STRING': '?s=a',
'REQUEST_METHOD': 'GET',
}, 'some-content-type')
from rpclib.server import ServerBase
server = ServerBase(app)
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.")