Module SimpleHTTPServer :: Class SimpleHTTPRequestHandler
[show private | hide private]
[frames | no frames]

Class SimpleHTTPRequestHandler

BaseRequestHandler --+        
                     |        
  StreamRequestHandler --+    
                         |    
    BaseHTTPRequestHandler --+
                             |
                            SimpleHTTPRequestHandler

Known Subclasses:
CGIHTTPRequestHandler, SimpleHTTPRequestHandler

Simple HTTP request handler with GET and HEAD commands.

This serves files from the current directory and any of its subdirectories. It assumes that all files are plain text files unless they have the extension ".html" in which case it assumes they are HTML files.

The GET and HEAD requests are identical except that the HEAD request omits the actual contents of the file.
Method Summary
  copyfile(self, source, outputfile)
Copy all data between two file objects.
  do_GET(self)
Serve a GET request.
  do_HEAD(self)
Serve a HEAD request.
  guess_type(self, path)
Guess the type of a file.
  list_directory(self, path)
Helper to produce a directory listing (absent index.html).
  send_head(self)
Common code for GET and HEAD commands.
  translate_path(self, path)
Translate a /-separated PATH to the local filename syntax.
    Inherited from BaseHTTPRequestHandler
  address_string(self)
Return the client address formatted for logging.
  date_time_string(self)
Return the current date and time formatted for a message header.
  end_headers(self)
Send the blank line ending the MIME headers.
  handle(self)
Handle multiple requests if necessary.
  handle_one_request(self)
Handle a single HTTP request.
  log_date_time_string(self)
Return the current time formatted for logging.
  log_error(self, *args)
Log an error.
  log_message(self, format, *args)
Log an arbitrary message.
  log_request(self, code, size)
Log an accepted request.
  parse_request(self)
Parse a request (internal).
  send_error(self, code, message)
Send and log an error reply.
  send_header(self, keyword, value)
Send a MIME header.
  send_response(self, code, message)
Send the response header and log the response code.
  version_string(self)
Return the server software version string.
    Inherited from StreamRequestHandler
  finish(self)
  setup(self)
    Inherited from BaseRequestHandler
  __init__(self, request, client_address, server)

Class Variable Summary
dict extensions_map = {'': 'application/octet-stream', '.obj'...
str server_version = 'SimpleHTTP/0.6'
    Inherited from BaseHTTPRequestHandler
str error_message_format = '<head>\n<title>Error response</t...
list monthname = [None, 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'J...
str protocol_version = 'HTTP/1.0'
dict responses = {400: ('Bad request', 'Bad request syntax or...
str sys_version = 'Python/2.3.4'
list weekdayname = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat',...
    Inherited from StreamRequestHandler
int rbufsize = -1                                                                    
int wbufsize = 0                                                                     

Method Details

copyfile(self, source, outputfile)

Copy all data between two file objects.

The SOURCE argument is a file object open for reading (or anything with a read() method) and the DESTINATION argument is a file object open for writing (or anything with a write() method).

The only reason for overriding this would be to change the block size or perhaps to replace newlines by CRLF -- note however that this the default server uses this to copy binary data as well.

do_GET(self)

Serve a GET request.

do_HEAD(self)

Serve a HEAD request.

guess_type(self, path)

Guess the type of a file.

Argument is a PATH (a filename).

Return value is a string of the form type/subtype, usable for a MIME Content-type header.

The default implementation looks the file's extension up in the table self.extensions_map, using text/plain as a default; however it would be permissible (if slow) to look inside the data to make a better guess.

list_directory(self, path)

Helper to produce a directory listing (absent index.html).

Return value is either a file object, or None (indicating an error). In either case, the headers are sent, making the interface the same as for send_head().

send_head(self)

Common code for GET and HEAD commands.

This sends the response code and MIME headers.

Return value is either a file object (which has to be copied to the outputfile by the caller unless the command was HEAD, and must be closed by the caller under all circumstances), or None, in which case the caller has nothing further to do.

translate_path(self, path)

Translate a /-separated PATH to the local filename syntax.

Components that mean special things to the local file system (e.g. drive or directory names) are ignored. (XXX They should probably be diagnosed.)

Class Variable Details

extensions_map

Type:
dict
Value:
{'': 'application/octet-stream',
 '.bin': 'application/octet-stream',
 '.dll': 'application/octet-stream',
 '.mp2': 'audio/mpeg',
 '.obj': 'application/octet-stream',
 '.ra': 'audio/x-pn-realaudio',
 '.sgm': 'text/x-sgml',
 '.texi': 'application/x-texinfo',
...                                                                    

server_version

Type:
str
Value:
'SimpleHTTP/0.6'                                                       

Generated by Epydoc 2.1 on Mon Aug 02 01:07:41 2004 http://epydoc.sf.net