mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Revert os.py 1.75, and directly implement update.
Fixes #1110478 and #1100235.
This commit is contained in:
parent
3069dbb8ec
commit
1d11de6dbd
3 changed files with 31 additions and 0 deletions
22
Lib/os.py
22
Lib/os.py
|
@ -442,6 +442,17 @@ else:
|
||||||
return key.upper() in self.data
|
return key.upper() in self.data
|
||||||
def get(self, key, failobj=None):
|
def get(self, key, failobj=None):
|
||||||
return self.data.get(key.upper(), failobj)
|
return self.data.get(key.upper(), failobj)
|
||||||
|
def update(self, dict=None, **kwargs):
|
||||||
|
if dict:
|
||||||
|
try:
|
||||||
|
items = dict.items()
|
||||||
|
except AttributeError:
|
||||||
|
# List of (key, value)
|
||||||
|
items = dict
|
||||||
|
for k, v in items:
|
||||||
|
self[k] = v
|
||||||
|
if kwargs:
|
||||||
|
self.update(kwargs)
|
||||||
def copy(self):
|
def copy(self):
|
||||||
return dict(self)
|
return dict(self)
|
||||||
|
|
||||||
|
@ -453,6 +464,17 @@ else:
|
||||||
def __setitem__(self, key, item):
|
def __setitem__(self, key, item):
|
||||||
putenv(key, item)
|
putenv(key, item)
|
||||||
self.data[key] = item
|
self.data[key] = item
|
||||||
|
def update(self, dict=None, **kwargs):
|
||||||
|
if dict:
|
||||||
|
try:
|
||||||
|
items = dict.items()
|
||||||
|
except AttributeError:
|
||||||
|
# List of (key, value)
|
||||||
|
items = dict
|
||||||
|
for k, v in items:
|
||||||
|
self[k] = v
|
||||||
|
if kwargs:
|
||||||
|
self.update(kwargs)
|
||||||
try:
|
try:
|
||||||
unsetenv
|
unsetenv
|
||||||
except NameError:
|
except NameError:
|
||||||
|
|
|
@ -226,6 +226,13 @@ class EnvironTests(mapping_tests.BasicTestMappingProtocol):
|
||||||
os.environ.clear()
|
os.environ.clear()
|
||||||
os.environ.update(self.__save)
|
os.environ.update(self.__save)
|
||||||
|
|
||||||
|
# Bug 1110478
|
||||||
|
def test_update(self):
|
||||||
|
if os.path.exists("/bin/sh"):
|
||||||
|
os.environ.update(HELLO="World")
|
||||||
|
value = os.popen("/bin/sh -c 'echo $HELLO'").read().strip()
|
||||||
|
self.assertEquals(value, "World")
|
||||||
|
|
||||||
class WalkTests(unittest.TestCase):
|
class WalkTests(unittest.TestCase):
|
||||||
"""Tests for os.walk()."""
|
"""Tests for os.walk()."""
|
||||||
|
|
||||||
|
|
|
@ -45,6 +45,8 @@ Extension Modules
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- Bug #1110478: Revert os.environ.update to do putenv again.
|
||||||
|
|
||||||
- Bug #1103844: fix distutils.install.dump_dirs() with negated options.
|
- Bug #1103844: fix distutils.install.dump_dirs() with negated options.
|
||||||
|
|
||||||
- os.{SEEK_SET, SEEK_CUR, SEEK_END} have been added for convenience.
|
- os.{SEEK_SET, SEEK_CUR, SEEK_END} have been added for convenience.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue