Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
from spyne.model.complex import Iterable
from spyne.model.primitive import Integer
from spyne.model.primitive import Unicode
class HelloWorldService(Service):
@rpc(Unicode, Integer, _returns=Iterable(Unicode))
def say_hello(ctx, name, times):
for i in range(times):
yield u'Hello, %s' % name
if __name__=='__main__':
application = Application([HelloWorldService], 'spyne.examples.hello.soap',
in_protocol=Soap11(validator='lxml'),
out_protocol=Soap11(pretty_print=True),
)
# disables context markers. set logging level to logging.INFO to enable
# them.
logging.getLogger('spyne.server.null').setLevel(logging.CRITICAL)
print "With serialization"
print "=================="
print
null = NullServer(application, ostr=True)
ret_stream = null.service.say_hello('Dave', 5)
ret_string = ''.join(ret_stream)
print ret_string
print
if not (ctx.in_header.user_name, ctx.in_header.session_id) in session_db:
raise AuthenticationError(ctx.in_object.user_name)
UserService.event_manager.add_listener('method_call', _on_method_call)
if __name__ == '__main__':
from spyne.util.wsgi_wrapper import run_twisted
logging.basicConfig(level=logging.DEBUG)
logging.getLogger('spyne.protocol.xml').setLevel(logging.DEBUG)
logging.getLogger('twisted').setLevel(logging.DEBUG)
application = Application([AuthenticationService, UserService],
tns='spyne.examples.authentication',
in_protocol=Soap11(validator='lxml'),
out_protocol=Soap11()
)
twisted_apps = [
(WsgiApplication(application), 'app'),
]
sys.exit(run_twisted(twisted_apps, 8000))
ctx.udc = session_id[0] # user name
UserService.event_manager.add_listener('method_call', _on_method_call)
if __name__=='__main__':
from spyne.util.wsgi_wrapper import run_twisted
logging.basicConfig(level=logging.DEBUG)
logging.getLogger('spyne.protocol.xml').setLevel(logging.DEBUG)
logging.getLogger('twisted').setLevel(logging.DEBUG)
application = Application([UserService],
tns='spyne.examples.authentication',
in_protocol=Soap11(validator='lxml'),
out_protocol=Soap11()
)
twisted_apps = [
(WsgiApplication(application), 'app'),
]
sys.exit(run_twisted(twisted_apps, 8000))
def main():
rest = Application([MultiProtService], tns=tns,
in_protocol=HttpRpc(), out_protocol=HttpRpc())
xml = Application([MultiProtService], tns=tns,
in_protocol=HttpRpc(), out_protocol=XmlDocument())
soap = Application([MultiProtService], tns=tns,
in_protocol=HttpRpc(), out_protocol=Soap11())
html = Application([MultiProtService], tns=tns,
in_protocol=HttpRpc(), out_protocol=HtmlMicroFormat())
png = Application([MultiProtService], tns=tns,
in_protocol=HttpRpc(), out_protocol=PngClock())
svg = Application([MultiProtService], tns=tns,
in_protocol=HttpRpc(), out_protocol=SvgClock())
json = Application([MultiProtService], tns=tns,
in_protocol=HttpRpc(), out_protocol=JsonDocument())
jsoni = Application([MultiProtService], tns=tns,
in_protocol=HttpRpc(), out_protocol=JsonDocument(ignore_wrappers=False))
AttrA = XmlAttribute(Unicode)
AttrB = XmlAttribute(Unicode)
Bar = Baz.customize(sub_ns=NS_B)
Baz = Unicode
class FooService(Service):
@rpc(FooCustomRequest, _returns = Iterable(Unicode), _body_style='bare')
def Foo(ctx, req):
AttrA, AttrB, Baz, Bar = req.AttrA, req.AttrB, req.Baz, req.Bar
yield 'Hello, %s' % Bar
application = Application([FooService],
tns="www.example.com/schema/a",
in_protocol=Soap11(validator='soft'),
out_protocol=Soap11(),
)
wsgi_application = WsgiApplication(application)
if __name__ == '__main__':
import logging
from wsgiref.simple_server import make_server
logging.basicConfig(level=logging.DEBUG)
logging.getLogger('spyne.protocol.xml').setLevel(logging.DEBUG)
logging.info("listening to http://127.0.0.1:8000")
def main():
file = open('bench_result' +
str(datetime.datetime.now().strftime("%Y-%m-%d-%H-%M")), 'w')
gen = CubeGen(number_dimensions=3, rows_length=1000, columns_length=5)
gen.generate_csv(gen.generate_cube(3, 1000))
XmlaProviderService.discover_tools.change_catalogue(CUBE_NAME)
mbench = MicBench()
file.write("Benchmarks are made with cpu :\n")
file.write(cpuinfo.get_cpu_info()['brand'] + "\n\n")
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)
t = PrettyTable(['Query', 'olapy execution time'])
cmd = """
SELECT
FROM [""" + CUBE_NAME + """]
WHERE ([Measures].[Amount])
CELL PROPERTIES VALUE, FORMAT_STRING, LANGUAGE, BACK_COLOR, FORE_COLOR, FONT_FLAGS"""
file.write(
@spyne.srpc(Unicode, Integer, _returns=Iterable(Unicode))
def echo(str, cnt):
for i in range(cnt):
yield str
@spyne.srpc(Unicode, _returns=AnswerServiceResponse)
def answer(str):
return AnswerServiceResponse(dummy_str='answer is', dummy_num=42)
class SomeSoapServiceTwo(spyne.Service):
__service_url_path__ = '/soap/someservicetwo'
__target_namespace__ = 'custom_namespacetwo'
__in_protocol__ = Soap11(validator='lxml')
__out_protocol__ = Soap11()
@spyne.srpc(Unicode, Integer, _returns=Iterable(Unicode))
def echo(str, cnt):
for i in range(cnt):
yield str
@spyne.srpc(Unicode, _returns=AnswerServiceResponse)
def answer(str):
return AnswerServiceResponse(dummy_str='answer is', dummy_num=42)
class SomeJsonService(spyne.Service):
__service_url_path__ = '/json/anotherservice'
__in_protocol__ = HttpRpc(validator='soft')
__out_protocol__ = JsonDocument(ignore_wrappers=True)
in_protocol=HttpRpc(), out_protocol=MessagePackDocument())
msgpack_rpc = Application([MultiProtService], tns=tns,
in_protocol=HttpRpc(), out_protocol=MessagePackRpc())
yaml = Application([MultiProtService], tns=tns,
in_protocol=HttpRpc(), out_protocol=YamlDocument())
dyn = Application([DynProtService], tns=tns,
in_protocol=HttpRpc(validator='soft'), out_protocol=HttpRpc())
DynProtService.protocols = {
'json': Tsetprot(JsonDocument(dyn)),
'xml': Tsetprot(XmlDocument(dyn)),
'yaml': Tsetprot(YamlDocument(dyn)),
'soap': Tsetprot(Soap11(dyn)),
'html': Tsetprot(HtmlMicroFormat(dyn)),
'png': Tsetprot(PngClock(dyn)),
'svg': Tsetprot(SvgClock(dyn)),
'msgpack': Tsetprot(MessagePackDocument(dyn)),
}
root = WsgiMounter({
'rest': rest,
'xml': xml,
'soap': soap,
'html': html,
'png': png,
'svg': svg,
'json': json,
'jsoni': jsoni,
'jsonl': jsonl,
('and', String),
('or', String),
])
class EmailManager(Service):
@rpc(String, String, String, _returns=String,
_in_variable_names={'from_': 'from'},
_out_variable_name='return')
def send_email(ctx, to, from_, message):
# do email sending here
return repr((to, from_, message, 'sent!'))
application = Application([EmailManager], 'spyne.examples.events',
in_protocol=Soap11(), out_protocol=Soap11())
if __name__ == '__main__':
import logging
from wsgiref.simple_server import make_server
logging.basicConfig(level=logging.DEBUG)
logging.getLogger('spyne.protocol.xml').setLevel(logging.DEBUG)
server = make_server('127.0.0.1', 8000, WsgiApplication(application))
logging.info("listening to http://127.0.0.1:8000")
logging.info("wsdl is at: http://localhost:8000/?wsdl")
server.serve_forever()
class FileServices(Service):
@rpc(Unicode, _returns=File)
def get_file(ctx, path):
# protect against file name injection attacks
# note that this doesn't protect against symlinks. depending on the kind
# of write access your clients have, this may or may not be a problem.
if not os.path.abspath(path).startswith(FILE_REPO):
raise ValidationError(path)
return File.Value(path=path)
application = Application([FileServices], 'spyne.examples.file.soap',
in_protocol=HttpRpc(),
out_protocol=Soap11())
wsgi_application = WsgiApplication(application)
if __name__ == '__main__':
import logging
from wsgiref.simple_server import make_server
logging.basicConfig(level=logging.DEBUG)
logging.getLogger('spyne.protocol.xml').setLevel(logging.DEBUG)
logging.info("listening to http://127.0.0.1:8000")
logging.info("wsdl is at: http://localhost:8000/?wsdl")
server = make_server('127.0.0.1', 8000, wsgi_application)