https://github.com/python/cpython/commit/509556241d7439098443779a59387310431bfc49
commit: 509556241d7439098443779a59387310431bfc49
branch: 3.14
author: Bénédikt Tran <[email protected]>
committer: picnixz <[email protected]>
date: 2026-07-05T12:15:11+02:00
summary:
[3.14] gh-151945: fix Sphinx reference warnings in `http.server` docs
(GH-153084) (#153087)
[3.14] gh-151945: fix Sphinx reference warnings in `http.server` docs
(GH-153084)
(cherry picked from commit 9f9787d83462f5b44cb59e3c69e7c1799612a33f)
files:
M Doc/library/http.server.rst
M Doc/tools/.nitignore
diff --git a/Doc/library/http.server.rst b/Doc/library/http.server.rst
index 80773578a768bd..e61d1d98f6cabf 100644
--- a/Doc/library/http.server.rst
+++ b/Doc/library/http.server.rst
@@ -39,7 +39,17 @@ handler. Code to create and run the server looks like this::
This class builds on the :class:`~socketserver.TCPServer` class by storing
the server address as instance variables named :attr:`server_name` and
:attr:`server_port`. The server is accessible by the handler, typically
- through the handler's :attr:`server` instance variable.
+ through the handler's :attr:`~socketserver.BaseRequestHandler.server`
+ instance variable.
+
+ .. attribute:: server_name
+
+ The HTTP server's fully qualified domain name.
+
+ .. attribute:: server_port
+
+ The HTTP server's port number obtained from *server_address*.
+
.. class:: ThreadingHTTPServer(server_address, RequestHandlerClass)
@@ -390,6 +400,14 @@ instantiation, of which this module provides three
different variants:
This will be ``"SimpleHTTP/" + __version__``, where ``__version__`` is
defined at the module level.
+ .. attribute:: index_pages
+
+ Specifies the filenames that are treated as directory index pages.
+
+ Defaults to ``("index.html", "index.htm")``.
+
+ .. versionadded:: 3.12
+
.. attribute:: extensions_map
A dictionary mapping suffixes into MIME types, contains custom overrides
@@ -413,8 +431,8 @@ instantiation, of which this module provides three
different variants:
The request is mapped to a local file by interpreting the request as a
path relative to the current working directory.
- If the request was mapped to a directory, the directory is checked for a
- file named ``index.html`` or ``index.htm`` (in that order). If found, the
+ If the request was mapped to a directory, the directory is checked for
+ an index page as specified by :attr:`index_pages`. If found, the
file's contents are returned; otherwise a directory listing is generated
by calling the :meth:`list_directory` method. This method uses
:func:`os.listdir` to scan the directory, and returns a ``404`` error
@@ -441,6 +459,30 @@ instantiation, of which this module provides three
different variants:
.. versionchanged:: 3.7
Support of the ``'If-Modified-Since'`` header.
+ .. method:: list_directory(path)
+
+ Helper to list the contents of *path* when no index page is present.
+
+ This returns either a :term:`file-like object` (which must be closed
+ by the caller) or ``None`` to indicate an error, in which case the
+ caller has nothing further to do. In either case, the headers are sent.
+
+ .. method:: guess_type(path)
+
+ Guess the type of the file at the given *path*.
+
+ This returns a string of the form ``type/subtype``, usable for
+ a MIME Content-type header.
+
+ The default implementation looks the file's extension up in
+ :attr:`extensions_map`, falling back to
+ :func:`mimetypes.guess_file_type` and then to
+ ``'application/octet-stream'``.
+
+ .. versionchanged:: 3.13
+ Add :func:`mimetypes.guess_file_type` as a fallback.
+
+
The :class:`SimpleHTTPRequestHandler` class can be used in the following
manner in order to create a very basic webserver serving files relative to
the current directory::
@@ -459,7 +501,7 @@ the current directory::
:class:`SimpleHTTPRequestHandler` can also be subclassed to enhance behavior,
such as using different index file names by overriding the class attribute
-:attr:`index_pages`.
+:attr:`~SimpleHTTPRequestHandler.index_pages`.
.. class:: CGIHTTPRequestHandler(request, client_address, server)
@@ -480,7 +522,9 @@ such as using different index file names by overriding the
class attribute
the other common server configuration is to treat special extensions as
denoting CGI scripts.
- The :func:`do_GET` and :func:`do_HEAD` functions are modified to run CGI
scripts
+ The :func:`~SimpleHTTPRequestHandler.do_GET` and
+ :func:`~SimpleHTTPRequestHandler.do_HEAD` functions
+ are modified to run CGI scripts
and serve the output, instead of serving files, if the request leads to
somewhere below the ``cgi_directories`` path.
diff --git a/Doc/tools/.nitignore b/Doc/tools/.nitignore
index bd0f7bfacd962f..74a741fabb90eb 100644
--- a/Doc/tools/.nitignore
+++ b/Doc/tools/.nitignore
@@ -12,7 +12,6 @@ Doc/library/ast.rst
Doc/library/asyncio-extending.rst
Doc/library/email.charset.rst
Doc/library/email.parser.rst
-Doc/library/http.server.rst
Doc/library/importlib.rst
Doc/library/logging.config.rst
Doc/library/logging.handlers.rst
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]