Issue #8391: os.execvpe() and os.getenv() supports unicode with surrogates and

bytes strings for environment keys and values
This commit is contained in:
Victor Stinner 2010-04-23 21:41:56 +00:00
parent 534db4e19f
commit 13bb71c38f
5 changed files with 123 additions and 169 deletions

View file

@ -450,6 +450,8 @@ environ = _Environ(environ, _keymap, _putenv, _unsetenv)
def getenv(key, default=None):
"""Get an environment variable, return None if it doesn't exist.
The optional second argument can specify an alternate default."""
if isinstance(key, bytes):
key = key.decode(sys.getfilesystemencoding(), "surrogateescape")
return environ.get(key, default)
__all__.append("getenv")