Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
6f35eda4
Commit
6f35eda4
authored
Oct 29, 2010
by
Victor Stinner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #10210: os.get_exec_path() ignores BytesWarning warnings
parent
bfd7b265
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
3 deletions
+20
-3
Lib/os.py
Lib/os.py
+16
-2
Lib/test/test_os.py
Lib/test/test_os.py
+4
-1
No files found.
Lib/os.py
View file @
6f35eda4
...
...
@@ -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
:
# 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
:
# 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
:
...
...
Lib/test/test_os.py
View file @
6f35eda4
...
...
@@ -461,8 +461,11 @@ class EnvironTests(mapping_tests.BasicTestMappingProtocol):
if
os
.
supports_bytes_environ
:
# env cannot contain 'PATH' and b'PATH' keys
try
:
# ignore BytesWarning warning
with
warnings
.
catch_warnings
(
record
=
True
):
mixed_env
=
{
'PATH'
:
'1'
,
b'PATH'
:
b'2'
}
except
BytesWarning
:
# mixed_env cannot be created with python -bb
pass
else
:
self
.
assertRaises
(
ValueError
,
os
.
get_exec_path
,
mixed_env
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment