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
bf28d2dc
Commit
bf28d2dc
authored
Sep 13, 2013
by
Serhiy Storchaka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #18818: The "encodingname" part of PYTHONIOENCODING is now optional.
parent
187b0630
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
56 additions
and
11 deletions
+56
-11
Doc/using/cmdline.rst
Doc/using/cmdline.rst
+6
-3
Lib/test/test_sys.py
Lib/test/test_sys.py
+36
-0
Misc/NEWS
Misc/NEWS
+2
-0
Python/pythonrun.c
Python/pythonrun.c
+12
-8
No files found.
Doc/using/cmdline.rst
View file @
bf28d2dc
...
...
@@ -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.
.. envvar:: PYTHONNOUSERSITE
...
...
Lib/test/test_sys.py
View file @
bf28d2dc
...
...
@@ -544,6 +544,42 @@ class SysModuleTest(unittest.TestCase):
out
=
p
.
communicate
()[
0
].
strip
()
self
.
assertEqual
(
out
,
b'?'
)
env
[
"PYTHONIOENCODING"
]
=
"ascii"
p
=
subprocess
.
Popen
([
sys
.
executable
,
"-c"
,
'print(chr(0xa2))'
],
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
,
env
=
env
)
out
,
err
=
p
.
communicate
()
self
.
assertEqual
(
out
,
b''
)
self
.
assertIn
(
b'UnicodeEncodeError:'
,
err
)
self
.
assertIn
(
rb"'\xa2'"
,
err
)
env
[
"PYTHONIOENCODING"
]
=
"ascii:"
p
=
subprocess
.
Popen
([
sys
.
executable
,
"-c"
,
'print(chr(0xa2))'
],
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
,
env
=
env
)
out
,
err
=
p
.
communicate
()
self
.
assertEqual
(
out
,
b''
)
self
.
assertIn
(
b'UnicodeEncodeError:'
,
err
)
self
.
assertIn
(
rb"'\xa2'"
,
err
)
env
[
"PYTHONIOENCODING"
]
=
":surrogateescape"
p
=
subprocess
.
Popen
([
sys
.
executable
,
"-c"
,
'print(chr(0xdcbd))'
],
stdout
=
subprocess
.
PIPE
,
env
=
env
)
out
=
p
.
communicate
()[
0
].
strip
()
self
.
assertEqual
(
out
,
b'
\
xbd
'
)
@
unittest
.
skipUnless
(
test
.
support
.
FS_NONASCII
,
'requires OS support of non-ASCII encodings'
)
def
test_ioencoding_nonascii
(
self
):
env
=
dict
(
os
.
environ
)
env
[
"PYTHONIOENCODING"
]
=
""
p
=
subprocess
.
Popen
([
sys
.
executable
,
"-c"
,
'print(%a)'
%
test
.
support
.
FS_NONASCII
],
stdout
=
subprocess
.
PIPE
,
env
=
env
)
out
=
p
.
communicate
()[
0
].
strip
()
self
.
assertEqual
(
out
,
os
.
fsencode
(
test
.
support
.
FS_NONASCII
))
@
unittest
.
skipIf
(
sys
.
base_prefix
!=
sys
.
prefix
,
'Test is not venv-compatible'
)
def
test_executable
(
self
):
...
...
Misc/NEWS
View file @
bf28d2dc
...
...
@@ -7,6 +7,8 @@ Projected Release date: 2013-09-29
Core
and
Builtins
-----------------
-
Issue
#
18818
:
The
"encodingname"
part
of
PYTHONIOENCODING
is
now
optional
.
Library
-------
...
...
Python/pythonrun.c
View file @
bf28d2dc
...
...
@@ -1056,7 +1056,7 @@ initstdio(void)
PyObject
*
std
=
NULL
;
int
status
=
0
,
fd
;
PyObject
*
encoding_attr
;
char
*
encoding
=
NULL
,
*
errors
;
char
*
pythonioencoding
=
NULL
,
*
encoding
,
*
errors
;
/* 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
);
if
(
encoding
==
NULL
)
{
pythonio
encoding
=
Py_GETENV
(
"PYTHONIOENCODING"
);
e
ncoding
=
e
rrors
=
NULL
;
if
(
pythonio
encoding
)
{
pythonioencoding
=
_PyMem_Strdup
(
pythonio
encoding
);
if
(
pythonio
encoding
==
NULL
)
{
PyErr_NoMemory
();
goto
error
;
}
errors
=
strchr
(
encoding
,
':'
);
errors
=
strchr
(
pythonio
encoding
,
':'
);
if
(
errors
)
{
*
errors
=
'\0'
;
errors
++
;
if
(
!*
errors
)
errors
=
NULL
;
}
if
(
*
pythonioencoding
)
encoding
=
pythonioencoding
;
}
/* Set sys.stdin */
...
...
@@ -1180,7 +1184,7 @@ initstdio(void)
status
=
-
1
;
}
PyMem_Free
(
encoding
);
PyMem_Free
(
pythonio
encoding
);
Py_XDECREF
(
bimod
);
Py_XDECREF
(
iomod
);
return
status
;
...
...
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