Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit da4d6da

Browse files
committed
Support case insensitive treatment of os.environ keys on Windows and
DOS (as well as OS/2). I presume that making a call to putenv() with a lowercase key will actually do the right thing. I know this is so on Windows/DOS, and I expect it is so OS/2 -- but the old OS/2 code didn't assume this. (I don't know if the person who provided the OS/2 patch was clueless or just didn't care about DOS and Windows.) Also ripped out the support for pickling -- as of 1.5, this is no longer needed to make pickling work.
1 parent 7f875ef commit da4d6da

1 file changed

Lines changed: 7 additions & 8 deletions

File tree

Lib/os.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -226,15 +226,19 @@ def _execvpe(file, args, env = None):
226226
else:
227227
import UserDict
228228

229-
if name in ('os2', ): # Where Env Var Names Must Be UPPERCASE
229+
if name in ('os2', 'nt', 'dos'): # Where Env Var Names Must Be UPPERCASE
230+
# But we store them as upper case
230231
import string
231232
class _Environ(UserDict.UserDict):
232233
def __init__(self, environ):
233234
UserDict.UserDict.__init__(self)
234-
self.data = environ
235+
data = self.data
236+
upper = string.upper
237+
for k, v in environ.items():
238+
data[upper(k)] = v
235239
def __setitem__(self, key, item):
236-
key = string.upper(key)
237240
putenv(key, item)
241+
key = string.upper(key)
238242
self.data[key] = item
239243
def __getitem__(self, key):
240244
return self.data[string.upper(key)]
@@ -244,13 +248,8 @@ class _Environ(UserDict.UserDict):
244248
def __init__(self, environ):
245249
UserDict.UserDict.__init__(self)
246250
self.data = environ
247-
def __getinitargs__(self):
248-
import copy
249-
return (copy.copy(self.data),)
250251
def __setitem__(self, key, item):
251252
putenv(key, item)
252253
self.data[key] = item
253-
def __copy__(self):
254-
return _Environ(self.data.copy())
255254

256255
environ = _Environ(environ)

0 commit comments

Comments
 (0)