cpython: c7fdb0637d0b (original) (raw)
Mercurial > cpython
changeset 85673:c7fdb0637d0b
Issue #18818: The "encodingname" part of PYTHONIOENCODING is now optional. [#18818]
Serhiy Storchaka storchaka@gmail.com | |
---|---|
date | Fri, 13 Sep 2013 11:46:24 +0300 |
parents | b85c9d2a5227 |
children | c902ceaf7825 |
files | Doc/using/cmdline.rst Lib/test/test_sys.py Misc/NEWS Python/pythonrun.c |
diffstat | 4 files changed, 56 insertions(+), 11 deletions(-)[+] [-] Doc/using/cmdline.rst 9 Lib/test/test_sys.py 36 Misc/NEWS 2 Python/pythonrun.c 20 |
line wrap: on
line diff
--- a/Doc/using/cmdline.rst +++ b/Doc/using/cmdline.rst @@ -538,13 +538,16 @@ conflict. .. envvar:: PYTHONIOENCODING If this is set before running the interpreter, it overrides the encoding used
- for stdin/stdout/stderr, in the syntax
encodingname:errorhandler
. The :errorhandler
part is optional and has the same meaning as in- :func:
str.encode
.
- for stdin/stdout/stderr, in the syntax
encodingname:errorhandler
. Both - the
encodingname
and the:errorhandler
parts are optional and have - the same meaning as in :func:
str.encode
. For stderr, the:errorhandler
part is ignored; the handler will always be'backslashreplace'
. - .. versionchanged:: 3.4
The ``encodingname`` part is now optional.[](#l1.18)
+ .. envvar:: PYTHONNOUSERSITE
--- a/Lib/test/test_sys.py +++ b/Lib/test/test_sys.py @@ -544,6 +544,42 @@ class SysModuleTest(unittest.TestCase): out = p.communicate()[0].strip() self.assertEqual(out, b'?')
env["PYTHONIOENCODING"] = "ascii"[](#l2.7)
p = subprocess.Popen([sys.executable, "-c", 'print(chr(0xa2))'],[](#l2.8)
stdout=subprocess.PIPE, stderr=subprocess.PIPE,[](#l2.9)
env=env)[](#l2.10)
out, err = p.communicate()[](#l2.11)
self.assertEqual(out, b'')[](#l2.12)
self.assertIn(b'UnicodeEncodeError:', err)[](#l2.13)
self.assertIn(rb"'\xa2'", err)[](#l2.14)
env["PYTHONIOENCODING"] = "ascii:"[](#l2.16)
p = subprocess.Popen([sys.executable, "-c", 'print(chr(0xa2))'],[](#l2.17)
stdout=subprocess.PIPE, stderr=subprocess.PIPE,[](#l2.18)
env=env)[](#l2.19)
out, err = p.communicate()[](#l2.20)
self.assertEqual(out, b'')[](#l2.21)
self.assertIn(b'UnicodeEncodeError:', err)[](#l2.22)
self.assertIn(rb"'\xa2'", err)[](#l2.23)
env["PYTHONIOENCODING"] = ":surrogateescape"[](#l2.25)
p = subprocess.Popen([sys.executable, "-c", 'print(chr(0xdcbd))'],[](#l2.26)
stdout=subprocess.PIPE, env=env)[](#l2.27)
out = p.communicate()[0].strip()[](#l2.28)
self.assertEqual(out, b'\xbd')[](#l2.29)
- @unittest.skipUnless(test.support.FS_NONASCII,
'requires OS support of non-ASCII encodings')[](#l2.32)
- def test_ioencoding_nonascii(self):
env = dict(os.environ)[](#l2.34)
env["PYTHONIOENCODING"] = ""[](#l2.36)
p = subprocess.Popen([sys.executable, "-c",[](#l2.37)
'print(%a)' % test.support.FS_NONASCII],[](#l2.38)
stdout=subprocess.PIPE, env=env)[](#l2.39)
out = p.communicate()[0].strip()[](#l2.40)
self.assertEqual(out, os.fsencode(test.support.FS_NONASCII))[](#l2.41)
+ @unittest.skipIf(sys.base_prefix != sys.prefix, 'Test is not venv-compatible') def test_executable(self):
--- a/Misc/NEWS +++ b/Misc/NEWS @@ -7,6 +7,8 @@ Projected Release date: 2013-09-29 Core and Builtins ----------------- +- Issue #18818: The "encodingname" part of PYTHONIOENCODING is now optional. + Library -------
--- a/Python/pythonrun.c +++ b/Python/pythonrun.c @@ -1056,7 +1056,7 @@ initstdio(void) PyObject *std = NULL; int status = 0, fd; PyObject * encoding_attr;
/* Hack to avoid a nasty recursion issue when Python is invoked in verbose mode: pre-import the Latin-1 and UTF-8 codecs */ @@ -1088,19 +1088,23 @@ initstdio(void) } Py_DECREF(wrapper);
- encoding = Py_GETENV("PYTHONIOENCODING");
- errors = NULL;
- if (encoding) {
encoding = _PyMem_Strdup(encoding);[](#l4.19)
if (encoding == NULL) {[](#l4.20)
- pythonioencoding = Py_GETENV("PYTHONIOENCODING");
- encoding = errors = NULL;
- if (pythonioencoding) {
pythonioencoding = _PyMem_Strdup(pythonioencoding);[](#l4.24)
if (pythonioencoding == NULL) {[](#l4.25) PyErr_NoMemory();[](#l4.26) goto error;[](#l4.27) }[](#l4.28)
errors = strchr(encoding, ':');[](#l4.29)
errors = strchr(pythonioencoding, ':');[](#l4.30) if (errors) {[](#l4.31) *errors = '\0';[](#l4.32) errors++;[](#l4.33)
if (!*errors)[](#l4.34)
errors = NULL;[](#l4.35) }[](#l4.36)
if (*pythonioencoding)[](#l4.37)
} /* Set sys.stdin */ @@ -1180,7 +1184,7 @@ initstdio(void) status = -1; }encoding = pythonioencoding;[](#l4.38)