File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2727 @echo " suspicious to check for suspicious markup in output text"
2828 @echo " coverage to check documentation coverage for library and C API"
2929 @echo " dist to create a \" dist\" directory with archived docs for download"
30+ @echo " serve to serve the documentation on the localhost (8000)"
3031
3132# Note: if you update versions here, do the same in make.bat and README.txt
3233checkout :
@@ -149,3 +150,6 @@ dist:
149150
150151check :
151152 $(PYTHON ) tools/rstlint.py -i tools
153+
154+ serve :
155+ ../Tools/scripts/serve.py build/html
Original file line number Diff line number Diff line change @@ -832,6 +832,9 @@ Build
832832Documentation
833833------------
834834
835+ - A small wsgi server was added as Tools/scripts/serve.py, and is used to
836+ implement a local documentation server via 'make serve' in the doc directory.
837+
835838- Updating `Using Python` documentation to include description of CPython's
836839 -J and -X options.
837840
Original file line number Diff line number Diff line change @@ -56,6 +56,7 @@ pysource.py Find Python source files
5656redemo.py Basic regular expression demonstration facility
5757reindent.py Change .py files to use 4-space indents.
5858rgrep.py Reverse grep through a file (useful for big logfiles)
59+ serve.py Small wsgiref-based web server, used in make serve in Doc
5960setup.py Install all scripts listed here
6061suff.py Sort a list of files by suffix
6162svneol.py Sets svn:eol-style on all files in directory
Original file line number Diff line number Diff line change 1+ #!/usr/bin/env python
2+ '''
3+ Small wsgiref based web server. Takes a path to serve from and an
4+ optional port number (defaults to 8000), then tries to serve files.
5+ Mime types are guessed from the file names, 404 errors are thrown
6+ if the file is not found. Used for the make serve target in Doc.
7+ '''
8+ import sys
9+ import os
10+ import mimetypes
11+ from wsgiref import simple_server , util
12+
13+ def app (environ , respond ):
14+
15+ fn = os .path .join (path , environ ['PATH_INFO' ][1 :])
16+ if '.' not in fn .split (os .path .sep )[- 1 ]:
17+ fn = os .path .join (fn , 'index.html' )
18+ type = mimetypes .guess_type (fn )[0 ]
19+
20+ if os .path .exists (fn ):
21+ respond ('200 OK' , [('Content-Type' , type )])
22+ return util .FileWrapper (open (fn ))
23+ else :
24+ respond ('404 Not Found' , [('Content-Type' , 'text/plain' )])
25+ return ['not found' ]
26+
27+ if __name__ == '__main__' :
28+ path = sys .argv [1 ]
29+ port = int (sys .argv [2 ]) if len (sys .argv ) > 2 else 8000
30+ httpd = simple_server .make_server ('' , port , app )
31+ httpd .serve_forever ()
You can’t perform that action at this time.
0 commit comments