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
40300272
Commit
40300272
authored
Apr 10, 2016
by
Serhiy Storchaka
Browse files
Options
Browse Files
Download
Plain Diff
Issue #25339: PYTHONIOENCODING now has priority over locale in setting the
error handler for stdin and stdout.
parents
cfff15d2
fc435118
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
35 additions
and
14 deletions
+35
-14
Lib/test/test_sys.py
Lib/test/test_sys.py
+23
-4
Misc/NEWS
Misc/NEWS
+3
-0
Python/pylifecycle.c
Python/pylifecycle.c
+9
-10
No files found.
Lib/test/test_sys.py
View file @
40300272
...
...
@@ -691,8 +691,10 @@ class SysModuleTest(unittest.TestCase):
args
=
[
sys
.
executable
,
"-c"
,
code
]
if
isolated
:
args
.
append
(
"-I"
)
elif
encoding
:
if
encoding
is
not
None
:
env
[
'PYTHONIOENCODING'
]
=
encoding
else
:
env
.
pop
(
'PYTHONIOENCODING'
,
None
)
p
=
subprocess
.
Popen
(
args
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
STDOUT
,
...
...
@@ -709,14 +711,31 @@ class SysModuleTest(unittest.TestCase):
'stderr: backslashreplace
\
n
'
)
# replace the default error handler
out
=
self
.
c_locale_get_error_handler
(
encoding
=
':
strict
'
)
out
=
self
.
c_locale_get_error_handler
(
encoding
=
':
ignore
'
)
self
.
assertEqual
(
out
,
'stdin:
strict
\
n
'
'stdout:
strict
\
n
'
'stdin:
ignore
\
n
'
'stdout:
ignore
\
n
'
'stderr: backslashreplace
\
n
'
)
# force the encoding
out
=
self
.
c_locale_get_error_handler
(
encoding
=
'iso8859-1'
)
self
.
assertEqual
(
out
,
'stdin: strict
\
n
'
'stdout: strict
\
n
'
'stderr: backslashreplace
\
n
'
)
out
=
self
.
c_locale_get_error_handler
(
encoding
=
'iso8859-1:'
)
self
.
assertEqual
(
out
,
'stdin: strict
\
n
'
'stdout: strict
\
n
'
'stderr: backslashreplace
\
n
'
)
# have no any effect
out
=
self
.
c_locale_get_error_handler
(
encoding
=
':'
)
self
.
assertEqual
(
out
,
'stdin: surrogateescape
\
n
'
'stdout: surrogateescape
\
n
'
'stderr: backslashreplace
\
n
'
)
out
=
self
.
c_locale_get_error_handler
(
encoding
=
''
)
self
.
assertEqual
(
out
,
'stdin: surrogateescape
\
n
'
'stdout: surrogateescape
\
n
'
...
...
Misc/NEWS
View file @
40300272
...
...
@@ -10,6 +10,9 @@ Release date: tba
Core and Builtins
-----------------
- Issue #25339: PYTHONIOENCODING now has priority over locale in setting the
error handler for stdin and stdout.
- Issue #26494: Fixed crash on iterating exhausting iterators.
Affected classes are generic sequence iterators, iterators of str, bytes,
bytearray, list, tuple, set, frozenset, dict, OrderedDict, corresponding
...
...
Python/pylifecycle.c
View file @
40300272
...
...
@@ -1166,15 +1166,6 @@ initstdio(void)
encoding
=
_Py_StandardStreamEncoding
;
errors
=
_Py_StandardStreamErrors
;
if
(
!
encoding
||
!
errors
)
{
if
(
!
errors
)
{
/* When the LC_CTYPE locale is the POSIX locale ("C locale"),
stdin and stdout use the surrogateescape error handler by
default, instead of the strict error handler. */
char
*
loc
=
setlocale
(
LC_CTYPE
,
NULL
);
if
(
loc
!=
NULL
&&
strcmp
(
loc
,
"C"
)
==
0
)
errors
=
"surrogateescape"
;
}
pythonioencoding
=
Py_GETENV
(
"PYTHONIOENCODING"
);
if
(
pythonioencoding
)
{
char
*
err
;
...
...
@@ -1187,7 +1178,7 @@ initstdio(void)
if
(
err
)
{
*
err
=
'\0'
;
err
++
;
if
(
*
err
&&
!
_Py_StandardStreamE
rrors
)
{
if
(
*
err
&&
!
e
rrors
)
{
errors
=
err
;
}
}
...
...
@@ -1195,6 +1186,14 @@ initstdio(void)
encoding
=
pythonioencoding
;
}
}
if
(
!
errors
&&
!
(
pythonioencoding
&&
*
pythonioencoding
))
{
/* When the LC_CTYPE locale is the POSIX locale ("C locale"),
stdin and stdout use the surrogateescape error handler by
default, instead of the strict error handler. */
char
*
loc
=
setlocale
(
LC_CTYPE
,
NULL
);
if
(
loc
!=
NULL
&&
strcmp
(
loc
,
"C"
)
==
0
)
errors
=
"surrogateescape"
;
}
}
/* Set sys.stdin */
...
...
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