blob: 5b45ed457e0b6d3388dfa861a4b3038703b29456 [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
5
6class CGITest(AEServer, MiniApplication):
7
8 def __init__(self):
9 MiniApplication.__init__(self)
10 AEServer.__init__(self)
11 self.installaehandler('aevt', 'oapp', self.open_app)
12 self.installaehandler('aevt', 'quit', self.quit)
13 self.installaehandler('WWW\275', 'sdoc', self.cgihandler)
Jack Jansene504fa21998-09-30 09:11:51 +000014 oldparams = MacOS.SchedParams(0, 0)
Jack Jansen5a1a1751996-09-09 01:47:24 +000015 self.mainloop()
Jack Jansene504fa21998-09-30 09:11:51 +000016 apply(MacOS.SchedParams, oldparams)
Jack Jansen5a1a1751996-09-09 01:47:24 +000017
18 def quit(self, **args):
19 self.quitting = 1
20
21 def open_app(self, **args):
22 pass
23
24 def cgihandler(self, pathargs, **args):
25 rv = """HTTP/1.0 200 OK
26Server: NetPresenz; python-cgi-script
27MIME-Version: 1.0
28Content-type: text/html
29
30<title>Python CGI-script results</title>
31<h1>Python CGI-script results</h1>
32<hr>
33"""
34 rv = rv+'<br><b>Direct object:</b> %s\n'%pathargs
35
36 for key in args.keys():
37 if key[0] != '_':
38 rv = rv + '<br><b>%s:</b> %s\n'%(key, args[key])
39 rv = rv +'<hr>\nSee you next time!\n'
40
41 # Note: if you want to quit after each request enable the line
42 # self.quitting = 1
43
44 return rv
45
46if __name__ == '__main__':
47 CGITest()