Jack Jansen | 5a1a175 | 1996-09-09 01:47:24 +0000 | [diff] [blame] | 1 | """cgitest - A minimal CGI applet. Echos parameters back to the client. |
| 2 | """ |
| 3 | |
| 4 | from MiniAEFrame import AEServer, MiniApplication |
| 5 | |
| 6 | class 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 Jansen | e504fa2 | 1998-09-30 09:11:51 +0000 | [diff] [blame^] | 14 | oldparams = MacOS.SchedParams(0, 0) |
Jack Jansen | 5a1a175 | 1996-09-09 01:47:24 +0000 | [diff] [blame] | 15 | self.mainloop() |
Jack Jansen | e504fa2 | 1998-09-30 09:11:51 +0000 | [diff] [blame^] | 16 | apply(MacOS.SchedParams, oldparams) |
Jack Jansen | 5a1a175 | 1996-09-09 01:47:24 +0000 | [diff] [blame] | 17 | |
| 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 |
| 26 | Server: NetPresenz; python-cgi-script |
| 27 | MIME-Version: 1.0 |
| 28 | Content-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 | |
| 46 | if __name__ == '__main__': |
| 47 | CGITest() |