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)
30 # (don't use a symlink as they don't work on Windows)
31 if leaf
== 'latest.xml':
35 self
.send_error(404, "Expected %s; got %s" % (next_step
, parsed
.path
))
36 elif parsed
.path
.startswith('/key-info/'):
37 self
.send_response(200)
39 self
.wfile
.write('<key-lookup/>')
41 elif os
.path
.exists(leaf
) and not isinstance(resp
, Give404
):
42 self
.send_response(200)
44 self
.wfile
.write(file(leaf
).read())
47 self
.send_error(404, "Missing: %s" % leaf
)
49 def handle_requests(*script
):
50 server_address
= ('localhost', 8000)
51 httpd
= BaseHTTPServer
.HTTPServer(server_address
, MyHandler
)
57 sys
.stderr
= sys
.stdout
58 #sys.stdout = sys.stderr
59 print "Waiting for request"
61 for next_step
in script
:
62 if type(next_step
) != tuple: next_step
= (next_step
,)
64 httpd
.handle_request()