mirror of
https://github.com/python/cpython.git
synced 2025-07-08 03:45:36 +00:00
bpo-44666: Use default encoding as fallback for compile_file (GH-27236)
When sys.stdout.encoding is None compile_file will fall back to sys.getdefaultencoding to encode/decode error messages. Co-authored-by: Stefan Hoelzl <stefan.hoelzl@posteo.de> Co-authored-by: Mickaël Schoentgen <contact@tiger-222.fr>
This commit is contained in:
parent
7cad0bee80
commit
80f0707629
4 changed files with 13 additions and 3 deletions
|
@ -254,9 +254,8 @@ def compile_file(fullname, ddir=None, force=False, rx=None, quiet=0,
|
|||
else:
|
||||
print('*** ', end='')
|
||||
# escape non-printable characters in msg
|
||||
msg = err.msg.encode(sys.stdout.encoding,
|
||||
errors='backslashreplace')
|
||||
msg = msg.decode(sys.stdout.encoding)
|
||||
encoding = sys.stdout.encoding or sys.getdefaultencoding()
|
||||
msg = err.msg.encode(encoding, errors='backslashreplace').decode(encoding)
|
||||
print(msg)
|
||||
except (SyntaxError, UnicodeError, OSError) as e:
|
||||
success = False
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue