New submission from Dirkjan Ochtman <dirk...@ochtman.nl>:

I'd like to put something like this in Doc, to make it easier to actually 
review the built documentation. (I guess we could put it in Tools, I'd just 
like it better if it was right there with the other stuff.)

Good idea? Thomas Wouters kind of liked it but said I should ask you.

from wsgiref.simple_server import make_server
import mimetypes, sys, os

CWD = os.path.dirname(os.path.abspath(__file__))
ROOT = os.path.join(CWD, 'build', 'html')

def app(environ, respond):

    fn = os.path.join(ROOT, 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 [open(fn).read()]
    else:
        respond('404 Not Found', [('Content-Type', 'text/plain')])
        return ['not found']

if __name__ == '__main__':
    port = int(sys.argv[1]) if len(sys.argv) > 1 else 8000
    httpd = make_server('', port, app)
    httpd.serve_forever()

----------
assignee: djc
components: Demos and Tools, Documentation
keywords: patch
messages: 99953
nosy: benjamin.peterson, djc
priority: low
severity: normal
stage: patch review
status: open
title: add small server to serve docs
type: feature request
versions: Python 2.7

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue8004>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to