Mercurial > cpython-lru_cache-weakref
diff Doc/library/simplehttpserver.rst @ 62354:84fefbf1d6c0 legacy-trunk
Fix Issue8937 - SimpleHTTPServer should contain usage example
| author | Senthil Kumaran <orsenthil@gmail.com> |
|---|---|
| date | Wed, 16 Jun 2010 14:55:31 +0000 |
| parents | 662d15af52df |
| children | c6845e83086f |
line wrap: on
line diff
--- a/Doc/library/simplehttpserver.rst Tue Jun 15 08:33:03 2010 +0000 +++ b/Doc/library/simplehttpserver.rst Wed Jun 16 14:55:31 2010 +0000 @@ -81,12 +81,34 @@ 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. + The :func:`test` function in the :mod:`SimpleHTTPServer` module is an + example which interfaces the :class:`SimpleHTTPRequestHandler` as a + Handler to the :mod:`BaseHTTPServer` module. .. versionadded:: 2.5 The ``'Last-Modified'`` header. +The :mod:`SimpleHTTPServer` module can be used the following manner in order to +setup a very basic web server serving files relative to the current directory.:: + + import SimpleHTTPServer + import SocketServer + + PORT = 8000 + + Handler = SimpleHTTPServer.SimpleHTTPRequestHandler + + httpd = SocketServer.TCPServer(("", PORT), Handler) + + print "serving at port", PORT + httpd.serve_forever() + +It can also be invoked directly using the ``-m`` switch of interpreter a with +``port number`` argument.:: + + python -m SimpleHTTPServer 8000 + .. seealso:: Module :mod:`BaseHTTPServer`
