This class is used to serve either files or output of CGI scripts from the current directory and below. This class implements the do_GET() and do_HEAD() functions. A lot of the work, such as parsing the request, is done by the base class BaseHTTPRequestHandler. SimpleHTTPRequestHandler This class serves files from the current directory and below, directly mapping the directory structure to HTTP requests. Subclasses should not need to override or extend the _init_() method. All the relevant information is stored in instance variables of the handler. For example, for the request method SPAM, the do_SPAM() method will be called with no arguments. The method name is constructed from the request. The handler will parse the request and the headers, then call a method specific to the request type. It must be sub-classed to handle each request method (e.g. By itself, it cannot respond to any actual HTTP requests BaseHTTPRequestHandler just provides a number of class and instance variables, and methods for use by subclasses. This class is used to handle the HTTP requests that arrive at the server. Now, look at some pre-defined Request Handler classes: class http. From rver import HTTPServer, BaseHTTPRequestHandler def run ( server_class = HTTPServer, handler_class = BaseHTTPRequestHandler ): server_address = ( '', 8000 ) httpd = server_class ( server_address, handler_class ) httpd.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |