--- mod_python_handler.py.orig	2004-05-04 16:01:32.000000000 -0700
+++ mod_python_handler.py	2004-05-04 17:32:27.000000000 -0700
@@ -21,6 +21,42 @@
     def close(self):
         pass
 
+def build_cgi_env(req):
+    """Call apache.build_cgi_env() and fix the result."""
+    env = dict(apache.build_cgi_env(req))
+
+    script_parts = env.get('SCRIPT_NAME').split('/')
+    path_parts = env.get('PATH_INFO', '').split('/')[1:] # should always start with '/' or be ''
+    filename_parts = env.get('SCRIPT_FILENAME').split('/')
+
+    path_parts.reverse()
+    while len(script_parts) > 2: # don't check beyond the 'base' script
+        if script_parts[-1] != filename_parts[-1]:
+            if not script_parts[-1]: # sometimes there are trailing '/'s in the script name
+                script_parts.pop()
+                continue
+            break
+        path_parts.append(script_parts.pop())
+        filename_parts.pop()
+    if path_parts:
+        path_parts.append('') # ensure a leading '/'
+    path_parts.reverse()
+
+    script_name = '/'.join(script_parts)
+    path_info = '/'.join(path_parts)
+    filename = '/'.join(filename_parts)
+    doc_root = env.get('DOCUMENT_ROOT')
+
+    # covers most cases of VirtualHost and doesn't break the ones it doesn't
+    if doc_root + script_name[1:] == filename:
+        env['PATH_INFO'] = script_name + path_info
+        env['SCRIPT_NAME'] = ''
+    else:
+        env['PATH_INFO'] = path_info
+        env['SCRIPT_NAME'] = script_name
+
+    return env
+
 class ModPythonPublisher(Publisher):
     def __init__(self, package, config=None):
         Publisher.__init__(self, package, config)
@@ -47,7 +83,7 @@
             self.publish(apache.CGIStdin(req),
                          apache.CGIStdout(req),
                          sys.stderr,
-                         apache.build_cgi_env(req))
+                         build_cgi_env(req))
 
             return apache.OK
         finally:
@@ -67,7 +103,7 @@
     try:
         configfile = opts['quixote-config-file']
         config = Config()
-        config.read_file(self, configfile)
+        config.read_file(configfile)
     except KeyError:
         config = None
 
