[Patches] [ python-Patches-508730 ] CGIHTTPServer execfile should save cwd

SourceForge.net noreply at sourceforge.net
Fri Oct 24 08:14:05 EDT 2003


Patches item #508730, was opened at 2002-01-25 18:41
Message generated for change (Comment added) made by akuchling
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: 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