2 import os
, sys
, urlparse
9 def __init__(self
, path
):
16 return "404 on " + self
.path
18 class MyHandler(BaseHTTPServer
.BaseHTTPRequestHandler
):
20 parsed
= urlparse
.urlparse(self
.path
)
22 leaf
= os
.path
.basename(parsed
.path
)
24 acceptable
= dict([(str(x
), x
) for x
in next_step
])
26 resp
= acceptable
.get(parsed
.path
, None) or \
27 acceptable
.get(leaf
, None) or \
28 acceptable
.get('*', None)
31 self
.send_error(404, "Expected %s; got %s" % (next_step
, parsed
.path
))
32 elif parsed
.path
.startswith('/key-info/'):
33 self
.send_response(200)
35 self
.wfile
.write('<key-lookup/>')
37 elif os
.path
.exists(leaf
) and not isinstance(resp
, Give404
):
38 self
.send_response(200)
40 self
.wfile
.write(file(leaf
).read())
43 self
.send_error(404, "Missing: %s" % leaf
)
45 def handle_requests(*script
):
46 server_address
= ('localhost', 8000)
47 httpd
= BaseHTTPServer
.HTTPServer(server_address
, MyHandler
)
53 sys
.stderr
= sys
.stdout
54 print "Waiting for request"
56 for next_step
in script
:
57 if type(next_step
) != tuple: next_step
= (next_step
,)
59 httpd
.handle_request()