Added " " (space) to the whitelist of allowed characters in the 'extract'
[zeroinstall.git] / tests / server.py
blob2fd48d59b4fcda6fdef3e9d45bfeb5dd1cb40fce
1 #!/usr/bin/env python
2 import os, sys
3 import BaseHTTPServer
4 import traceback
6 next_step = None
8 class MyHandler(BaseHTTPServer.BaseHTTPRequestHandler):
9 def do_GET(self):
10 leaf = os.path.basename(self.path)
11 if next_step != leaf:
12 self.send_error(404, "Expected %s; got %s" % (expected, leaf))
14 if os.path.exists(leaf):
15 self.send_response(200)
16 self.end_headers()
17 self.wfile.write(file(leaf).read())
18 self.wfile.close()
19 else:
20 self.send_error(404, "Missing: %s" % leaf)
22 def handle_requests(*script):
23 server_address = ('localhost', 8000)
24 httpd = BaseHTTPServer.HTTPServer(server_address, MyHandler)
25 child = os.fork()
26 if child:
27 return child
28 # We are the child
29 try:
30 sys.stderr = sys.stdout
31 print "Waiting for request"
32 global next_step
33 for next_step in script:
34 httpd.handle_request()
35 print "Done"
36 os._exit(0)
37 except:
38 traceback.print_exc()
39 os._exit(1)