[Python-checkins] r85203 - in python/branches/release31-maint: Lib/http/server.py Lib/test/test_httpservers.py
senthil.kumaran
python-checkins at python.org
Sun Oct 3 20:04:52 CEST 2010
Author: senthil.kumaran
Date: Sun Oct 3 20:04:52 2010
New Revision: 85203
Log:
Merged revisions 85202 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k
........
r85202 | senthil.kumaran | 2010-10-03 23:25:45 +0530 (Sun, 03 Oct 2010) | 4 lines
Fix Issue9272 - Change CGIHTTPServer to give the child program a copy of os.environ
........
Modified:
python/branches/release31-maint/ (props changed)
python/branches/release31-maint/Lib/http/server.py
python/branches/release31-maint/Lib/test/test_httpservers.py
Modified: python/branches/release31-maint/Lib/http/server.py
==============================================================================
--- python/branches/release31-maint/Lib/http/server.py (original)
+++ python/branches/release31-maint/Lib/http/server.py Sun Oct 3 20:04:52 2010
@@ -99,6 +99,7 @@
import sys
import time
import urllib.parse
+import copy
# Default error message template
DEFAULT_ERROR_MESSAGE = """\
@@ -959,7 +960,7 @@
# Reference: http://hoohoo.ncsa.uiuc.edu/cgi/env.html
# XXX Much of the following could be prepared ahead of time!
- env = {}
+ env = copy.deepcopy(os.environ)
env['SERVER_SOFTWARE'] = self.version_string()
env['SERVER_NAME'] = self.server.server_name
env['GATEWAY_INTERFACE'] = 'CGI/1.1'
@@ -1024,7 +1025,6 @@
for k in ('QUERY_STRING', 'REMOTE_HOST', 'CONTENT_LENGTH',
'HTTP_USER_AGENT', 'HTTP_COOKIE', 'HTTP_REFERER'):
env.setdefault(k, "")
- os.environ.update(env)
self.send_response(200, "Script output follows")
@@ -1056,7 +1056,7 @@
pass
os.dup2(self.rfile.fileno(), 0)
os.dup2(self.wfile.fileno(), 1)
- os.execve(scriptfile, args, os.environ)
+ os.execve(scriptfile, args, env)
except:
self.server.handle_error(self.request, self.client_address)
os._exit(127)
@@ -1081,7 +1081,8 @@
p = subprocess.Popen(cmdline,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
- stderr=subprocess.PIPE
+ stderr=subprocess.PIPE,
+ env = env
)
if self.command.lower() == "post" and nbytes > 0:
data = self.rfile.read(nbytes)
Modified: python/branches/release31-maint/Lib/test/test_httpservers.py
==============================================================================
--- python/branches/release31-maint/Lib/test/test_httpservers.py (original)
+++ python/branches/release31-maint/Lib/test/test_httpservers.py Sun Oct 3 20:04:52 2010
@@ -470,6 +470,13 @@
self.assertEquals((b'Hello World\n', 'text/html', 200),
(res.read(), res.getheader('Content-type'), res.status))
+ def test_os_environ_is_not_altered(self):
+ signature = "Test CGI Server"
+ os.environ['SERVER_SOFTWARE'] = signature
+ res = self.request('/cgi-bin/file1.py')
+ self.assertEqual((b'Hello World\n', 'text/html', 200),
+ (res.read(), res.getheader('Content-type'), res.status))
+ self.assertEqual(os.environ['SERVER_SOFTWARE'], signature)
def test_main(verbose=None):
try:
More information about the Python-checkins
mailing list