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