9 def __init__(self
, path
):
16 return "404 on " + self
.path
18 class MyHandler(BaseHTTPServer
.BaseHTTPRequestHandler
):
20 leaf
= os
.path
.basename(self
.path
)
22 acceptable
= dict([(str(x
), x
) for x
in next_step
])
24 resp
= acceptable
.get(self
.path
, None) or \
25 acceptable
.get(leaf
, None) or \
26 acceptable
.get('*', None)
29 self
.send_error(404, "Expected %s; got %s" % (next_step
, self
.path
))
31 if os
.path
.exists(leaf
) and not isinstance(resp
, Give404
):
32 self
.send_response(200)
34 self
.wfile
.write(file(leaf
).read())
37 self
.send_error(404, "Missing: %s" % leaf
)
39 def handle_requests(*script
):
40 server_address
= ('localhost', 8000)
41 httpd
= BaseHTTPServer
.HTTPServer(server_address
, MyHandler
)
47 sys
.stderr
= sys
.stdout
48 print "Waiting for request"
50 for next_step
in script
:
51 if type(next_step
) != tuple: next_step
= (next_step
,)
53 httpd
.handle_request()