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 |
Just van Rossum | 158ce42 | 2000-03-26 10:12:26 +0000 | [diff] [blame] | 5 | import MacOS |
Jack Jansen | 5a1a175 | 1996-09-09 01:47:24 +0000 | [diff] [blame] | 6 | |
| 7 | class 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 Jansen | e504fa2 | 1998-09-30 09:11:51 +0000 | [diff] [blame] | 15 | oldparams = MacOS.SchedParams(0, 0) |
Jack Jansen | 5a1a175 | 1996-09-09 01:47:24 +0000 | [diff] [blame] | 16 | self.mainloop() |
Jack Jansen | e504fa2 | 1998-09-30 09:11:51 +0000 | [diff] [blame] | 17 | apply(MacOS.SchedParams, oldparams) |
Jack Jansen | 5a1a175 | 1996-09-09 01:47:24 +0000 | [diff] [blame] | 18 | |
| 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 Rossum | 158ce42 | 2000-03-26 10:12:26 +0000 | [diff] [blame] | 27 | Server: Unknown; python-cgi-script |
Jack Jansen | 5a1a175 | 1996-09-09 01:47:24 +0000 | [diff] [blame] | 28 | MIME-Version: 1.0 |
| 29 | Content-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 | |
| 47 | if __name__ == '__main__': |
| 48 | CGITest() |