mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
gh-91954: Emit EncodingWarning from locale and subprocess (GH-91977)
locale.getpreferredencoding() and subprocess.Popen() emit EncodingWarning
This commit is contained in:
parent
c7b7f12b86
commit
354ace8b07
5 changed files with 65 additions and 14 deletions
|
@ -655,6 +655,11 @@ try:
|
|||
except NameError:
|
||||
def getpreferredencoding(do_setlocale=True):
|
||||
"""Return the charset that the user is likely using."""
|
||||
if sys.flags.warn_default_encoding:
|
||||
import warnings
|
||||
warnings.warn(
|
||||
"UTF-8 Mode affects locale.getpreferredencoding(). Consider locale.getencoding() instead.",
|
||||
EncodingWarning, 2)
|
||||
if sys.flags.utf8_mode:
|
||||
return 'utf-8'
|
||||
return getencoding()
|
||||
|
@ -663,6 +668,12 @@ else:
|
|||
def getpreferredencoding(do_setlocale=True):
|
||||
"""Return the charset that the user is likely using,
|
||||
according to the system configuration."""
|
||||
|
||||
if sys.flags.warn_default_encoding:
|
||||
import warnings
|
||||
warnings.warn(
|
||||
"UTF-8 Mode affects locale.getpreferredencoding(). Consider locale.getencoding() instead.",
|
||||
EncodingWarning, 2)
|
||||
if sys.flags.utf8_mode:
|
||||
return 'utf-8'
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue