diff options
author | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2010-02-24 04:12:11 (GMT) |
---|---|---|
committer | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2010-02-24 04:12:11 (GMT) |
commit | e4c74e1ea26e77b065a8999b7192160595474211 (patch) | |
tree | d34c0c2afddb8f236e5fc6a0ae5fbcf29b92528c /Tools/scripts | |
parent | 2d78070f63aee49842e82b2d9aae66ac7493c0fa (diff) | |
download | cpython-e4c74e1ea26e77b065a8999b7192160595474211.zip cpython-e4c74e1ea26e77b065a8999b7192160595474211.tar.gz cpython-e4c74e1ea26e77b065a8999b7192160595474211.tar.bz2 |
Issue #8004: add a serve target to the Doc Makefile.
Diffstat (limited to 'Tools/scripts')
-rwxr-xr-x | Tools/scripts/serve.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/Tools/scripts/serve.py b/Tools/scripts/serve.py new file mode 100755 index 0000000..09d850a --- /dev/null +++ b/Tools/scripts/serve.py @@ -0,0 +1,25 @@ +#!/usr/bin/env python +import sys +import os +import mimetypes +from wsgiref import simple_server, util + +def app(environ, respond): + + fn = os.path.join(path, environ['PATH_INFO'][1:]) + if '.' not in fn.split(os.path.sep)[-1]: + fn = os.path.join(fn, 'index.html') + type = mimetypes.guess_type(fn)[0] + + if os.path.exists(fn): + respond('200 OK', [('Content-Type', type)]) + return util.FileWrapper(open(fn)) + else: + respond('404 Not Found', [('Content-Type', 'text/plain')]) + return ['not found'] + +if __name__ == '__main__': + path = sys.argv[1] + port = int(sys.argv[2]) if len(sys.argv) > 2 else 8000 + httpd = simple_server.make_server('', port, app) + httpd.serve_forever() |