def test_multilevel_customized_simple_type(self): class ExampleService(ServiceBase): __tns__ = 'http://xml.company.com/ns/example/' @rpc(M(Uuid), _returns=Unicode) def say_my_uuid(ctx, uuid): return 'Your UUID: %s' % uuid Application([ExampleService], tns='kickass.ns', in_protocol=Soap11(validator='lxml'), out_protocol=Soap11())
def test_out_kwargs(self): class SomeService(ServiceBase): @srpc() def yay(): pass app = Application([SomeService], 'tns', in_protocol=JsonDocument(), out_protocol=JsonDocument()) assert 'cls' in app.out_protocol.kwargs assert not ('cls' in app.in_protocol.kwargs) app = Application([SomeService], 'tns', in_protocol=JsonDocument(), out_protocol=JsonDocument(cls='hey')) assert app.out_protocol.kwargs['cls'] == 'hey' assert not ('cls' in app.in_protocol.kwargs)
def create_app(flask_app): """Creates SOAP services application and distribute Flask config into user con defined context for each method call. """ application = Application([HelloWorldService], 'spyne.examples.flask', in_protocol=Soap11(validator='lxml'), out_protocol=Soap11() # out_protocol=Soap11(), ) return application
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) application = Application(services, 'order', in_protocol=Soap11(validator='lxml'), out_protocol=Soap11()) return application
def main(): logging.basicConfig(level=logging.DEBUG) logging.getLogger('spyne.protocol.xml').setLevel(logging.DEBUG) services = (SomeService, SomeAuxService) application = Application(services, 'spyne.examples.auxproc', in_protocol=HttpRpc(), out_protocol=XmlDocument()) server = make_server(host, port, WsgiApplication(application)) logging.info("listening to http://%s:%d" % (host, port)) return server.serve_forever()
def _test_type(cls, inst): class SomeService(ServiceBase): @rpc(_returns=cls, _body_style='bare') def some_call(ctx): return inst app = Application([SomeService], 'some_ns', out_protocol=HtmlFormTable()) null = NullServer(app, ostr=True) elt = etree.fromstring(''.join(null.service.some_call())) print(etree.tostring(elt, pretty_print=True)) return elt
def test_invalid_input(self): class SomeService(ServiceBase): pass app = Application([SomeService], 'tns', in_protocol=JsonDocument(), out_protocol=JsonDocument()) server = ServerBase(app) initial_ctx = MethodContext(server, MethodContext.SERVER) initial_ctx.in_string = [b'{'] ctx, = server.generate_contexts(initial_ctx, in_string_charset='utf8') assert ctx.in_error.faultcode == 'Client.JsonDecodeError'
def webserverFun(): soap_app = Application([IMonitorWebServices], 'IMonitorServices', in_protocol=Soap11(validator="lxml"), out_protocol=Soap11()) wsgi_app = WsgiApplication(soap_app) # svr = simple_server.make_server(ip,port,wsgi_app) svr = mt_wsgi((ip, port), simple_server.WSGIRequestHandler) svr.set_app(wsgi_app) try: svr.serve_forever() finally: svr.server_close()
def __publish(self, soap_type): app = Application(self.__services, self.__tns, self.__name, soap_type(validator="lxml"), soap_type()) if self.__event_handler_dict is not None: for key, value in self.__event_handler_dict.items(): app.event_manager.add_listener(key, value) wsgi_app = WsgiApplication(app) server = make_server(self.__host, self.__port, wsgi_app) self.__server = server self.__thread = _PublishThread(server) self.__thread.start() print("Service, %s, published at %s." % (self.__name, time.strftime(self.__time_format)), file=self.__log_target)
def get_spyne_app(discover_request_hanlder, execute_request_hanlder): """ :return: spyne Application """ return Application( [XmlaProviderService], "urn:schemas-microsoft-com:xml-analysis", in_protocol=XmlaSoap11(validator="soft"), out_protocol=XmlaSoap11(validator="soft"), config={ "discover_request_hanlder": discover_request_hanlder, "execute_request_hanlder": execute_request_hanlder, }, )
def create_app(flask_app): application = Application( [ShippingService], tns='shipping', in_protocol=Soap11(validator='lxml'), out_protocol=Soap11(), ) def _flask_config_context(ctx): ctx.udc = UserDefinedContext(flask_app.config) application.event_manager.add_listener('method_call', _flask_config_context) return application
def test_custom_primitive_in_array(self): RequestStatus = Unicode(values=['new', 'processed'], zonta='bonta') class DataRequest(ComplexModel): status = Array(RequestStatus) class HelloWorldService(ServiceBase): @rpc(DataRequest) def some_call(ctx, dgrntcl): pass Application([HelloWorldService], 'spyne.examples.hello.soap', in_protocol=Soap11(validator='lxml'), out_protocol=Soap11())
def test_canonical_case(self): class TestSelfReference(ComplexModel): self_reference = SelfReference c = TestSelfReference._type_info['self_reference'] c = c.__orig__ or c assert c is TestSelfReference class SoapService(ServiceBase): @rpc(_returns=TestSelfReference) def view_categories(ctx): pass Application([SoapService], 'service.soap')
def test_inherited_attribute(self): class DeviceEntity(ComplexModel): token = XmlAttribute(Unicode, use='required') class DigitalInput(DeviceEntity): IdleState = XmlAttribute(Unicode) class Service(ServiceBase): @rpc(_returns=DigitalInput, _body_style='bare') def GetDigitalInput(ctx): return DigitalInput() Application([Service], 'some_tns', in_protocol=Soap11(validator='lxml'), out_protocol=Soap11())
def soap(flask_app): application = Application( [Soap], tns=flask_app.config.get('NAMESPACE'), name='getPersonInfoPy', in_protocol=Soap11(validator='lxml'), out_protocol=Soap11() ) def _flask_conf_context(ctx): ctx.udc = UserDefinedContext(flask_app) application.event_manager.add_listener('method_call', _flask_conf_context) return application
def test_canonical_case(self): class TestSelfReference(ComplexModel): self_reference = SelfReference assert (TestSelfReference._type_info['self_reference'] is TestSelfReference) class SoapService(ServiceBase): @rpc(_returns=TestSelfReference) def view_categories(ctx): pass Application([SoapService], 'service.soap', in_protocol=ProtocolBase(), out_protocol=ProtocolBase())
def conn(): print("spawning server") application = Application([XmlaProviderService], 'urn:schemas-microsoft-com:xml-analysis', in_protocol=Soap11(validator='soft'), out_protocol=Soap11(validator='soft')) wsgi_application = WsgiApplication(application) server = WSGIServer(application=wsgi_application, host=HOST, port=PORT) server.start() provider = xmla.XMLAProvider() conn = provider.connect(location=server.url) yield conn print("stopping server") server.stop()
def rest_get(flask_app): Sget = Application( [DictWage], tns=flask_app.config.get('NAMESPACE'), name='DictWage', in_protocol=HttpRpc(validator='soft'), out_protocol=JsonDocument(), ) def _flask_config_context(ctx): ctx.udc = UserDefinedContext(flask_app) Sget.event_manager.add_listener( 'method_call', _flask_config_context ) return Sget
def soap_get(flask_app): Sget = Application( [DictWage], tns=flask_app.config.get('NAMESPACE'), name='DictWage', in_protocol=Soap11(validator='lxml'), out_protocol=Soap11(), ) def _flask_config_context(ctx): ctx.udc = UserDefinedContext(flask_app) Sget.event_manager.add_listener( 'method_call', _flask_config_context ) return Sget
def main(): # You can use any Wsgi server. Here, we chose # Python's built-in wsgi server but you're not # supposed to use it in production. application = Application( [WebAPIService], tns="spyne.examples.hello", # tns="tns", in_protocol=Soap11(validator='lxml'), out_protocol=Soap11()) wsgi_app = WsgiApplication(application) host = '0.0.0.0' port = 5558 print "http://%s:%d" % (host, port) server = make_server(host, port, wsgi_app) server.serve_forever()
def test_callback_name(self): callback_name = 'some_callback' retval = 42 class SomeService(ServiceBase): @srpc(_returns=Integer) def yay(): return retval app = Application([SomeService], 'tns', in_protocol=JsonDocument(), out_protocol=JsonP(callback_name)) server = NullServer(app, ostr=True) assert ''.join( server.service.yay()) == '%s(%d);' % (callback_name, retval)
def _test_type_no_root_cloth(cls, inst): from spyne.util import appreg appreg._applications.clear() class SomeService(ServiceBase): @rpc(_returns=cls, _body_style='bare') def some_call(ctx): return inst prot = HtmlForm() app = Application([SomeService], 'some_ns', out_protocol=prot) null = NullServer(app, ostr=True) elt = etree.fromstring(''.join(null.service.some_call())) show(elt) return elt
def test_customized_simple_type_in_xml_attribute(self): class Product(ComplexModel): __namespace__ = 'some_ns' id = XmlAttribute(Uuid) edition = Unicode class SomeService(ServiceBase): @rpc(Product, _returns=Product) def echo_product(ctx, product): logging.info('edition_id: %r', product.edition_id) return product Application([SomeService], tns='some_ns', in_protocol=Soap11(validator='lxml'), out_protocol=Soap11() )
def test_remote_call_success(self): from spyne import mrpc class SomeComplexModel(ComplexModel): i = Integer @mrpc(_returns=SelfReference) def echo(self, ctx): return self class SomeService(ServiceBase): @rpc(_returns=SomeComplexModel) def get(ctx): return SomeComplexModel() null = NullServer(Application([SomeService], tns='some_tns')) v = SomeComplexModel(i=5) assert null.service.echo(v) is v
def create_app(flask_app): application = Application( [WhoisServiceSOAP], 'whoisinfo.service', in_protocol=Soap11(), out_protocol=Soap11(), ) def _flask_config_context(ctx): ctx.udc = UserDefinedContext(flask_app.config) application.event_manager.add_listener('method_call', _flask_config_context) #output_wsdl(application) # to output wsdl file lul #wsdl output is found at 'http://localhost:5000/soap/?wsdl' return application
def test_simple_type_explicit_customization(self): class Header(ComplexModel): test = Boolean(min_occurs=0, nillable=False) pw = Unicode.customize(min_occurs=0, nillable=False, min_len=6) class Params(ComplexModel): sendHeader = Header.customize(nillable=False, min_occurs=1) class DummyService(ServiceBase): @rpc(Params, _returns=Unicode) def loadServices(ctx, serviceParams): return '42' Application([DummyService], tns='dummy', name='DummyService', in_protocol=Soap11(validator='lxml'), out_protocol=Soap11())
def __init__(self, server_address, url, api, is_ssl): WSGIServer.__init__(self, server_address, ApiHandler) self.is_ssl = is_ssl if self.is_ssl: self.base_environ["HTTPS"] = "yes" app = ApiApplication( Application([SubregCzService], 'http://subreg.cz/wsdl', 'SubregCzService', in_protocol=Soap11(), out_protocol=Soap11(), config={"api": api})) self.set_app(app) app.doc.wsdl11.build_interface_document(url)
def test_callback_name(self): callback_name = 'some_callback' retval = 42 class SomeService(ServiceBase): @srpc(_returns=Integer) def yay(): return retval app = Application([SomeService], 'tns', in_protocol=JsonDocument(), out_protocol=JsonP(callback_name)) server = NullServer(app, ostr=True) ret = server.service.yay() ret = list(ret) print(ret) assert b''.join(ret) == b''.join((callback_name.encode('utf8'), b'(', str(retval).encode('utf8'), b');'))
def test_interface(self): class SomeComplexModel(ComplexModel): @mrpc() def member_method(self, ctx): pass methods = SomeComplexModel.Attributes.methods print(methods) assert 'member_method' in methods class SomeService(ServiceBase): @rpc(_returns=SomeComplexModel) def service_method(ctx): return SomeComplexModel() app = Application([SomeService], 'some_ns') mmm = __name__ + '.SomeComplexModel.SomeComplexModel.member_method' assert mmm in app.interface.method_id_map
def spyne_app_process(): class TestService(ServiceBase): @rpc(Unicode, _returns=Unicode) def ping(self, data): return data spyne_app = Application( [TestService], tns="aiohttp_spyne.tests.test", in_protocol=Soap11(validator="lxml"), out_protocol=Soap11(), ) handler = AIOSpyne(spyne_app) app = web.Application(client_max_size=1024**2 * 2) app.router.add_get("/{tail:.*}", handler.get) app.router.add_post("/{tail:.*}", handler.post) web.run_app(app, host="0.0.0.0", port=PORT)