bpo-36329: Remove 'make -C Doc serve' in favour of 'make -C Doc htmlview' by hugovk · Pull Request #32354 · python/cpython · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions Doc/Makefile
68 changes: 57 additions & 11 deletions Doc/library/wsgiref.rst
Original file line number Diff line number Diff line change
Expand Up @@ -813,30 +813,76 @@ Examples

This is a working "Hello World" WSGI application::

"""
Every WSGI application must have an application object - a callable
object that accepts two arguments. For that purpose, we're going to
use a function (note that you're not limited to a function, you can
use a class for example). The first argument passed to the function
is a dictionary containing CGI-style environment variables and the
second variable is the callable object.
"""
from wsgiref.simple_server import make_server

# Every WSGI application must have an application object - a callable
# object that accepts two arguments. For that purpose, we're going to
# use a function (note that you're not limited to a function, you can
# use a class for example). The first argument passed to the function
# is a dictionary containing CGI-style environment variables and the
# second variable is the callable object.

def hello_world_app(environ, start_response):
status = '200 OK' # HTTP Status
headers = [('Content-type', 'text/plain; charset=utf-8')] # HTTP Headers
status = "200 OK" # HTTP Status
headers = [("Content-type", "text/plain; charset=utf-8")] # HTTP Headers
start_response(status, headers)

# The returned object is going to be printed
return [b"Hello World"]

with make_server('', 8000, hello_world_app) as httpd:
with make_server("", 8000, hello_world_app) as httpd:
print("Serving on port 8000...")

# Serve until process is killed
httpd.serve_forever()



Example of a WSGI application serving the current directory, accept optional
directory and port number (default: 8000) on the command line:
directory and port number (default: 8000) on the command line::

"""
Small wsgiref based web server. Takes a path to serve from and an
optional port number (defaults to 8000), then tries to serve files.
MIME types are guessed from the file names, 404 errors are raised
if the file is not found.
"""
import mimetypes
import os
import sys
from wsgiref import simple_server, util


def app(environ, respond):
# Get the file name and MIME type
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")
mime_type = mimetypes.guess_type(fn)[0]

# Return 200 OK if file exists, otherwise 404 Not Found
if os.path.exists(fn):
respond("200 OK", [("Content-Type", mime_type)])
return util.FileWrapper(open(fn, "rb"))
else:
respond("404 Not Found", [("Content-Type", "text/plain")])
return [b"not found"]


if __name__ == "__main__":
# Get the path and port from command-line arguments
path = sys.argv[1] if len(sys.argv) > 1 else os.getcwd()
port = int(sys.argv[2]) if len(sys.argv) > 2 else 8000

# Make and start the server until control-c
httpd = simple_server.make_server("", port, app)
print(f"Serving {path} on port {port}, control-C to stop")
try:
httpd.serve_forever()
except KeyboardInterrupt:
print("Shutting down.")
httpd.server_close()


.. literalinclude:: ../../Tools/scripts/serve.py
4 changes: 2 additions & 2 deletions Doc/make.bat
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ echo. Provided by Sphinx:
echo. html, htmlhelp, latex, text
echo. suspicious, linkcheck, changes, doctest
echo. Provided by this script:
echo. clean, check, serve, htmlview
echo. clean, check, htmlview
echo.
echo.All arguments past the first one are passed through to sphinx-build as
echo.filenames to build or are ignored. See README.rst in this directory or
Expand Down Expand Up @@ -184,7 +184,7 @@ cmd /S /C "%SPHINXLINT% -i tools"
goto end

:serve
cmd /S /C "%PYTHON% ..\Tools\scripts\serve.py "%BUILDDIR%\html""
echo.The serve target was removed, use htmlview instead (see bpo-36329)
goto end

:end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Remove 'make -C Doc serve' in favour of 'make -C Doc htmlview'
1 change: 0 additions & 1 deletion Tools/scripts/README
36 changes: 0 additions & 36 deletions Tools/scripts/serve.py

This file was deleted.