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
372ac5e7
Commit
372ac5e7
authored
May 17, 2010
by
Victor Stinner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PyObject_Dump() encodes unicode objects to utf8 with backslashreplace (instead
of strict) error handler to escape surrogates
parent
6baded49
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
16 additions
and
1 deletion
+16
-1
Lib/test/test_sys.py
Lib/test/test_sys.py
+10
-0
Misc/NEWS
Misc/NEWS
+3
-0
Objects/object.c
Objects/object.c
+3
-1
No files found.
Lib/test/test_sys.py
View file @
372ac5e7
...
...
@@ -145,6 +145,16 @@ class SysModuleTest(unittest.TestCase):
"raise SystemExit(47)"
])
self
.
assertEqual
(
rc
,
47
)
# test that the exit message is written with backslashreplace error
# handler to stderr
import
subprocess
code
=
r'import sys; sys.exit("surrogates:\uDCFF")'
process
=
subprocess
.
Popen
([
sys
.
executable
,
"-c"
,
code
],
stderr
=
subprocess
.
PIPE
)
stdout
,
stderr
=
process
.
communicate
()
self
.
assertEqual
(
process
.
returncode
,
1
)
self
.
assertTrue
(
stderr
.
startswith
(
b"surrogates:
\
\
udcff"
),
stderr
)
def
test_getdefaultencoding
(
self
):
self
.
assertRaises
(
TypeError
,
sys
.
getdefaultencoding
,
42
)
# can't check more than the type, as the user might have changed it
...
...
Misc/NEWS
View file @
372ac5e7
...
...
@@ -12,6 +12,9 @@ What's New in Python 3.2 Alpha 1?
Core and Builtins
-----------------
- PyObject_Dump() encodes unicode objects to utf8 with backslashreplace
(instead of strict) error handler to escape surrogates
- Issue #8715: Create PyUnicode_EncodeFSDefault() function: Encode a Unicode
object to Py_FileSystemDefaultEncoding with the "surrogateescape" error
handler, and return bytes. If Py_FileSystemDefaultEncoding is not set, fall
...
...
Objects/object.c
View file @
372ac5e7
...
...
@@ -303,7 +303,9 @@ internal_print(PyObject *op, FILE *fp, int flags, int nesting)
}
else
if
(
PyUnicode_Check
(
s
))
{
PyObject
*
t
;
t
=
_PyUnicode_AsDefaultEncodedString
(
s
,
NULL
);
t
=
PyUnicode_EncodeUTF8
(
PyUnicode_AS_UNICODE
(
s
),
PyUnicode_GET_SIZE
(
s
),
"backslashreplace"
);
if
(
t
==
NULL
)
ret
=
0
;
else
{
...
...
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