running code from "Scripting The Web with Python"

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


I've snipped the following code from Guido's
http://www.w3j.com/6/s3.vanrossum.html presentation:

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() 

I can't run it due to syntax errors (Python 2.0 and 1.5). I've tried
hacking it a bit, but not knowing Python syntax I've been unable to make
it run. Any ideas?





More information about the Python-list mailing list