running code from "Scripting The Web with Python"

Eugene Leitl Eugene.Leitl at lrz.uni-muenchen.de
Tue Mar 27 07:20:50 EST 2001


I haven't snipped the rest of the post, to preserve content. The program
works nicely (it is serving a Java applet page right now), and I'm very
much impressed with it. Not with the program, that is, with the language.

It solves several of my problems: I can have a single binary containing my
entire application, instead of littering the client's filespace with
diverse versions of Python and/or large frozen binaries, or even little
ugly fewmets in the cgi-bin and html directories. Perfect.

Are the handlers asynchronous? Or will the server hang if processing
a lengthy request? If yes, are Python threads painless, or are
there diverse caveats?

TIA,
Eugene

On Tue, 27 Mar 2001, Hamish Lawson wrote:

> Eugene Leitl wrote:
> 
> > I've snipped the following code from Guido's
> > http://www.w3j.com/6/s3.vanrossum.html presentation:
> > ... I can't run it due to syntax errors
> 
> 
> Wow, they really messed up the formatting on that! Below is the
> properly formatted version.
> 
> Hamish Lawson
> 
> ---
> 
> import StringIO
> import SimpleHTTPServer
> 
> BaseClass = SimpleHTTPServer.SimpleHTTPRequestHandler
> 
> CounterTemplate = """ <H1>Server
> Statistics</H1>
> 
> This <A HREF=/index.html>server</A> has been accessed
> <b>%d</b> times.  """
> 
> count = 0
> 
> class MyRequestHandler(BaseClass):
> 
>     def do_GET(self):
>         global count
>         count = count + 1
>         BaseClass.do_GET(self)
> 
>     def send_head(self):
>         if self.path == "/counter.html":
>             return self.send_counter()
>         else:
>             return BaseClass.send_head(self)
> 
>     def send_counter(self):
>         self.send_response(200)
>         self.send_header("Content-type", "text/html")
>         self.end_headers()
>         text = CounterTemplate % count
>         return StringIO.StringIO(text)
> 
> def test():
>     SimpleHTTPServer.test(MyRequestHandler)
> 
> test() 
> 
> 
> ____________________________________________________________
> Do You Yahoo!?
> Get your free @yahoo.co.uk address at http://mail.yahoo.co.uk
> or your free @yahoo.ie address at http://mail.yahoo.ie
> 
> -- 
> http://mail.python.org/mailman/listinfo/python-list
> 

______________________________________________________________
ICBMTO  : N48 10'07'' E011 33'53'' http://www.lrz.de/~ui22204 
57F9CFD3: ED90 0433 EB74 E4A9 537F CFF5 86E7 629B 57F9 CFD3





More information about the Python-list mailing list