#!/usr/bin/env python3'''Small wsgiref based web server. Takes a path to serve from and anoptional port number (defaults to 8000), then tries to serve files.Mime types are guessed from the file names, 404 errors are raisedif the file is not found. Used for the make serve target in Doc.'''import sysimport osimport mimetypesfrom wsgiref import simple_server, utildef 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, "rb"))else:respond('404 Not Found', [('Content-Type', 'text/plain')])return [b'not found']if __name__ == '__main__':path = sys.argv[1]port = int(sys.argv[2]) if len(sys.argv) > 2 else 8000httpd = simple_server.make_server('', port, app)print("Serving {} on port {}, control-C to stop".format(path, port))try:httpd.serve_forever()except KeyboardInterrupt:print("\b\bShutting down.")
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。