From 4011723d0d27d96dc82cf42b31576929522477b6 Mon Sep 17 00:00:00 2001 From: Just van Rossum Date: Tue, 28 Mar 2000 12:05:13 +0000 Subject: - new version of PythonCGISlave - new script/applet BuildCGIApplet This largely supercedes :Mac:Demos:cgi, except for the html doc file. Should it move here? Merged with CGI_README.txt? Todo: fullbuild support. (jvr) --- Mac/Tools/CGI/BuildCGIApplet.py | 74 ++++++++++++ Mac/Tools/CGI/BuildCGIApplet.rsrc | Bin 0 -> 460 bytes Mac/Tools/CGI/CGI_README.txt | 66 +++++++++++ Mac/Tools/CGI/PythonCGISlave.py | 243 ++++++++++++++++++++++++++++++++++++++ Mac/Tools/CGI/PythonCGISlave.rsrc | Bin 0 -> 460 bytes 5 files changed, 383 insertions(+) create mode 100644 Mac/Tools/CGI/BuildCGIApplet.py create mode 100644 Mac/Tools/CGI/BuildCGIApplet.rsrc create mode 100644 Mac/Tools/CGI/CGI_README.txt create mode 100644 Mac/Tools/CGI/PythonCGISlave.py create mode 100644 Mac/Tools/CGI/PythonCGISlave.rsrc diff --git a/Mac/Tools/CGI/BuildCGIApplet.py b/Mac/Tools/CGI/BuildCGIApplet.py new file mode 100644 index 0000000..29783c2 --- /dev/null +++ b/Mac/Tools/CGI/BuildCGIApplet.py @@ -0,0 +1,74 @@ +"""BuildCGIApplet.py -- Create a CGI applet from a Python script. + +Specilized version of BuildApplet, enabling Python CGI scripts to be +used under Mac web servers like WebStar. The __main__ program is +PythonCGISlave.py, which provides a compatibility layer, emulating +Unix-style CGI scripts. See CGI_README.txt for details. +""" + +import sys +import os +import macfs +import MacOS +import Res +import EasyDialogs +import buildtools +import py_resource + + +def main(): + try: + buildcgiapplet() + except buildtools.BuildError, detail: + EasyDialogs.Message(detail) + + +def buildcgiapplet(): + buildtools.DEBUG=1 + + # Find the template + # (there's no point in proceeding if we can't find it) + + template = buildtools.findtemplate() + wrapper = os.path.join(sys.exec_prefix, ":Mac:Tools:CGI:PythonCGISlave.py") + + # Ask for source text if not specified in sys.argv[1:] + if not sys.argv[1:]: + srcfss, ok = macfs.PromptGetFile('Select a CGI script:', 'TEXT', 'APPL') + if not ok: + return + filename = srcfss.as_pathname() + dstfilename = mkcgifilename(filename) + dstfss, ok = macfs.StandardPutFile('Save application as:', + os.path.basename(dstfilename)) + if not ok: + return + dstfilename = dstfss.as_pathname() + buildone(template, wrapper, filename, dstfilename) + else: + # Loop over all files to be processed + for filename in sys.argv[1:]: + dstfilename = mkcgifilename(filename) + buildone(template, wrapper, filename, dstfilename) + + +def mkcgifilename(filename): + if filename[-3:] == '.py': + filename = filename[:-3] + filename = filename + ".cgi" + return filename + + +def buildone(template, wrapper, src, dst): + buildtools.process(template, wrapper, dst, 1) + # write source as a PYC resource into dst + ref = Res.OpenResFile(dst) + try: + Res.UseResFile(ref) + py_resource.frompyfile(src, "CGI_MAIN", preload=1) + finally: + Res.CloseResFile(ref) + + +if __name__ == '__main__': + main() diff --git a/Mac/Tools/CGI/BuildCGIApplet.rsrc b/Mac/Tools/CGI/BuildCGIApplet.rsrc new file mode 100644 index 0000000..6c9b6b5 Binary files /dev/null and b/Mac/Tools/CGI/BuildCGIApplet.rsrc differ diff --git a/Mac/Tools/CGI/CGI_README.txt b/Mac/Tools/CGI/CGI_README.txt new file mode 100644 index 0000000..89f559f --- /dev/null +++ b/Mac/Tools/CGI/CGI_README.txt @@ -0,0 +1,66 @@ +Python CGI under MacOS + +This folder contains two tools that enable Python CGI scripts under +Mac based web servers, like WebStar, Quid Quo Pro, NetPresentz or +Apple's Personal Webserver. + +Both tools emulate Unix style CGI's, allowing for cross platform +CGI scripts. In short, this happens by converting an AppleEvent sent +by the web server into os.environ dictionary entries. See below for more +details. + +Both tools serve slightly different purposes: +- PythonCGISlave enables execution of Python scripts as plain *.py + text files. The web server must be configured to handle .py requests + over to PythonCGISlave. Not all web servers support that. Eg. WebStar + does, but NetPresentz does not. +- BuildCGIApplet wraps a Python CGI script in a compatibility layer, and + creates a CGI Applet which can be executed by any web server. + +The pros and cons of using PythonCGISlave are (+ is good, - is bad): + + support plain .py files, no need to wrap each script + - not supported b all servers, requires more complicated configuration +The pros and cons of using BuildCGIApplet are: + + supported by more servers + + less configuration troubles + - must wrap each script + + +Using BuildCGIApplet + +Drop your CGI script onto BuildCGIApplet. An applet called