Issue #8513: os.get_exec_path() supports b'PATH' key and bytes value.
subprocess.Popen() and os._execvpe() support bytes program name. Add
os.supports_bytes_environ flag: True if the native OS type of the environment
is bytes (eg. False on Windows).
diff --git a/Lib/os.py b/Lib/os.py
index 13ab18c..8f47137 100644
--- a/Lib/os.py
+++ b/Lib/os.py
@@ -355,7 +355,11 @@
         return
     last_exc = saved_exc = None
     saved_tb = None
-    for dir in get_exec_path(env):
+    path_list = get_exec_path(env)
+    if name != 'nt':
+        file = fsencode(file)
+        path_list = map(fsencode, path_list)
+    for dir in path_list:
         fullname = path.join(dir, file)
         try:
             exec_func(fullname, *argrest)
@@ -380,7 +384,30 @@
     """
     if env is None:
         env = environ
-    return env.get('PATH', defpath).split(pathsep)
+
+    try:
+        path_list = env.get('PATH')
+    except TypeError:
+        path_list = None
+
+    if supports_bytes_environ:
+        try:
+            path_listb = env[b'PATH']
+        except (KeyError, TypeError):
+            pass
+        else:
+            if path_list is not None:
+                raise ValueError(
+                    "env cannot contain 'PATH' and b'PATH' keys")
+            path_list = path_listb
+
+        if path_list is not None and isinstance(path_list, bytes):
+            path_list = path_list.decode(sys.getfilesystemencoding(),
+                                         'surrogateescape')
+
+    if path_list is None:
+        path_list = defpath
+    return path_list.split(pathsep)
 
 
 # Change environ to automatically call putenv(), unsetenv if they exist.
@@ -482,9 +509,11 @@
     The optional second argument can specify an alternate default.
     key, default and the result are str."""
     return environ.get(key, default)
-__all__.append("getenv")
 
-if name not in ('os2', 'nt'):
+supports_bytes_environ = name not in ('os2', 'nt')
+__all__.extend(("getenv", "supports_bytes_environ"))
+
+if supports_bytes_environ:
     def _check_bytes(value):
         if not isinstance(value, bytes):
             raise TypeError("bytes expected, not %s" % type(value).__name__)