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
47a00f3d
Commit
47a00f3d
authored
Dec 02, 2012
by
Benjamin Peterson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
support encoding error handlers that return bytes (closes #16585)
parent
aff47239
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
13 additions
and
2 deletions
+13
-2
Lib/test/test_multibytecodec.py
Lib/test/test_multibytecodec.py
+4
-0
Misc/NEWS
Misc/NEWS
+3
-0
Modules/cjkcodecs/multibytecodec.c
Modules/cjkcodecs/multibytecodec.c
+6
-2
No files found.
Lib/test/test_multibytecodec.py
View file @
47a00f3d
...
@@ -45,6 +45,10 @@ class Test_MultibyteCodec(unittest.TestCase):
...
@@ -45,6 +45,10 @@ class Test_MultibyteCodec(unittest.TestCase):
self
.
assertRaises
(
IndexError
,
dec
,
self
.
assertRaises
(
IndexError
,
dec
,
b'apple
\
x92
ham
\
x93
spam'
,
'test.cjktest'
)
b'apple
\
x92
ham
\
x93
spam'
,
'test.cjktest'
)
def
test_errorhandler_returns_bytes
(
self
):
enc
=
"
\
u30fb
\
udc80
"
.
encode
(
'gb18030'
,
'surrogateescape'
)
self
.
assertEqual
(
enc
,
b'
\
x81
9
\
xa7
9
\
x80
'
)
def
test_codingspec
(
self
):
def
test_codingspec
(
self
):
try
:
try
:
for
enc
in
ALL_CJKENCODINGS
:
for
enc
in
ALL_CJKENCODINGS
:
...
...
Misc/NEWS
View file @
47a00f3d
...
@@ -98,6 +98,9 @@ Core and Builtins
...
@@ -98,6 +98,9 @@ Core and Builtins
Library
Library
-------
-------
-
Issue
#
16585
:
Make
CJK
encoders
support
error
handlers
that
return
bytes
per
PEP
383.
-
Issue
#
10182
:
The
re
module
doesn
't truncate indices to 32 bits anymore.
-
Issue
#
10182
:
The
re
module
doesn
't truncate indices to 32 bits anymore.
Patch by Serhiy Storchaka.
Patch by Serhiy Storchaka.
...
...
Modules/cjkcodecs/multibytecodec.c
View file @
47a00f3d
...
@@ -316,7 +316,7 @@ multibytecodec_encerror(MultibyteCodec *codec,
...
@@ -316,7 +316,7 @@ multibytecodec_encerror(MultibyteCodec *codec,
goto
errorexit
;
goto
errorexit
;
if
(
!
PyTuple_Check
(
retobj
)
||
PyTuple_GET_SIZE
(
retobj
)
!=
2
||
if
(
!
PyTuple_Check
(
retobj
)
||
PyTuple_GET_SIZE
(
retobj
)
!=
2
||
!
PyUnicode_Check
((
tobj
=
PyTuple_GET_ITEM
(
retobj
,
0
)
))
||
(
!
PyUnicode_Check
((
tobj
=
PyTuple_GET_ITEM
(
retobj
,
0
)))
&&
!
PyBytes_Check
(
tobj
))
||
!
PyLong_Check
(
PyTuple_GET_ITEM
(
retobj
,
1
)))
{
!
PyLong_Check
(
PyTuple_GET_ITEM
(
retobj
,
1
)))
{
PyErr_SetString
(
PyExc_TypeError
,
PyErr_SetString
(
PyExc_TypeError
,
"encoding error handler must return "
"encoding error handler must return "
...
@@ -324,7 +324,7 @@ multibytecodec_encerror(MultibyteCodec *codec,
...
@@ -324,7 +324,7 @@ multibytecodec_encerror(MultibyteCodec *codec,
goto
errorexit
;
goto
errorexit
;
}
}
{
if
(
PyUnicode_Check
(
tobj
))
{
const
Py_UNICODE
*
uraw
=
PyUnicode_AS_UNICODE
(
tobj
);
const
Py_UNICODE
*
uraw
=
PyUnicode_AS_UNICODE
(
tobj
);
retstr
=
multibytecodec_encode
(
codec
,
state
,
&
uraw
,
retstr
=
multibytecodec_encode
(
codec
,
state
,
&
uraw
,
...
@@ -333,6 +333,10 @@ multibytecodec_encerror(MultibyteCodec *codec,
...
@@ -333,6 +333,10 @@ multibytecodec_encerror(MultibyteCodec *codec,
if
(
retstr
==
NULL
)
if
(
retstr
==
NULL
)
goto
errorexit
;
goto
errorexit
;
}
}
else
{
Py_INCREF
(
tobj
);
retstr
=
tobj
;
}
assert
(
PyBytes_Check
(
retstr
));
assert
(
PyBytes_Check
(
retstr
));
retstrsize
=
PyBytes_GET_SIZE
(
retstr
);
retstrsize
=
PyBytes_GET_SIZE
(
retstr
);
...
...
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