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
))
33 if os
.path
.exists(leaf
) and not isinstance(resp
, Give404
):
34 self
.send_response(200)
36 self
.wfile
.write(file(leaf
).read())
39 self
.send_error(404, "Missing: %s" % leaf
)
41 def handle_requests(*script
):
42 server_address
= ('localhost', 8000)
43 httpd
= BaseHTTPServer
.HTTPServer(server_address
, MyHandler
)
49 sys
.stderr
= sys
.stdout
50 print "Waiting for request"
52 for next_step
in script
:
53 if type(next_step
) != tuple: next_step
= (next_step
,)
55 httpd
.handle_request()