Bug in CGIHTTPServer?

Lucio Torre lucio at movilogic.com
Mon Jan 14 11:37:39 EST 2002


Ive been playing with the CGIHTTPServer in the python 2.1 library. I 
dont know if this is fixed in 2.2.

As i did some tweaks when subclassing, i dont know if this error is in 
the lib or my code, but i think its in the lib, or at least thats where 
i fixed it.

The problem is that on Windows2000, when executing a script that resides 
in a directory that has a space on its name, the popen fails.

So in:

def run_cgi(self):
        """Execute a CGI script."""
        {...}
        elif self.have_popen2:
            # Windows -- use popen2 to create a subprocess
            import shutil
            os.environ.update(env)
            cmdline = scriptfile
            if self.is_python(scriptfile):
                interp = sys.executable
                if interp.lower().endswith("w.exe"):
                    # On Windows, use python.exe, not python.exe
                    interp = interp[:-5] = interp[-4:]
                cmdline = "%s %s" % (interp, cmdline)
            {...}
i changed: the last line to:
                cmdline = "%s \"%s\"" % (interp, cmdline)

Now it works.

Just in case i somehow messed with sciptfile, here is my subclass of 
CGIHTTPServer:

class autochino_server(CGIHTTPServer.CGIHTTPRequestHandler):
   def do_GET(self):
      """Serve a GET request."""
      if not self.is_cgi():
         f = self.send_head()
         if f:
             self.copyfile(f, self.wfile)
             f.close()
      else:           
         self.run_cgi()

   def is_cgi(self):
      """Test whether self.path corresponds to a CGI script.

      Return a tuple (dir, rest) if self.path requires running a
      CGI script, None if not.  Note that rest begins with a
      slash if it is not empty.

      The default implementation tests whether the path
      begins with one of the strings in the list
      self.cgi_directories (and the next character is a '/'
      or the end of the string).

      """

      path = self.path
      print path
      i = os.path.split(path)[1].rfind("?")
      if i >= 0:
         self.cgi_info = os.path.split(path)[0], os.path.split(path)[1]
         return 1
      if  self.is_python(path):
         self.cgi_info = os.path.split(path)[0], os.path.split(path)[1]
         return 1

      for x in self.cgi_directories:
         i = len(x)
         if path[:i] == x and (not path[i:] or path[i] == '/'):
             self.cgi_info = path[:i], path[i+1:]
             return 1
      return 0           


Dont know what elase to do, so just letting everyone know.

Lucio.






More information about the Python-list mailing list