[Pythonmac-SIG] More Mac CGI

Just van Rossum just@letterror.com
Sun, 26 Mar 2000 14:41:31 +0100


I managed to install an evaluation copy of WebStar -- the "active
installer" contains all neccesary files for a minimal HTTP server setup, so
there's no need to download the full 44 megs. The pythoncgislave.py script
I posted earlier does not work as is, because I can't find a way to make
WebStar launch *.py (or whatever extension) files with a different app,
like I did in the past with Quid Pro Quo. So it seems the CGI *must* be an
applet under WebStar.

The good news is that I managed to repair Jack's CGI demo, like so:
- add the line "import MacOS" somewhere at the top of the realcgitest.py scr=
ipt
- drop cgitest.cgi.rsrc onto EditPython prefs, choose "Default startup
options..." and check "Disable argc/argv emulation". This is essential,
since if it's not checked the first AE's sent to the applet get eaten by
the argv emulation code.

Both changes have been checked in into the CVS repository.

I now understand slightly better what MacPerl does (thanks J=F6rg) and I
think we can duplicate this easily in MacPython: a CGI script needs to be
wrapped in something that's *very* similar to Jack's realcgitest.py script.
This could be done by an applet called "BuildCGIApplet". A .py file dropped
on it will be converted to a .cgi applet.

As I wrote before, the wrapper code translates as many parameters and
headers from the AE to compatible os.eviron key/values as possible, and
then executes the real cgi program, which will reside inside the CGI applet
as bytecode in a 'PYC ' resource.

Jack's demo will not quit once started; I think this is good default
behavior since it saves an enormous amount of startup overhead each time
the CGI gets executed. We only need to be careful with memory leaks: maybe
just clearing the globals dict after the CGI has run is enough. An
additional safety measure could be to add a try/except around the mainloop
call, and quit upon an exception. Tracebacks should be printed to stderr,
stderr needs to be redirected to a log file.

Does this sound like a plan?

I will try and work a little on these ideas, feedback is welcome of course.

Just