[Pythonmac-SIG] MacPython, CGI and free cd's

Just van Rossum just@letterror.com
Thu, 3 Aug 2000 15:42:59 +0100


At 12:30 PM +0200 03-08-2000, Jack Jansen wrote:
>Will something simple like dropping the applet in the server's CGI directory
>work?

With PythonCGISlave? No. It does if you run your script through
BuildCGIApplet, which will create a .cgi applet ready to roll.
Unfortunately for every change you will have to create the applet again.

For PythonCGISlave, you need to configure the server so it directs any *.py
requests to the PythonCGISlave applet. I think in most (Mac) web servers
this is called an "action handler". The disadvantage (as well as advantage,
once the script works) of this method is that modules don't get reloaded
upon each request; if you edit a module, you're forced to either do a
reload() in your script, or quit PythonCGISlave by hand. However, for
debugging, PythonCGISlave can be configured to quit after each request, by
setting the global variable LONG_RUNNING to 0.

>If we can explain this is a few simple sentences for Personal Websharing
>I think we're all set. Personal Websharing is what everyone will start with
>nowadays, as it's included in MacOS, so I guess we can safely assume that
>anyone who has a more powerful server will also have the knowledge about
>where
>to put CGI stuff for their brand of server.

Also good points. Unfortunately I'm still running an ancient OS (8.1), so I
don't have PWS yet to play with.

[ ... ]
>But why wouldn't we do something nicer for Python users?

You mean create something portable? Or do you mean _Mac_Python users?

>Putting the
>try/except in the wrapper, for instance (the user can always override it with
>another try/exceept in their script).

I don't see why we should create different default behavior than for unix.

>Also, on unix you can test your CGI script with something like
>% QUERY_STRING=arg+arg+arg cgi-bin/myscript
>but on the mac this isn't possible, but we could easily provide some help.

Ah, but that's an entirely different problem I'd say. How about a *very*
simple wrapper, as an applet called, say, TestCGIScript:

import sys, os
import EasyDialogs

if len(sys.argv) <> 2:
	print "please drop exactly one cgi script on this applet"
	sys.exit(1)

query = EasyDialogs.AskString("Enter query string:")
if query:
	script = sys.argv[1]
	namespace = {"__name__": "__main__"}
	os.environ["QUERY_STRING"] = query
	execfile(script, namespace)

>Hmm, maybe this should be folded into the IDE? If you could "Run as CGI" from
>the IDE and then "Save as CGI" (which would save in the right place, copy the
>applet, etc) we would be giving people a pretty decent CGI development
>environment...

And make the UI even messier than it already is? ;-)

Just