blob: e51cb9782079ae07e84b7f6885581236f7cd11f3 [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
Jack Jansen8eff33b2000-06-20 22:01:04 +00007debug=1
8
Jack Jansen5a1a1751996-09-09 01:47:24 +00009class CGITest(AEServer, MiniApplication):
10
11 def __init__(self):
12 MiniApplication.__init__(self)
13 AEServer.__init__(self)
14 self.installaehandler('aevt', 'oapp', self.open_app)
15 self.installaehandler('aevt', 'quit', self.quit)
16 self.installaehandler('WWW\275', 'sdoc', self.cgihandler)
Jack Jansen8eff33b2000-06-20 22:01:04 +000017 if debug:
18 self.installaehandler('****', '****', self.otherhandler)
Jack Jansene504fa21998-09-30 09:11:51 +000019 oldparams = MacOS.SchedParams(0, 0)
Jack Jansen5a1a1751996-09-09 01:47:24 +000020 self.mainloop()
Jack Jansene504fa21998-09-30 09:11:51 +000021 apply(MacOS.SchedParams, oldparams)
Jack Jansen5a1a1751996-09-09 01:47:24 +000022
23 def quit(self, **args):
24 self.quitting = 1
25
26 def open_app(self, **args):
27 pass
Jack Jansen8eff33b2000-06-20 22:01:04 +000028
29 def otherhandler(self, *args, **kwargs):
30 print 'Unknown AppleEvent'
31 print 'args', args
32 print 'kwargs', kwargs
33
Jack Jansen5a1a1751996-09-09 01:47:24 +000034 def cgihandler(self, pathargs, **args):
Jack Jansen8eff33b2000-06-20 22:01:04 +000035 if debug:
36 print 'CGI request', pathargs, args
Jack Jansen5a1a1751996-09-09 01:47:24 +000037 rv = """HTTP/1.0 200 OK
Just van Rossum158ce422000-03-26 10:12:26 +000038Server: Unknown; python-cgi-script
Jack Jansen5a1a1751996-09-09 01:47:24 +000039MIME-Version: 1.0
40Content-type: text/html
41
42<title>Python CGI-script results</title>
43<h1>Python CGI-script results</h1>
44<hr>
45"""
46 rv = rv+'<br><b>Direct object:</b> %s\n'%pathargs
47
48 for key in args.keys():
49 if key[0] != '_':
50 rv = rv + '<br><b>%s:</b> %s\n'%(key, args[key])
51 rv = rv +'<hr>\nSee you next time!\n'
52
53 # Note: if you want to quit after each request enable the line
54 # self.quitting = 1
55
56 return rv
57
58if __name__ == '__main__':
59 CGITest()