Re: [Zope] ZServer serving CGI by itself
Eric, Thank you very much for the example code. That basically does what I want. However, I have a couple of added complexities. First, I have a lot of scripts, not just one. I'd like to have the equivalent of a ScriptAlias in Apache, where I can tell Zope to treat everything in a certain directory as a CGI script. Second, my scripts do funky things like set cookies for authentication. So I need to tell Zope to basically get out of the way after calling the CGI script. (Specifically, I don't want Zope sending the HTTP header.) Third, some of my scripts are long running processes and I'd like to be able to send results back to the client unbuffered. With Apache 1.3.x, I'm able to run Python scripts with the -u flag to the Python interpreter to force unbuffered output (i.e. you see the progress instead of having to wait for the script to finish). I'm thinking of writing a CGIScript product to handle this. My idea is that I could add a CGIScript object to any Zope folder, setting parameters as appropriate. Parameters could include: 1) name of CGI script to execute on host machine or name of directory containing CGI scripts 2) buffer output 3) script sends HTTP headers 4) environment variables 5) exception handling Has a general CGI product in Zope already been done? I've already written a few external methods in testing Zope, which is easy enough, but haven't yet tried to write a product. How hard is it? Anyone have any advice (aside from go with the flow and run Zope behind Apache)? Thanks, Fred P.S. Is standard_error_message broken in Zope 2.2.2? I couldn't figure out how to use error_value without the code in lib/python/ZPublisher/HTTPResponse.py throwing in extra tags. I finally just edited that file and things seem to be working. Running with or without the -D flag didn't make any difference. Eric Walstad wrote: > > I have a C++ program I run from Zope and then return the results to Zope. > Just like you described, I farm the work out to an external method which > runs the CGI, grabs the results and hands them back to Zope. Be sure to > hard code the line that calls your CGI. Otherwise, the External Method > could be used to call any (potentially damaging) code on your Linux box. [snip] ___ Zope maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
RE: [Zope] ZServer serving CGI by itself
Oops, replace "gashtg" with "interestingValue" below. Sorry I missed t. -E ... "ws.calc.results.gashtg"> should be ... "ws.calc.results.interestingValue"> ___ Zope maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
RE: [Zope] ZServer serving CGI by itself
Hi Fred, // I haven't seen any documentation on how to add CGI capability to Zope. // // Before I spend my time writing a product or external method that allows // me to call CGI programs from inside Zope, has anyone else already done // this? I have a C++ program I run from Zope and then return the results to Zope. Just like you described, I farm the work out to an external method which runs the CGI, grabs the results and hands them back to Zope. Be sure to hard code the line that calls your CGI. Otherwise, the External Method could be used to call any (potentially damaging) code on your Linux box. The (simplified) DTML Method "displayResults": <- This creates and initializes an object with the External Method The initial gas heating usage: The simulation method is invoked: <- This invokes the Simulate method of the ws object, which is what calls the CGI The gas heating usage after the simulation: <- this displays the results of the CGI call The (simplified) External Method "CWebCGI": import sys, os, string class CResults: "Container for results" def __init__(self): self.interestingValue = 0.0 class CCalc: "Container for calculation data" def __init__(self): self.results = CResults() self.parameters = "enter your CGI's parameter(s) here (if any)"# Note this file is on the Linux Hard Drive, not the ZODB class CWebCGI: "Container for the simulation" def __init__(self): self.calc = CCalc() self.execPath = "/path/to/the/CGIprogram"# Note this file is on the Linux Hard Drive, not the ZODB. def simulate(self): f = os.popen(self.execPath + " " + self.calc.parameters) lines = f.readlines() # grab the output of the CGI here status = f.close() self.calc.results.interestingValue = string.split(lines[0], "=")[1] def wsFactory():# <- This is the "Function Name" of the External Method return CWebCGI() // // Thanks for the bandwidth, // Fred Hope it helps, Eric. ___ Zope maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )