blob: a91771a83f111b8359792e5f6830948164bc1eb5 [file] [log] [blame]
Jack Jansen5a1a1751996-09-09 01:47:24 +00001"""cgitest - A minimal CGI applet. Echos parameters back to the client.
2"""
3
4from MiniAEFrame import AEServer, MiniApplication
Just van Rossum158ce422000-03-26 10:12:26 +00005import MacOS
Jack Jansen5a1a1751996-09-09 01:47:24 +00006
7class CGITest(AEServer, MiniApplication):
8
9 def __init__(self):
10 MiniApplication.__init__(self)
11 AEServer.__init__(self)
12 self.installaehandler('aevt', 'oapp', self.open_app)
13 self.installaehandler('aevt', 'quit', self.quit)
14 self.installaehandler('WWW\275', 'sdoc', self.cgihandler)
Jack Jansene504fa21998-09-30 09:11:51 +000015 oldparams = MacOS.SchedParams(0, 0)
Jack Jansen5a1a1751996-09-09 01:47:24 +000016 self.mainloop()
Jack Jansene504fa21998-09-30 09:11:51 +000017 apply(MacOS.SchedParams, oldparams)
Jack Jansen5a1a1751996-09-09 01:47:24 +000018
19 def quit(self, **args):
20 self.quitting = 1
21
22 def open_app(self, **args):
23 pass
24
25 def cgihandler(self, pathargs, **args):
26 rv = """HTTP/1.0 200 OK
Just van Rossum158ce422000-03-26 10:12:26 +000027Server: Unknown; python-cgi-script
Jack Jansen5a1a1751996-09-09 01:47:24 +000028MIME-Version: 1.0
29Content-type: text/html
30
31<title>Python CGI-script results</title>
32<h1>Python CGI-script results</h1>
33<hr>
34"""
35 rv = rv+'<br><b>Direct object:</b> %s\n'%pathargs
36
37 for key in args.keys():
38 if key[0] != '_':
39 rv = rv + '<br><b>%s:</b> %s\n'%(key, args[key])
40 rv = rv +'<hr>\nSee you next time!\n'
41
42 # Note: if you want to quit after each request enable the line
43 # self.quitting = 1
44
45 return rv
46
47if __name__ == '__main__':
48 CGITest()