diff options
author | Senthil Kumaran <orsenthil@gmail.com> | 2010-06-16 16:44:15 (GMT) |
---|---|---|
committer | Senthil Kumaran <orsenthil@gmail.com> | 2010-06-16 16:44:15 (GMT) |
commit | 322db0d3582faadc25b349edf77650b65db46fb7 (patch) | |
tree | 0f14f96138e966373fea82cfe2ebcb4b05303650 /Doc/library/http.server.rst | |
parent | b0434fcd4b7bbfddc556f938e3a4eb8e0934d2d0 (diff) | |
download | cpython-322db0d3582faadc25b349edf77650b65db46fb7.zip cpython-322db0d3582faadc25b349edf77650b65db46fb7.tar.gz cpython-322db0d3582faadc25b349edf77650b65db46fb7.tar.bz2 |
Merged revisions 82022 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k
................
r82022 | senthil.kumaran | 2010-06-16 22:11:11 +0530 (Wed, 16 Jun 2010) | 9 lines
Merged revisions 82018 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r82018 | senthil.kumaran | 2010-06-16 20:25:31 +0530 (Wed, 16 Jun 2010) | 3 lines
Fix Issue8937 - SimpleHTTPServer should contain usage example
........
................
Diffstat (limited to 'Doc/library/http.server.rst')
-rw-r--r-- | Doc/library/http.server.rst | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/Doc/library/http.server.rst b/Doc/library/http.server.rst index d647980..3d15b9e 100644 --- a/Doc/library/http.server.rst +++ b/Doc/library/http.server.rst @@ -281,8 +281,30 @@ of which this module provides three different variants: contents of the file are output. If the file's MIME type starts with ``text/`` the file is opened in text mode; otherwise binary mode is used. - For example usage, see the implementation of the :func:`test` function. + For example usage, see the implementation of the :func:`test` function + invocation in the :mod:`http.server` module. +The :class:`SimpleHTTPRequestHandler` class can be invoked the following manner +with the :mod:`http.server` to create a very basic webserver serving files +relative to the current directory.:: + + import http.server + import socketserver + + PORT = 8000 + + Handler = http.server.SimpleHTTPRequestHandler + + httpd = socketserver.TCPServer(("", PORT), Handler) + + print("serving at port", PORT) + httpd.serve_forever() + +:mod:`http.server` can also be invoked directly using the ``-m`` switch of +interpreter a with ``port number`` argument which interfaces +:class:`SimpleHTTPRequestHandler` by default.:: + + python -m http.server 8000 .. class:: CGIHTTPRequestHandler(request, client_address, server) |