[New-bugs-announce] [issue8004] add small server to serve docs

Dirkjan Ochtman report at bugs.python.org
Tue Feb 23 22:22:06 CET 2010

New submission from Dirkjan Ochtman <dirkjan at 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()]
        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)

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 <report at bugs.python.org>

More information about the New-bugs-announce mailing list