3 from __future__
import print_function
5 import os
, sys
, urlparse
12 def __init__(self
, path
):
19 return "404 on " + self
.path
21 class MyHandler(BaseHTTPServer
.BaseHTTPRequestHandler
):
23 parsed
= urlparse
.urlparse(self
.path
)
25 leaf
= os
.path
.basename(parsed
.path
)
27 acceptable
= dict([(str(x
), x
) for x
in next_step
])
29 resp
= acceptable
.get(parsed
.path
, None) or \
30 acceptable
.get(leaf
, None) or \
31 acceptable
.get('*', None)
33 # (don't use a symlink as they don't work on Windows)
34 if leaf
== 'latest.xml':
38 self
.send_error(404, "Expected %s; got %s" % (next_step
, parsed
.path
))
39 elif parsed
.path
.startswith('/key-info/'):
40 self
.send_response(200)
42 self
.wfile
.write('<key-lookup><item vote="good">Approved for testing</item></key-lookup>')
44 elif os
.path
.exists(leaf
) and not isinstance(resp
, Give404
):
45 self
.send_response(200)
47 self
.wfile
.write(file(leaf
).read())
50 self
.send_error(404, "Missing: %s" % leaf
)
52 def handle_requests(*script
):
53 server_address
= ('localhost', 8000)
54 httpd
= BaseHTTPServer
.HTTPServer(server_address
, MyHandler
)
60 sys
.stderr
= sys
.stdout
61 #sys.stdout = sys.stderr
62 print("Waiting for request")
64 for next_step
in script
:
65 if type(next_step
) != tuple: next_step
= (next_step
,)
67 httpd
.handle_request()