def main(): # start publisher process p = multiprocessing.Process(target=camera_publisher) p.start() stream_app = WsgiApplication( Application( [StreamingService], tns='spyne.examples.streaming', in_protocol=HttpRpc(), out_protocol=HttpRpc(mime_type='video/ogg'), )) root_app = DispatcherMiddleware(NotFound(), {'/stream': stream_app}) # get stream header from the publisher process socket = context.socket(zmq.REQ) socket.connect(header_socket) socket.send("hey") StreamingService.stream_header = socket.recv() socket.close() # have fun! run_simple('0.0.0.0', port, root_app, static_files={'/': "."}, threaded=True)
def test_http_headers(self): class RequestHeader(ComplexModel): _type_info = { 'Cookie': String(max_occurs='unbounded') } class ResponseHeader(ComplexModel): _type_info = { 'Set-Cookie': String(max_occurs='unbounded') } class SomeService(ServiceBase): __in_header__ = RequestHeader __out_header__ = ResponseHeader @rpc(String) def some_call(ctx, s): assert s is not None ctx.out_header = ResponseHeader(**{'Set-Cookie': s}) def start_response(code, headers): assert dict(headers)['Set-Cookie'] == 'hey' ret = ''.join(WsgiApplication(Application([SomeService], 'tns', in_protocol=HttpRpc(), out_protocol=HttpRpc()))({ 'QUERY_STRING': '&s=hey', 'PATH_INFO': '/some_call', 'REQUEST_METHOD': 'GET', 'SERVER_NAME': 'localhost', }, start_response, "http://null")) assert ret == ''
def test_simple_aux_wsgi(self): data = [] class SomeService(Service): @srpc(String, _returns=String) def call(s): data.append(s) class AuxService(Service): __aux__ = SyncAuxProc() @srpc(String, _returns=String) def call(s): data.append(s) app = Application([SomeService, AuxService], 'tns', in_protocol=HttpRpc(), out_protocol=HttpRpc()) server = WsgiApplication(app) server( { 'QUERY_STRING': 's=hey', 'PATH_INFO': '/call', 'REQUEST_METHOD': 'POST', 'CONTENT_TYPE': 'text/xml; charset=utf8', 'SERVER_NAME': 'localhost', 'wsgi.input': BytesIO(), }, start_response, "http://null") assert data == ['hey', 'hey']
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
def test_cookie_parse(self): string = 'some_string' class RequestHeader(ComplexModel): some_field = String class SomeService(ServiceBase): __in_header__ = RequestHeader @rpc(String) def some_call(ctx, s): assert ctx.in_header.some_field == string def start_response(code, headers): assert code == HTTP_200 c = SimpleCookie() c['some_field'] = string ''.join(wsgiref_validator(WsgiApplication(Application([SomeService], 'tns', in_protocol=HttpRpc(parse_cookie=True), out_protocol=HttpRpc())))({ 'SCRIPT_NAME': '', 'QUERY_STRING': '', 'PATH_INFO': '/some_call', 'REQUEST_METHOD': 'GET', 'SERVER_NAME': 'localhost', 'SERVER_PORT': "9999", 'HTTP_COOKIE': str(c), 'wsgi.url_scheme': 'http', 'wsgi.version': (1,0), 'wsgi.input': StringIO(), 'wsgi.errors': StringIO(), 'wsgi.multithread': False, 'wsgi.multiprocess': False, 'wsgi.run_once': True, }, start_response))
def test_thread_aux_wsgi(self): import logging logging.basicConfig(level=logging.DEBUG) data = set() class Service(ServiceBase): @srpc(String, _returns=String) def call(s): data.add(s) class AuxService(ServiceBase): __aux__ = ThreadAuxProc() @srpc(String, _returns=String) def call(s): data.add(s + "aux") app = Application([Service, AuxService], 'tns', in_protocol=HttpRpc(), out_protocol=HttpRpc()) server = WsgiApplication(app) server( { 'QUERY_STRING': 's=hey', 'PATH_INFO': '/call', 'REQUEST_METHOD': 'GET', 'SERVER_NAME': 'localhost', }, start_response, "http://null") import time time.sleep(1) assert data == set(['hey', 'heyaux'])
def test_simple_aux_wsgi(self): data = [] class Service(ServiceBase): @srpc(String, _returns=String) def call(s): data.append(s) class AuxService(ServiceBase): __aux__ = SyncAuxProc() @srpc(String, _returns=String) def call(s): data.append(s) app = Application([Service, AuxService], 'tns', in_protocol=HttpRpc(), out_protocol=HttpRpc()) server = WsgiApplication(app) server( { 'QUERY_STRING': 's=hey', 'PATH_INFO': '/call', 'REQUEST_METHOD': 'GET', 'SERVER_NAME': 'localhost', }, start_response, "http://null") assert data == ['hey', 'hey']
def initialize(services, tns='spyne.examples.twisted.resource'): logging.basicConfig(level=logging.DEBUG) logging.getLogger('spyne.protocol.xml').setLevel(logging.DEBUG) observer = log.PythonLoggingObserver('twisted') log.startLoggingWithObserver(observer.emit, setStdout=False) return Application(services, 'spyne.examples.twisted.hello', in_protocol=HttpRpc(), out_protocol=HttpRpc())
def test_http_headers(self): d = datetime(year=2013, month=1, day=1) string = ['hey', 'yo'] class ResponseHeader(ComplexModel): _type_info = { 'Set-Cookie': String(max_occurs='unbounded'), 'Expires': DateTime } class SomeService(ServiceBase): __out_header__ = ResponseHeader @rpc(String) def some_call(ctx, s): assert s is not None ctx.out_header = ResponseHeader(**{ 'Set-Cookie': string, 'Expires': d }) def start_response(code, headers): print(headers) assert len([s for s in string if ('Set-Cookie', s) in headers]) == len(string) assert dict(headers)['Expires'] == 'Tue, 01 Jan 2013 00:00:00 GMT' app = Application([SomeService], 'tns', in_protocol=HttpRpc(), out_protocol=HttpRpc()) wsgi_app = WsgiApplication(app) req_dict = { 'SCRIPT_NAME': '', 'QUERY_STRING': '&s=foo', 'PATH_INFO': '/some_call', 'REQUEST_METHOD': 'GET', 'SERVER_NAME': 'localhost', 'SERVER_PORT': "9999", 'wsgi.url_scheme': 'http', 'wsgi.version': (1, 0), 'wsgi.input': StringIO(), 'wsgi.errors': StringIO(), 'wsgi.multithread': False, 'wsgi.multiprocess': False, 'wsgi.run_once': True, } ret = wsgi_app(req_dict, start_response) print(list(ret)) wsgi_app = wsgiref_validator(wsgi_app) ret = wsgi_app(req_dict, start_response) assert list(ret) == [b'']
def start_a2bs(config): subconfig = config.services.getwrite( 'web', HttpListener( host='0.0.0.0', port=9271, disabled=False, _subapps=[ StaticFileServer(url='assets', path=abspath('assets'), list_contents=False) ], )) services = [ TestServices, CardReaderServices, CardWriterServices, SipBuddyReaderServices, SipBuddyWriterServices, ExtReaderServices, ExtWriterServices, ] subconfig.subapps['json'] = \ Application(services, tns='a2bs.web', name='A2BillingJson', in_protocol=HttpRpc(validator='soft'), out_protocol=JsonDocument(), config=config, ) subconfig.subapps['xml'] = \ Application(services, tns='a2bs.web', name='A2BillingXml', in_protocol=HttpRpc(validator='soft'), out_protocol=XmlDocument(), config=config, ) subconfig.subapps[''] = \ Application(services, tns='a2bs.web', name='A2BillingHtml', in_protocol=HttpRpc(validator='soft'), out_protocol=HtmlMicroFormat(), config=config, ) site = subconfig.gen_site() logger.info("listening for a2billing http endpoint %s:%d", subconfig.host, subconfig.port) return reactor.listenTCP(subconfig.port, site, interface=subconfig.host), None
def setUp(self): class SomeService(ServiceBase): @srpc(String, _returns=String) def echo_string(s): return s app = Application([SomeService], 'tns', in_protocol=HttpRpc(validator='soft'), out_protocol=HttpRpc(), ) self.app = WsgiApplication(app)
def test_http_headers(self): DATE = datetime(year=2013, month=1, day=1) STR = 'hey' class ResponseHeader(ComplexModel): _type_info = { 'Set-Cookie': String(max_occurs='unbounded'), 'Expires': DateTime } class SomeService(ServiceBase): __out_header__ = ResponseHeader @rpc(String) def some_call(ctx, s): assert s is not None ctx.out_header = ResponseHeader(**{ 'Set-Cookie': STR, 'Expires': DATE }) def start_response(code, headers): assert dict(headers)['Set-Cookie'] == STR assert dict(headers)['Expires'] == 'Tue, 01 Jan 2013 00:00:00 GMT' ret = ''.join( validator( WsgiApplication( Application( [SomeService], 'tns', in_protocol=HttpRpc(), out_protocol=HttpRpc())))({ 'SCRIPT_NAME': '', 'QUERY_STRING': '&s=' + STR, 'PATH_INFO': '/some_call', 'REQUEST_METHOD': 'GET', 'SERVER_NAME': 'localhost', 'SERVER_PORT': "9999", 'wsgi.url_scheme': 'http', 'wsgi.version': (1, 0), 'wsgi.input': StringIO(), 'wsgi.errors': StringIO(), 'wsgi.multithread': False, 'wsgi.multiprocess': False, 'wsgi.run_once': True, }, start_response)) assert ret == ''
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>'
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>'
def test_string_array_no_header(self): class SomeService(ServiceBase): @srpc(String(max_occurs='unbounded'), _returns=Array(String)) def some_call(s): return s app = Application([SomeService], 'tns', in_protocol=HttpRpc(), out_protocol=HtmlRowTable(header=False)) server = WsgiApplication(app) out_string = call_wsgi_app(server, body_pairs=(('s', '1'), ('s', '2'))) #FIXME: Needs a proper test with xpaths and all. show(html.fromstring(out_string), 'TestHtmlRowTable.test_string_array_no_header') assert out_string == \ '<div>' \ '<table class="some_callResponse">' \ '<tr>' \ '<td>' \ '<table>' \ '<tr>' \ '<td>1</td>' \ '</tr>' \ '<tr>' \ '<td>2</td>' \ '</tr>' \ '</table>' \ '</td>' \ '</tr>' \ '</table>' \ '</div>'
def test_column_href_string_with_substitution(self): _link = "http://arskom.com.tr/?spyne_test=%s" class C(ComplexModel): c = Unicode(pa={HtmlColumnTable: dict(href=_link)}) class SomeService(ServiceBase): @srpc(_returns=C) def some_call(): return C(c="hello") app = Application( [SomeService], 'tns', in_protocol=HttpRpc(), out_protocol=HtmlColumnTable(field_name_attr='class')) server = WsgiApplication(app) out_string = call_wsgi_app_kwargs(server) elt = html.fromstring(out_string) print(html.tostring(elt, pretty_print=True)) assert elt.xpath('//td[@class="c"]')[0][0].tag == 'a' assert elt.xpath( '//td[@class="c"]')[0][0].attrib['href'] == _link % "hello"
def create_http_application(self): app = HydraSoapApplication(applications, tns='hydra.base', in_protocol=HttpRpc(validator='soft'), out_protocol=JsonDocument()) return app
def test_string_array(self): class SomeService(ServiceBase): @srpc(String(max_occurs='unbounded'), _returns=Array(String)) def some_call(s): return s app = Application([SomeService], 'tns', in_protocol=HttpRpc(), out_protocol=HtmlRowTable()) server = WsgiApplication(app) out_string = call_wsgi_app(server, body_pairs=(('s', '1'), ('s', '2'))) show(html.fromstring(out_string), 'TestHtmlRowTable.test_string_array') assert out_string == \ '<div xmlns="http://www.w3.org/1999/xhtml">' \ '<table xmlns="http://www.w3.org/1999/xhtml" class="some_callResponse">' \ '<tr>' \ '<th>string</th>' \ '<td>' \ '<table>' \ '<tr>' \ '<td>1</td>' \ '</tr>' \ '<tr>' \ '<td>2</td>' \ '</tr>' \ '</table>' \ '</td>' \ '</tr>' \ '</table>' \ '</div>'
def test_string_array(self): class SomeService(ServiceBase): @srpc(String(max_occurs='unbounded'), _returns=Array(String)) def some_call(s): return s app = Application([SomeService], 'tns', in_protocol=HttpRpc(), out_protocol=HtmlRowTable(field_name_attr=None, field_type_name_attr=None)) server = WsgiApplication(app) out_string = call_wsgi_app(server, body_pairs=(('s', '1'), ('s', '2'))) show(html.fromstring(out_string), 'TestHtmlRowTable.test_string_array') assert out_string.decode('utf8') == \ '<div>' \ '<table class="some_callResponse">' \ '<tr>' \ '<th>string</th>' \ '<td>' \ '<table>' \ '<tr>' \ '<td>1</td>' \ '</tr>' \ '<tr>' \ '<td>2</td>' \ '</tr>' \ '</table>' \ '</td>' \ '</tr>' \ '</table>' \ '</div>'
def test_complex_array(self): class SomeService(ServiceBase): @srpc(CCM, _returns=Array(CCM)) def some_call(ccm): return [ccm] * 5 app = Application([SomeService], 'tns', in_protocol=HttpRpc(), out_protocol=HtmlTable(field_name_attr='class')) server = WsgiApplication(app) out_string = call_wsgi_app_kwargs( server, ccm_i='456', ccm_s='def', ccm_c_i='123', ccm_c_s='abc', ) elt = html.fromstring(out_string) print(html.tostring(elt, pretty_print=True)) resp = elt.find_class('some_callResponse') assert len(resp) == 1 for i in range(len(elt)): row = elt[i] if i == 0: # check for field names in table header cell = row.findall('th[@class="i"]') assert len(cell) == 1 assert cell[0].text == 'i' cell = row.findall('th[@class="c_i"]') assert len(cell) == 1 assert cell[0].text == 'c_i' cell = row.findall('th[@class="c_s"]') assert len(cell) == 1 assert cell[0].text == 'c_s' cell = row.findall('th[@class="s"]') assert len(cell) == 1 assert cell[0].text == 's' else: # check for field values in table body cell = row.findall('td[@class="i"]') assert len(cell) == 1 assert cell[0].text == '456' cell = row.findall('td[@class="c_i"]') assert len(cell) == 1 assert cell[0].text == '123' cell = row.findall('td[@class="c_s"]') assert len(cell) == 1 assert cell[0].text == 'abc' cell = row.findall('td[@class="s"]') assert len(cell) == 1 assert cell[0].text == 'def'
def test_complex_array(self): class CM(ComplexModel): i = Integer s = String class CCM(ComplexModel): c = CM i = Integer s = String class SomeService(ServiceBase): @srpc(CCM, _returns=Array(CCM)) def some_call(ccm): return [CCM(c=ccm.c, i=ccm.i, s=ccm.s)] * 2 app = Application([SomeService], 'tns', in_protocol=HttpRpc(hier_delim='_'), out_protocol=HtmlMicroFormat()) server = WsgiApplication(app) out_string = call_wsgi_app_kwargs(server, ccm_c_s='abc', ccm_c_i=123, ccm_i=456, ccm_s='def') # # Here's what this is supposed to return: # # <div class="some_callResponse"><div class="some_callResult"> # <div class="CCM"> # <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 class="CCM"> # <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></div> # print(out_string) elt = html.fromstring(''.join(out_string)) show(elt, "TestHtmlMicroFormat.test_complex_array") resp = elt.find_class('some_callResponse') assert len(resp) == 1 res = resp[0].find_class('some_callResult') assert len(res) == 1 assert len(res[0].find_class("CCM")) == 2
def run(self): # Instantiate the application by giving it: # * The list of services it should wrap, # * A namespace string. # * An input protocol. # * An output protocol. application = Application( [CryptoassetsRPCService], 'spyne.examples.hello.http', # The input protocol is set as HttpRpc to make our service easy to # call. Input validation via the 'soft' engine is enabled. (which is # actually the the only validation method for HttpRpc.) in_protocol=HttpRpc(validator='soft'), # The ignore_wrappers parameter to JsonDocument simplifies the reponse # dict by skipping outer response structures that are redundant when # the client knows what object to expect. out_protocol=JsonDocument(ignore_wrappers=True), ) # Now that we have our application, we must wrap it inside a transport. # In this case, we use Spyne's standard Wsgi wrapper. Spyne supports # popular Http wrappers like Twisted, Django, Pyramid, etc. as well as # a ZeroMQ (REQ/REP) wrapper. wsgi_application = WsgiApplication(application) # More daemon boilerplate self.server = make_server(self.ip, self.port, wsgi_application) logging.info("listening to http://127.0.0.1:8000") logging.info("wsdl is at: http://localhost:8000/?wsdl") self.server.serve_forever()
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>'
def test_anyuri_uri_value(self): _link = "http://arskom.com.tr/" _text = "Arskom" class C(ComplexModel): c = AnyUri class SomeService(ServiceBase): @srpc(_returns=C) def some_call(): return C(c=AnyUri.Value(_link, text=_text)) app = Application([SomeService], 'tns', in_protocol=HttpRpc(), out_protocol=HtmlTable(field_name_attr='class', fields_as='rows')) server = WsgiApplication(app) out_string = call_wsgi_app_kwargs(server) elt = html.fromstring(out_string) print(html.tostring(elt, pretty_print=True)) assert elt.xpath('//td[@class="c"]')[0][0].tag == 'a' assert elt.xpath('//td[@class="c"]')[0][0].text == _text assert elt.xpath('//td[@class="c"]')[0][0].attrib['href'] == _link
def start_core(config): subconfig = config.services['core'] if subconfig.subapps is None: subconfig.subapps = {} subconfig.subapps.update({ '': Application( [CoreReaderServices], tns='https://jmap.io/', name='CoreServices', in_protocol=HttpRpc(validator='soft'), out_protocol=JsonDocument(), config=config, ), 'api': Application( [ MailReaderServices, MailWriterServices, ], tns='https://jmap.io/', name='ApiServices', in_protocol=JsonDocument(validator='soft'), out_protocol=JsonDocument(), config=config, ) }) return subconfig.gen_site()
def create_jsonp_application(self): app = HydraSoapApplication(applications, tns='hydra.base', in_protocol=HttpRpc(validator='soft'), out_protocol=JsonP("hydra_cb")) return app
def test_before_first_root(self): class CM(ComplexModel): i = Integer s = String class CCM(ComplexModel): c = CM i = Integer s = String class SomeService(Service): @srpc(CCM, _returns=Array(CCM)) def some_call(ccm): return [CCM(c=ccm.c,i=ccm.i, s=ccm.s)] * 2 cb_called = [False] def _cb(ctx, cls, inst, parent, name, **kwargs): assert not cb_called[0] cb_called[0] = True app = Application([SomeService], 'tns', in_protocol=HttpRpc(hier_delim='_'), out_protocol=HtmlMicroFormat( doctype=None, before_first_root=_cb)) server = WsgiApplication(app) call_wsgi_app_kwargs(server, ccm_c_s='abc', ccm_c_i=123, ccm_i=456, ccm_s='def') assert cb_called[0]
def test_complex(self): class SomeService(ServiceBase): @srpc(CCM, _returns=CCM) def some_call(ccm): return ccm app = Application([SomeService], 'tns', in_protocol=HttpRpc(), out_protocol=HtmlTable(field_name_attr='class', fields_as='rows')) server = WsgiApplication(app) out_string = call_wsgi_app_kwargs(server, ccm_c_s='abc', ccm_c_i='123', ccm_i='456', ccm_s='def') elt = html.fromstring(out_string) print(html.tostring(elt, pretty_print=True)) # Here's what this is supposed to return """ <table class="some_callResponse"> <tr> <th class="i">i</th> <td class="i">456</td> </tr> <tr> <th class="c_i">c_i</th> <td class="c_i">123</td> </tr> <tr> <th class="c_s">c_s</th> <td class="c_s">abc</td> </tr> <tr> <th class="s">s</th> <td class="s">def</td> </tr> </table> """ resp = elt.find_class('some_callResponse') assert len(resp) == 1 assert elt.xpath('//th[@class="i"]/text()')[0] == 'i' assert elt.xpath('//td[@class="i"]/text()')[0] == '456' assert elt.xpath('//th[@class="c_i"]/text()')[0] == 'c_i' assert elt.xpath('//td[@class="c_i"]/text()')[0] == '123' assert elt.xpath('//th[@class="c_s"]/text()')[0] == 'c_s' assert elt.xpath('//td[@class="c_s"]/text()')[0] == 'abc' assert elt.xpath('//th[@class="s"]/text()')[0] == 's' assert elt.xpath('//td[@class="s"]/text()')[0] == 'def'
def test_imports(self): import logging logging.basicConfig(level=logging.DEBUG) class KeyValuePair(ComplexModel): __namespace__ = "1" key = Unicode value = Unicode class Something(ComplexModel): __namespace__ = "2" d = DateTime i = Integer class SomethingElse(ComplexModel): __namespace__ = "3" a = AnyXml b = UnsignedLong s = Something class BetterSomething(Something): __namespace__ = "4" k = UnsignedInteger16 class Service1(ServiceBase): @rpc(SomethingElse, _returns=Array(KeyValuePair)) def some_call(ctx, sth): pass class Service2(ServiceBase): @rpc(BetterSomething, _returns=Array(KeyValuePair)) def some_other_call(ctx, sth): pass application = Application([Service1, Service2], in_protocol=HttpRpc(), out_protocol=Soap11(), name='Service', tns='target_namespace') imports = application.interface.imports tns = application.interface.get_tns() smm = application.interface.service_method_map print(imports) assert imports[tns] == set(['1', '3', '4']) assert imports['3'] == set(['2']) assert imports['4'] == set(['2']) assert smm['{%s}some_call' % tns] assert smm['{%s}some_call' % tns][0][0] == Service1 assert smm['{%s}some_call' % tns][0][1].function == Service1.some_call assert smm['{%s}some_other_call' % tns] assert smm['{%s}some_other_call' % tns][0][0] == Service2 assert smm['{%s}some_other_call' % tns][0][1].function == Service2.some_other_call
def geometry_service(fcgi=True): if fcgi is False: def _on_method_return_object(ctx): ctx.transport.resp_headers['Access-Control-Allow-Origin'] = "*" ctx.transport.resp_headers['Cache-Control'] = "public,max-age=86400" # tbd GeometryService.event_manager.add_listener('method_return_object', _on_method_return_object) json = Application([GeometryService], tns='swhv.service.geometry.json', in_protocol=HttpRpc(validator='soft'), out_protocol=JsonDocument()) msgpack = Application([GeometryService], tns='swhv.service.geometry.msgpack', in_protocol=HttpRpc(validator='soft'), out_protocol=MessagePackDocument()) return WsgiMounter({'json': json, 'msgpack': msgpack})