7
7
8
8
from wsgiref .simple_server import make_server
9
9
from spyne import Application , rpc , ServiceBase , Iterable , UnsignedInteger , \
10
- String , Unicode , M , UnsignedInteger32
10
+ String , Unicode
11
11
12
12
from spyne .protocol .json import JsonDocument
13
13
from spyne .protocol .http import HttpRpc
24
24
testenv ["spyne_server" ] = ("http://127.0.0.1:" + str (testenv ["spyne_port" ]))
25
25
26
26
class HelloWorldService (ServiceBase ):
27
- # @rpc(Unicode, _returns=Unicode)
28
- # def get_resource(self, resource_id):
29
- # # Simulate checking for a resource
30
- # if resource_id != "existing_resource":
31
- # raise ResourceNotFoundError(
32
- # "Resource not found",
33
- # "The requested resource does not exist."
34
- # )
35
- # return f"Resource {resource_id} found."
36
-
37
27
@rpc (String , UnsignedInteger , _returns = Iterable (String ))
38
28
def say_hello (ctx , name , times ):
39
29
"""
40
- Docstrings for service methods do appear as documentation in the
41
- interface documents. <b>What fun!</b>
42
-
43
30
:param name: The name to say hello to
44
31
:param times: The number of times to say hello
45
32
@@ -50,12 +37,22 @@ def say_hello(ctx, name, times):
50
37
yield 'Hello, %s' % name
51
38
52
39
@rpc (_returns = Unicode )
53
- def hello (self ):
40
+ def hello (ctx ):
54
41
return "<center><h1>🐍 Hello Stan! 🦄</h1></center>"
55
42
56
- @rpc (M (UnsignedInteger32 ))
57
- def del_user (ctx , user_id ):
43
+ @rpc (_returns = Unicode )
44
+ def response_headers (ctx ):
45
+ ctx .transport .add_header ("X-Capture-This" , "this" )
46
+ ctx .transport .add_header ("X-Capture-That" , "that" )
47
+ return "Stan wuz here with headers!"
48
+
49
+ @rpc (UnsignedInteger )
50
+ def custom_404 (ctx , user_id ):
58
51
raise ResourceNotFoundError (user_id )
52
+
53
+ @rpc ()
54
+ def exception (ctx ):
55
+ raise Exception ('fake error' )
59
56
60
57
61
58
application = Application ([HelloWorldService ], 'spyne.examples.hello.http' ,
@@ -66,7 +63,5 @@ def del_user(ctx, user_id):
66
63
spyne_server = make_server ('127.0.0.1' , testenv ["spyne_port" ], wsgi_app )
67
64
68
65
if __name__ == '__main__' :
69
- # logging.info("listening to http://127.0.0.1:8000")
70
- # logging.info("wsdl is at: http://localhost:8000/?wsdl")
71
66
spyne_server .request_queue_size = 20
72
67
spyne_server .serve_forever ()
0 commit comments