mirror of
https://github.com/python/cpython.git
synced 2025-07-29 14:15:07 +00:00
[Bug #737202; fix from Titus Brown] Make CGIHTTPServer work for scripts in sub-directories
This commit is contained in:
parent
eabc0e87af
commit
b29069d6b6
1 changed files with 19 additions and 0 deletions
|
@ -105,17 +105,36 @@ class CGIHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
|
||||||
|
|
||||||
def run_cgi(self):
|
def run_cgi(self):
|
||||||
"""Execute a CGI script."""
|
"""Execute a CGI script."""
|
||||||
|
path = self.path
|
||||||
dir, rest = self.cgi_info
|
dir, rest = self.cgi_info
|
||||||
|
|
||||||
|
i = path.find('/', len(dir) + 1)
|
||||||
|
while i >= 0:
|
||||||
|
nextdir = path[:i]
|
||||||
|
nextrest = path[i+1:]
|
||||||
|
|
||||||
|
scriptdir = self.translate_path(nextdir)
|
||||||
|
if os.path.isdir(scriptdir):
|
||||||
|
dir, rest = nextdir, nextrest
|
||||||
|
i = path.find('/', len(dir) + 1)
|
||||||
|
else:
|
||||||
|
break
|
||||||
|
|
||||||
|
# find an explicit query string, if present.
|
||||||
i = rest.rfind('?')
|
i = rest.rfind('?')
|
||||||
if i >= 0:
|
if i >= 0:
|
||||||
rest, query = rest[:i], rest[i+1:]
|
rest, query = rest[:i], rest[i+1:]
|
||||||
else:
|
else:
|
||||||
query = ''
|
query = ''
|
||||||
|
|
||||||
|
# dissect the part after the directory name into a script name &
|
||||||
|
# a possible additional path, to be stored in PATH_INFO.
|
||||||
i = rest.find('/')
|
i = rest.find('/')
|
||||||
if i >= 0:
|
if i >= 0:
|
||||||
script, rest = rest[:i], rest[i:]
|
script, rest = rest[:i], rest[i:]
|
||||||
else:
|
else:
|
||||||
script, rest = rest, ''
|
script, rest = rest, ''
|
||||||
|
|
||||||
scriptname = dir + '/' + script
|
scriptname = dir + '/' + script
|
||||||
scriptfile = self.translate_path(scriptname)
|
scriptfile = self.translate_path(scriptname)
|
||||||
if not os.path.exists(scriptfile):
|
if not os.path.exists(scriptfile):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue