[Patches] [ python-Patches-508730 ] CGIHTTPServer execfile should
save cwd
SourceForge.net
noreply at sourceforge.net
Sat Mar 20 17:03:34 EST 2004
Patches item #508730, was opened at 2002-01-25 18:41
Message generated for change (Comment added) made by tim_one
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=508730&group_id=5470
Category: None
Group: None
>Status: Closed
>Resolution: Accepted
Priority: 5
Submitted By: Dan Grassi (dgrassi)
Assigned to: Nobody/Anonymous (nobody)
Summary: CGIHTTPServer execfile should save cwd
Initial Comment:
In CGIHTTPServer when running a script via execfile the
cwd is not saved and restored. If the executed script
changes the cwd subsequent requests will fail because
self.translate_path in SimpleHTTPServer relies on the
cwd.
One fix is to suround the execfile call with
save_cwd = os.getcwd()
and
os.chdir(save_cwd)
Here is the proposed fix starting at line 254:
+ save_cwd = os.getcwd()
try:
try:
sys.argv = [scriptfile]
if '=' not in decoded_query:
sys.argv.append(decoded_query)
sys.stdout = self.wfile
sys.stdin = self.rfile
execfile(scriptfile, {"__name__":
"__main__"})
finally:
+ os.chdir(save_cwd)
----------------------------------------------------------------------
>Comment By: Tim Peters (tim_one)
Date: 2004-03-20 17:03
Message:
Logged In: YES
user_id=31435
I checked this in, but have no idea how to test it. In part
that's because the execfile path doesn't appear to be taken
on Unixish *or* Windows systems. Is this entire block of
code actually unreachable (== is there an OS now that
doesn't have fork or popen2 or popen3?).
Lib/CGIHTTPServer.py; new revision: 1.34
----------------------------------------------------------------------
Comment By: A.M. Kuchling (akuchling)
Date: 2003-10-24 08:14
Message:
Logged In: YES
user_id=11375
It looks like a bug worth fixing, and the proposed patch seems reasonable.
----------------------------------------------------------------------
Comment By: Brett Cannon (bcannon)
Date: 2003-05-16 20:47
Message:
Logged In: YES
user_id=357491
Since a patch is in the comments I am making this a patch instead of a bug.
As for the idea, it seems good to me. Anyone else care to comment?
----------------------------------------------------------------------
Comment By: Dan Grassi (dgrassi)
Date: 2002-01-25 18:55
Message:
Logged In: YES
user_id=366473
Here is the (hopefully) properly indented fix:
+ save_cwd = os.getcwd()
try:
try:
sys.argv = [scriptfile]
if '=' not in decoded_query:
sys.argv.append(decoded_query)
sys.stdout = self.wfile
sys.stdin = self.rfile
execfile(scriptfile, {"__name__": "__main__"})
finally:
+ os.chdir(save_cwd)
----------------------------------------------------------------------
Comment By: Dan Grassi (dgrassi)
Date: 2002-01-25 18:48
Message:
Logged In: YES
user_id=366473
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=508730&group_id=5470
More information about the Patches
mailing list