mirror of
https://github.com/python/cpython.git
synced 2025-08-29 21:25:01 +00:00
Issue #8603: Create a bytes version of os.environ for Unix
Create os.environb mapping and os.getenvb() function, os.unsetenv() encodes str argument to the file system encoding with the surrogateescape error handler (instead of utf8/strict) and accepts bytes, and posix.environ keys and values are bytes.
This commit is contained in:
parent
d930b63583
commit
84ae118006
7 changed files with 190 additions and 54 deletions
|
@ -803,8 +803,6 @@ class POSIXProcessTestCase(BaseTestCase):
|
|||
|
||||
def test_undecodable_env(self):
|
||||
for key, value in (('test', 'abc\uDCFF'), ('test\uDCFF', '42')):
|
||||
value_repr = repr(value).encode("ascii")
|
||||
|
||||
# test str with surrogates
|
||||
script = "import os; print(repr(os.getenv(%s)))" % repr(key)
|
||||
env = os.environ.copy()
|
||||
|
@ -813,19 +811,19 @@ class POSIXProcessTestCase(BaseTestCase):
|
|||
[sys.executable, "-c", script],
|
||||
env=env)
|
||||
stdout = stdout.rstrip(b'\n\r')
|
||||
self.assertEquals(stdout, value_repr)
|
||||
self.assertEquals(stdout.decode('ascii'), repr(value))
|
||||
|
||||
# test bytes
|
||||
key = key.encode("ascii", "surrogateescape")
|
||||
value = value.encode("ascii", "surrogateescape")
|
||||
script = "import os; print(repr(os.getenv(%s)))" % repr(key)
|
||||
script = "import os; print(repr(os.getenvb(%s)))" % repr(key)
|
||||
env = os.environ.copy()
|
||||
env[key] = value
|
||||
stdout = subprocess.check_output(
|
||||
[sys.executable, "-c", script],
|
||||
env=env)
|
||||
stdout = stdout.rstrip(b'\n\r')
|
||||
self.assertEquals(stdout, value_repr)
|
||||
self.assertEquals(stdout.decode('ascii'), repr(value))
|
||||
|
||||
|
||||
@unittest.skipUnless(mswindows, "Windows specific tests")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue