def test_pathInfo(self): """ L{twcgi.CGIScript.render} sets the process environment I{PATH_INFO} from the request path. """ class FakeReactor: """ A fake reactor recording the environment passed to spawnProcess. """ def spawnProcess(self, process, filename, args, env, wdir): """ Store the C{env} L{dict} to an instance attribute. @param process: Ignored @param filename: Ignored @param args: Ignored @param env: The environment L{dict} which will be stored @param wdir: Ignored """ self.process_env = env _reactor = FakeReactor() resource = twcgi.CGIScript(self.mktemp(), reactor=_reactor) request = DummyRequest(['a', 'b']) _render(resource, request) self.assertEqual(_reactor.process_env["PATH_INFO"], "/a/b")
from twisted.internet import reactor from twisted.web import static, server, twcgi root = static.File("/root") root.putChild("login.cgi", twcgi.CGIScript("/var/www/cgi-bin/login.py")) reactor.listenTCP(80, server.Site(root)) reactor.run()
class Parent(rend.Page): child_child = twcgi.CGIScript('abc.cgi')
def addCGIDir(resource, path, filterF=None): files = [f for f in os.listdir(path) if filterF and filterF(f)] for f in files: resource.putChild(f, twcgi.CGIScript(os.path.join(path, f))) return files