Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e821cb6

Browse files
committed
Merged revisions 78416,78430 via svnmerge from
svn+ssh://[email protected]/python/trunk ........ r78416 | dirkjan.ochtman | 2010-02-23 23:12:11 -0500 (Tue, 23 Feb 2010) | 1 line Issue #8004: add a serve target to the Doc Makefile. ........ r78430 | dirkjan.ochtman | 2010-02-24 12:06:31 -0500 (Wed, 24 Feb 2010) | 1 line Add some notes about Tools/scripts/serve.py. ........
1 parent 61605d7 commit e821cb6

4 files changed

Lines changed: 39 additions & 0 deletions

File tree

Doc/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ help:
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
3233
checkout:
@@ -149,3 +150,6 @@ dist:
149150

150151
check:
151152
$(PYTHON) tools/rstlint.py -i tools
153+
154+
serve:
155+
../Tools/scripts/serve.py build/html

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -832,6 +832,9 @@ Build
832832
Documentation
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

Tools/scripts/README

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ pysource.py Find Python source files
5656
redemo.py Basic regular expression demonstration facility
5757
reindent.py Change .py files to use 4-space indents.
5858
rgrep.py Reverse grep through a file (useful for big logfiles)
59+
serve.py Small wsgiref-based web server, used in make serve in Doc
5960
setup.py Install all scripts listed here
6061
suff.py Sort a list of files by suffix
6162
svneol.py Sets svn:eol-style on all files in directory

Tools/scripts/serve.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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()

0 commit comments

Comments
 (0)