[Patches] [ python-Patches-508730 ] CGIHTTPServer execfile should save cwd
SourceForge.net
noreply@sourceforge.net
Fri, 16 May 2003 17:47:28 -0700
Patches item #508730, was opened at 2002-01-25 15:41
Message generated for change (Comment added) made by bcannon
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=508730&group_id=5470
>Category: None
>Group: None
Status: Open
Resolution: None
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: Brett Cannon (bcannon)
Date: 2003-05-16 17: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 15: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 15: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