Skip to content

Commit 14b3a6a

Browse files
picnixzmiss-islington
authored andcommitted
gh-151945: fix Sphinx reference warnings in http.server docs (GH-153084)
(cherry picked from commit 9f9787d) Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
1 parent e9f92ac commit 14b3a6a

2 files changed

Lines changed: 45 additions & 4 deletions

File tree

Doc/library/http.server.rst

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,17 @@ handler. Code to create and run the server looks like this::
3939
This class builds on the :class:`~socketserver.TCPServer` class by storing
4040
the server address as instance variables named :attr:`server_name` and
4141
:attr:`server_port`. The server is accessible by the handler, typically
42-
through the handler's :attr:`server` instance variable.
42+
through the handler's :attr:`~socketserver.BaseRequestHandler.server`
43+
instance variable.
44+
45+
.. attribute:: server_name
46+
47+
The HTTP server's fully qualified domain name.
48+
49+
.. attribute:: server_port
50+
51+
The HTTP server's port number obtained from *server_address*.
52+
4353

4454
.. class:: ThreadingHTTPServer(server_address, RequestHandlerClass)
4555

@@ -402,6 +412,14 @@ instantiation, of which this module provides three different variants:
402412

403413
.. versionadded:: 3.15
404414

415+
.. attribute:: index_pages
416+
417+
Specifies the filenames that are treated as directory index pages.
418+
419+
Defaults to ``("index.html", "index.htm")``.
420+
421+
.. versionadded:: 3.12
422+
405423
.. attribute:: extensions_map
406424

407425
A dictionary mapping suffixes into MIME types, contains custom overrides
@@ -435,7 +453,7 @@ instantiation, of which this module provides three different variants:
435453
path relative to the current working directory.
436454

437455
If the request was mapped to a directory, the directory is checked for a
438-
file named ``index.html`` or ``index.htm`` (in that order). If found, the
456+
an index page as specified by :attr:`index_pages`. If found, the
439457
file's contents are returned; otherwise a directory listing is generated
440458
by calling the :meth:`list_directory` method. This method uses
441459
:func:`os.listdir` to scan the directory, and returns a ``404`` error
@@ -465,6 +483,30 @@ instantiation, of which this module provides three different variants:
465483
.. versionchanged:: 3.7
466484
Support of the ``'If-Modified-Since'`` header.
467485

486+
.. method:: list_directory(path)
487+
488+
Helper to list the contents of *path* when no index page is present.
489+
490+
This returns either a :term:`file-like object` (which must be closed
491+
by the caller) or ``None`` to indicate an error, in which case the
492+
caller has nothing further to do. In either case, the headers are sent.
493+
494+
.. method:: guess_type(path)
495+
496+
Guess the type of the file at the given *path*.
497+
498+
This returns a string of the form ``type/subtype``, usable for
499+
a MIME Content-type header.
500+
501+
The default implementation looks the file's extension up in
502+
:attr:`extensions_map`, falling back to
503+
:func:`mimetypes.guess_file_type` and then to
504+
:attr:`default_content_type`.
505+
506+
.. versionchanged:: 3.13
507+
Add :func:`mimetypes.guess_file_type` as a fallback.
508+
509+
468510
The :class:`SimpleHTTPRequestHandler` class can be used in the following
469511
manner in order to create a very basic webserver serving files relative to
470512
the current directory::
@@ -483,7 +525,7 @@ the current directory::
483525

484526
:class:`SimpleHTTPRequestHandler` can also be subclassed to enhance behavior,
485527
such as using different index file names by overriding the class attribute
486-
:attr:`index_pages`.
528+
:attr:`~SimpleHTTPRequestHandler.index_pages`.
487529

488530

489531
.. _http-server-cli:

Doc/tools/.nitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ Doc/library/ast.rst
99
Doc/library/asyncio-extending.rst
1010
Doc/library/email.charset.rst
1111
Doc/library/email.parser.rst
12-
Doc/library/http.server.rst
1312
Doc/library/importlib.rst
1413
Doc/library/logging.config.rst
1514
Doc/library/logging.handlers.rst

0 commit comments

Comments
 (0)