Am lost in ObjetLand... (BaseHTTPServer class hierarchy)

Terry Reedy tjreedy at home.com
Wed Aug 22 19:55:28 EDT 2001


"Fred Pacquier" <fredp at mygale.org.nospam> wrote in message
news:Xns9105B9AA19A20PaCmAnRDLM at 161.48.128.20...
>
> Another newbie question...
>
> I was playing with BaseHTTPServer.py and got stumped with a
(seemingly)
> simple question :
>
> The module defines these classes :
>
> class HTTPServer(SocketServer.TCPServer):
>  (...)
>
> class BaseHTTPRequestHandler(SocketServer.StreamRequestHandler):
>   (...)
>     def date_time_string(self):
>         (...)
>   (...)
>
> then a function that serves as "main" :
>
> def test(HandlerClass = BaseHTTPRequestHandler,
>          ServerClass = ):
>
>     server_address = ('', 8000)
>     httpd = ServerClass(server_address, HandlerClass)
>     httpd.serve_forever()
>
>
> The question is : can I use the date_time_string() method of
> BaseHTTPRequestHandler inside the 'test' function ? If so, how ? At
first I
> thought the 'httpd' instance of HTTPServer should know about that
method
> somehow, but now I'm not so sure :)

You can create your own instance of BaseHTTPRequestHandler in the test
function and then call that method on it, but it will not be the same
instance as the one used by ServerClass.  Take a look at
HTTPServer.__init__ to see what it does with the Handler Class.  Then
search for "date_time_string" to see if it ever calls that method.

Terry J. Reedy






More information about the Python-list mailing list