mirror of
https://github.com/python/cpython.git
synced 2025-11-19 10:46:17 +00:00
Issue #9549: sys.setdefaultencoding() and PyUnicode_SetDefaultEncoding()
are now removed, since their effect was inexistent in 3.x (the default encoding is hardcoded to utf-8 and cannot be changed).
This commit is contained in:
parent
b0fa831d1e
commit
fce7fd6426
8 changed files with 4 additions and 90 deletions
25
Lib/site.py
25
Lib/site.py
|
|
@ -460,25 +460,6 @@ def aliasmbcs():
|
|||
encodings._cache[enc] = encodings._unknown
|
||||
encodings.aliases.aliases[enc] = 'mbcs'
|
||||
|
||||
def setencoding():
|
||||
"""Set the string encoding used by the Unicode implementation. The
|
||||
default is 'ascii', but if you're willing to experiment, you can
|
||||
change this."""
|
||||
encoding = "ascii" # Default value set by _PyUnicode_Init()
|
||||
if 0:
|
||||
# Enable to support locale aware default string encodings.
|
||||
import locale
|
||||
loc = locale.getdefaultlocale()
|
||||
if loc[1]:
|
||||
encoding = loc[1]
|
||||
if 0:
|
||||
# Enable to switch off string to Unicode coercion and implicit
|
||||
# Unicode to string conversion.
|
||||
encoding = "undefined"
|
||||
if encoding != "ascii":
|
||||
# On Non-Unicode builds this will raise an AttributeError...
|
||||
sys.setdefaultencoding(encoding) # Needs Python Unicode build !
|
||||
|
||||
|
||||
def execsitecustomize():
|
||||
"""Run custom site specific code, if available."""
|
||||
|
|
@ -527,15 +508,9 @@ def main():
|
|||
setcopyright()
|
||||
sethelper()
|
||||
aliasmbcs()
|
||||
setencoding()
|
||||
execsitecustomize()
|
||||
if ENABLE_USER_SITE:
|
||||
execusercustomize()
|
||||
# Remove sys.setdefaultencoding() so that users cannot change the
|
||||
# encoding after initialization. The test for presence is needed when
|
||||
# this module is run as a script, because this code is executed twice.
|
||||
if hasattr(sys, "setdefaultencoding"):
|
||||
del sys.setdefaultencoding
|
||||
|
||||
main()
|
||||
|
||||
|
|
|
|||
|
|
@ -29,10 +29,6 @@ if not os.path.isdir(site.USER_SITE):
|
|||
|
||||
class HelperFunctionsTests(unittest.TestCase):
|
||||
"""Tests for helper functions.
|
||||
|
||||
The setting of the encoding (set using sys.setdefaultencoding) used by
|
||||
the Unicode implementation is not tested.
|
||||
|
||||
"""
|
||||
|
||||
def setUp(self):
|
||||
|
|
@ -333,10 +329,6 @@ class ImportSideEffectTests(unittest.TestCase):
|
|||
else:
|
||||
self.fail("did not alias mbcs")
|
||||
|
||||
def test_setdefaultencoding_removed(self):
|
||||
# Make sure sys.setdefaultencoding is gone
|
||||
self.assertTrue(not hasattr(sys, "setdefaultencoding"))
|
||||
|
||||
def test_sitecustomize_executed(self):
|
||||
# If sitecustomize is available, it should have been imported.
|
||||
if "sitecustomize" not in sys.modules:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue