1 |
#!/usr/bin/python |
2 |
# |
3 |
# Experiments with Pythons XML-RPM implementation |
4 |
# - the server |
5 |
# |
6 |
# $Id$ |
7 |
|
8 |
from SimpleXMLRPCServer import * |
9 |
|
10 |
class ServerImpl(SimpleXMLRPCServer): |
11 |
|
12 |
def serve_forever(self): |
13 |
print '[server] starting up' |
14 |
self.quit = 0 |
15 |
while not self.quit: |
16 |
self.handle_request() |
17 |
|
18 |
print '[server] shutting down' |
19 |
self.socket.close() |
20 |
|
21 |
class ServerFunctions: |
22 |
|
23 |
# we pass in a ref to the server |
24 |
# that these functions will be used in |
25 |
# so they can interact...I'm guessing |
26 |
# this is clean?...who knows :) |
27 |
def __init__(self, server): |
28 |
self.server = server |
29 |
|
30 |
def die(self): |
31 |
"""die() => kills the server""" |
32 |
self.server.quit = 1 |
33 |
return 1 |
34 |
|
35 |
def remoteprint(self, text): |
36 |
"""print('HelloWorld') => prints HelloWorld""" |
37 |
print '[server] got:', text |
38 |
return 1 |
39 |
|
40 |
def main(): |
41 |
print '--- i-scream.org XML-RPC test server ---' |
42 |
|
43 |
server = ServerImpl(('127.0.0.1', 8000), logRequests=0) |
44 |
server.register_instance(ServerFunctions(server)) |
45 |
server.register_introspection_functions() |
46 |
server.register_multicall_functions() |
47 |
server.serve_forever() |
48 |
|
49 |
if __name__=='__main__': |
50 |
main() |