This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author djc
Recipients benjamin.peterson, djc
Date 2010-02-23.21:22:04
SpamBayes Score 4.521855e-06
Marked as misclassified No
Message-id <1266960126.19.0.905943018148.issue8004@psf.upfronthosting.co.za>
In-reply-to
Content
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()
History
Date User Action Args
2010-02-23 21:22:06djcsetrecipients: + djc, benjamin.peterson
2010-02-23 21:22:06djcsetmessageid: <1266960126.19.0.905943018148.issue8004@psf.upfronthosting.co.za>
2010-02-23 21:22:05djclinkissue8004 messages
2010-02-23 21:22:04djccreate