This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: os.environ.update doesn't work
Type: Stage:
Components: Library (Lib) Versions: Python 2.4
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: juneaftn, loewis
Priority: normal Keywords:

Created on 2005-01-27 07:22 by juneaftn, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (4)
msg24066 - (view) Author: June Kim (juneaftn) Date: 2005-01-27 07:22
os.environ.update doesn't really update os.environ --
it doesn't call putenv subsequently.

This is the test code:

#test1.py
import os
FILENAME='test2.py'
env={};env['ENVIRON_UPDATE']='123';os.environ.update(env)
os.environ['ENVIRON_DIRECT_SETTING']='123'
cmdline='c:\python24\python.exe -u %s'%FILENAME
fs=os.popen3(cmdline,'b')
print fs[1].read()

#test2.py
import os
if os.environ.has_key('ENVIRON_UPDATE'):print
'os.env.update worked'
else:print 'os.env.update failed'
if os.environ.has_key('ENVIRON_DIRECT_SETTING'):print
'os.env assignment worked'
else:print 'os.env assignment failed'

Run test1.py with python 2.4 on windows.

The reason os.environ.update doesn't work is the update
method is removed from 2.4. (It works with 2.3)

Following is the patch:

--- os.py       Thu Jan 27 07:09:38 2005
+++ os_new.py   Thu Jan 27 07:10:44 2005
@@ -435,6 +435,9 @@
                 return key.upper() in self.data
             def get(self, key, failobj=None):
                 return self.data.get(key.upper(), failobj)
+            def update(self, dict):
+                for k, v in dict.items():
+                    self[k] = v
             def copy(self):
                 return dict(self)

@@ -446,6 +449,9 @@
             def __setitem__(self, key, item):
                 putenv(key, item)
                 self.data[key] = item
+            def update(self, dict):
+                for k, v in dict.items():
+                    self[k] = v
             try:
                 unsetenv
             except NameError:
msg24067 - (view) Author: June Kim (juneaftn) Date: 2005-01-27 07:22
Logged In: YES 
user_id=116941

This is the cause of the cgi bug #1100235.
msg24068 - (view) Author: June Kim (juneaftn) Date: 2005-01-27 07:39
Logged In: YES 
user_id=116941

The update methods in os.py were removed in the Revision
1.75. Thu Mar 4 08:25:44 2004 UTC according to the cvs.
msg24069 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2005-01-29 13:34
Logged In: YES 
user_id=21627

Thanks for the report. Fixed in

os.py 1.85
test_os.py 1.29
NEWS 1.1235
os.py 1.83.2.1
NEWS 1.1193.2.17
History
Date User Action Args
2022-04-11 14:56:09adminsetgithub: 41497
2005-01-27 07:22:12juneaftncreate