Movatterモバイル変換


[0]ホーム

URL:


Previous PageUp One LevelNext PagePython Library ReferenceContentsModule IndexIndex
Previous:11.16 BaseHTTPServerUp:11. Internet Protocols andNext:11.18 CGIHTTPServer

11.17SimpleHTTPServer -- Simple HTTP request handler

TheSimpleHTTPServer module defines a request-handler class,interface compatible withBaseHTTPServer.BaseHTTPRequestHandlerwhich serves files only from a base directory.

TheSimpleHTTPServer module defines the following class:

classSimpleHTTPRequestHandler(request, client_address, server)
This class is used, to serve files from current directory and below,directly mapping the directory structure to HTTP requests.

A lot of the work is done by the base classBaseHTTPServer.BaseHTTPRequestHandler, such as parsing therequest. This class implements thedo_GET() anddo_HEAD() functions.

TheSimpleHTTPRequestHandler defines the following membervariables:

server_version
This will be"SimpleHTTP/" + __version__, where__version__is defined in the module.

extensions_map
A dictionary mapping suffixes into MIME types. Default is signifiedby an empty string, and is considered to betext/plain.The mapping is used case-insensitively, and so should contain onlylower-cased keys.

TheSimpleHTTPRequestHandler defines the following methods:

do_HEAD()
This method serves the'HEAD' request type: it sends theheaders it would send for the equivalentGET request. See thedo_GET() method for more complete explanation of the possibleheaders.

do_GET()
The request is mapped to a local file by interpreting the request asa path relative to the current working directory.

If the request was mapped to a directory, a403 respond is output,followed by the explanation'Directory listing not supported'.AnyIOError exception in opening the requested file, is mappedto a404,'File not found' error. Otherwise, the contenttype is guessed using theextensions_map variable.

A'Content-type:' with the guessed content type is output, andthen a blank line, signifying end of headers, and then the contents ofthe file. The file is always opened in binary mode.

For example usage, see the implementation of thetest()function.

See Also:

ModuleBaseHTTPServer:
Base class implementation for Web server and request handler.


Previous PageUp One LevelNext PagePython Library ReferenceContentsModule IndexIndex
Previous:11.16 BaseHTTPServerUp:11. Internet Protocols andNext:11.18 CGIHTTPServer
Release 2.2.3, documentation updated on 30 May 2003.
SeeAbout this document... for information on suggesting changes.
[8]ページ先頭

©2009-2026 Movatter.jp