summaryrefslogtreecommitdiff
path: root/Lib/os.py
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@haypocalc.com>2010-10-29 00:38:58 +0000
committerVictor Stinner <victor.stinner@haypocalc.com>2010-10-29 00:38:58 +0000
commit519661dbd19161d85239d0ee76593b304a186717 (patch)
tree2dbb453d342978eabed006ac74897bb17934699c /Lib/os.py
parentc8f747eb9edeaed5bb09b22dbf9271ed92df7746 (diff)
downloadcpython-519661dbd19161d85239d0ee76593b304a186717.tar.gz
Issue #10210: os.get_exec_path() ignores BytesWarning warnings
Diffstat (limited to 'Lib/os.py')
-rw-r--r--Lib/os.py18
1 files changed, 16 insertions, 2 deletions
diff --git a/Lib/os.py b/Lib/os.py
index 5c80e67eb4..cdc2a66b48 100644
--- a/Lib/os.py
+++ b/Lib/os.py
@@ -382,18 +382,32 @@ def get_exec_path(env=None):
*env* must be an environment variable dict or None. If *env* is None,
os.environ will be used.
"""
+ # Use a local import instead of a global import to avoid bootstrap issue:
+ # the os module is used to build Python extensions.
+ import warnings
+
if env is None:
env = environ
try:
- path_list = env.get('PATH')
+ # ignore BytesWarning warning
+ with warnings.catch_warnings(record=True):
+ path_list = env.get('PATH')
except (TypeError, BytesWarning):
+ # A BytesWarning here means that env has a b'PATH' key, but no 'PATH'
+ # key. Compare bytes and str raises a BytesWarning exception only if
+ # sys.flags.bytes_warning==2, and in this case it is not possible to
+ # create a dictionary with both keys.
path_list = None
if supports_bytes_environ:
try:
- path_listb = env[b'PATH']
+ # ignore BytesWarning warning
+ with warnings.catch_warnings(record=True):
+ path_listb = env[b'PATH']
except (KeyError, TypeError, BytesWarning):
+ # A BytesWarning here means that env has a 'PATH' key, but no
+ # b'PATH' key. See the comment above for an explaination.
pass
else:
if path_list is not None: