OPSI.web2.twcgi module

I hold resource classes and helper classes that deal with CGI scripts.

Things which are still not working properly:

  • CGIScript.render doesn’t set REMOTE_ADDR or REMOTE_HOST in the environment
OPSI.web2.twcgi.createCGIEnvironment(request)
class OPSI.web2.twcgi.CGIDirectory(pathname)

Bases: OPSI.web2.resource.Resource, twisted.python.filepath.FilePath

A directory that serves only CGI scripts (to infinite depth) and does not support directory listings.

@param pathname: A path to the directory that you wish to serve
CGI scripts from, for example /var/www/cgi-bin/

@type pathname: str

addSlash = True
locateChild(request, segments)
render(request)
class OPSI.web2.twcgi.CGIScript(filename)

Bases: OPSI.web2.resource.LeafResource

I represent a CGI script.

My implementation is complex due to the fact that it requires asynchronous IPC with an external process with an unpleasant protocol.

http_POST(request)
render(request)

Do various things to conform to the CGI specification.

I will set up the usual slew of environment variables, then spin off a process.

class OPSI.web2.twcgi.FilteredScript(filename, filters=None)

Bases: OPSI.web2.twcgi.CGIScript

I am a special version of a CGI script, that uses a specific executable (or, the first existing executable in a list of executables).

This is useful for interfacing with other scripting languages that adhere to the CGI standard (cf. PHPScript). My ‘filters’ attribute specifies what executables to try to run, and my ‘filename’ init parameter describes which script to pass to the first argument of that script.

filters = ('/usr/bin/cat',)
render(request)
class OPSI.web2.twcgi.PHP3Script(filename, filters=None)

Bases: OPSI.web2.twcgi.FilteredScript

I am a FilteredScript that uses the default PHP3 command on most systems.

filters = ('/usr/bin/php3',)
class OPSI.web2.twcgi.PHPScript(filename, filters=None)

Bases: OPSI.web2.twcgi.FilteredScript

I am a FilteredScript that uses the PHP command on most systems. Sometimes, php wants the path to itself as argv[0]. This is that time.

filters = ('/usr/bin/php4-cgi', '/usr/bin/php4')