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
e0a2b72e
Commit
e0a2b72e
authored
May 10, 2009
by
Martin v. Löwis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rename the surrogates error handler to surrogatepass.
parent
cf7925df
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
25 additions
and
25 deletions
+25
-25
Doc/library/codecs.rst
Doc/library/codecs.rst
+7
-7
Lib/test/test_codecs.py
Lib/test/test_codecs.py
+6
-6
Lib/test/test_unicode.py
Lib/test/test_unicode.py
+3
-3
Misc/NEWS
Misc/NEWS
+1
-1
Python/codecs.c
Python/codecs.c
+6
-6
Python/marshal.c
Python/marshal.c
+2
-2
No files found.
Doc/library/codecs.rst
View file @
e0a2b72e
...
...
@@ -327,15 +327,15 @@ and implemented by all standard Python codecs:
In addition, the following error handlers are specific to a single codec:
+------------------
+---------+-
-------------------------------------------+
|
Value
| Codec | Meaning
|
+==================
+=========+=
===========================================+
|
``'surrogates'`` | utf-8 | Allow encoding and decoding of surrogate
|
|
| | codes in UTF-8.
|
+------------------
+---------+-
-------------------------------------------+
+------------------
-+---------+
-------------------------------------------+
|
Value
| Codec | Meaning
|
+==================
=+=========+
===========================================+
|
``'surrogatepass'``|
utf-8 | Allow encoding and decoding of surrogate
|
|
| | codes in UTF-8.
|
+------------------
-+---------+
-------------------------------------------+
.. versionadded:: 3.1
The ``'utf8b'`` and ``'surrogates'`` error handlers.
The ``'utf8b'`` and ``'surrogate
pas
s'`` error handlers.
The set of allowed values can be extended via :meth:`register_error`.
...
...
Lib/test/test_codecs.py
View file @
e0a2b72e
...
...
@@ -545,12 +545,12 @@ class UTF8Test(ReadTest):
self
.
assertRaises
(
UnicodeEncodeError
,
"
\
ud800
"
.
encode
,
"utf-8"
)
self
.
assertRaises
(
UnicodeDecodeError
,
b"
\
xed
\
xa0
\
x80
"
.
decode
,
"utf-8"
)
def
test_surrogates_handler
(
self
):
self
.
assertEquals
(
"abc
\
ud800
def"
.
encode
(
"utf-8"
,
"surrogates"
),
def
test_surrogate
pas
s_handler
(
self
):
self
.
assertEquals
(
"abc
\
ud800
def"
.
encode
(
"utf-8"
,
"surrogate
pas
s"
),
b"abc
\
xed
\
xa0
\
x80
def"
)
self
.
assertEquals
(
b"abc
\
xed
\
xa0
\
x80
def"
.
decode
(
"utf-8"
,
"surrogates"
),
self
.
assertEquals
(
b"abc
\
xed
\
xa0
\
x80
def"
.
decode
(
"utf-8"
,
"surrogate
pas
s"
),
"abc
\
ud800
def"
)
self
.
assertTrue
(
codecs
.
lookup_error
(
"surrogates"
))
self
.
assertTrue
(
codecs
.
lookup_error
(
"surrogate
pas
s"
))
class
UTF7Test
(
ReadTest
):
encoding
=
"utf-7"
...
...
@@ -1040,12 +1040,12 @@ class NameprepTest(unittest.TestCase):
# Skipped
continue
# The Unicode strings are given in UTF-8
orig
=
str
(
orig
,
"utf-8"
,
"surrogates"
)
orig
=
str
(
orig
,
"utf-8"
,
"surrogate
pas
s"
)
if
prepped
is
None
:
# Input contains prohibited characters
self
.
assertRaises
(
UnicodeError
,
nameprep
,
orig
)
else
:
prepped
=
str
(
prepped
,
"utf-8"
,
"surrogates"
)
prepped
=
str
(
prepped
,
"utf-8"
,
"surrogate
pas
s"
)
try
:
self
.
assertEquals
(
nameprep
(
orig
),
prepped
)
except
Exception
as
e
:
...
...
Lib/test/test_unicode.py
View file @
e0a2b72e
...
...
@@ -906,10 +906,10 @@ class UnicodeTest(
self
.
assertEqual
(
'
\
u20ac
'
.
encode
(
'utf-8'
),
b'
\
xe2
\
x82
\
xac
'
)
self
.
assertEqual
(
'
\
ud800
\
udc02
'
.
encode
(
'utf-8'
),
b'
\
xf0
\
x90
\
x80
\
x82
'
)
self
.
assertEqual
(
'
\
ud84d
\
udc56
'
.
encode
(
'utf-8'
),
b'
\
xf0
\
xa3
\
x91
\
x96
'
)
self
.
assertEqual
(
'
\
ud800
'
.
encode
(
'utf-8'
,
'surrogates'
),
b'
\
xed
\
xa0
\
x80
'
)
self
.
assertEqual
(
'
\
udc00
'
.
encode
(
'utf-8'
,
'surrogates'
),
b'
\
xed
\
xb0
\
x80
'
)
self
.
assertEqual
(
'
\
ud800
'
.
encode
(
'utf-8'
,
'surrogate
pas
s'
),
b'
\
xed
\
xa0
\
x80
'
)
self
.
assertEqual
(
'
\
udc00
'
.
encode
(
'utf-8'
,
'surrogate
pas
s'
),
b'
\
xed
\
xb0
\
x80
'
)
self
.
assertEqual
(
(
'
\
ud800
\
udc02
'
*
1000
).
encode
(
'utf-8'
,
'surrogates'
),
(
'
\
ud800
\
udc02
'
*
1000
).
encode
(
'utf-8'
,
'surrogate
pas
s'
),
b'
\
xf0
\
x90
\
x80
\
x82
'
*
1000
)
self
.
assertEqual
(
...
...
Misc/NEWS
View file @
e0a2b72e
...
...
@@ -56,7 +56,7 @@ Core and Builtins
- Issue #4426: The UTF-7 decoder was too strict and didn't accept some legal
sequences. Patch by Nick Barnes and Victor Stinner.
- Issue #3672: Reject surrogates in utf-8 codec; add surrogates error handler.
- Issue #3672: Reject surrogates in utf-8 codec; add surrogate
pas
s error handler.
- Issue #5883: In the io module, the BufferedIOBase and TextIOBase ABCs have
received a new method, detach(). detach() disconnects the underlying stream
...
...
Python/codecs.c
View file @
e0a2b72e
...
...
@@ -751,7 +751,7 @@ PyObject *PyCodec_BackslashReplaceErrors(PyObject *exc)
/* This handler is declared static until someone demonstrates
a need to call it directly. */
static
PyObject
*
PyCodec_SurrogateErrors
(
PyObject
*
exc
)
PyCodec_Surrogate
Pass
Errors
(
PyObject
*
exc
)
{
PyObject
*
restuple
;
PyObject
*
object
;
...
...
@@ -935,9 +935,9 @@ static PyObject *backslashreplace_errors(PyObject *self, PyObject *exc)
return
PyCodec_BackslashReplaceErrors
(
exc
);
}
static
PyObject
*
surrogates_errors
(
PyObject
*
self
,
PyObject
*
exc
)
static
PyObject
*
surrogate
pas
s_errors
(
PyObject
*
self
,
PyObject
*
exc
)
{
return
PyCodec_SurrogateErrors
(
exc
);
return
PyCodec_Surrogate
Pass
Errors
(
exc
);
}
static
PyObject
*
utf8b_errors
(
PyObject
*
self
,
PyObject
*
exc
)
...
...
@@ -993,10 +993,10 @@ static int _PyCodecRegistry_Init(void)
}
},
{
"surrogates"
,
"surrogate
pas
s"
,
{
"surrogates"
,
surrogates_errors
,
"surrogate
pas
s"
,
surrogate
pas
s_errors
,
METH_O
}
},
...
...
Python/marshal.c
View file @
e0a2b72e
...
...
@@ -314,7 +314,7 @@ w_object(PyObject *v, WFILE *p)
PyObject
*
utf8
;
utf8
=
PyUnicode_EncodeUTF8
(
PyUnicode_AS_UNICODE
(
v
),
PyUnicode_GET_SIZE
(
v
),
"surrogates"
);
"surrogate
pas
s"
);
if
(
utf8
==
NULL
)
{
p
->
depth
--
;
p
->
error
=
WFERR_UNMARSHALLABLE
;
...
...
@@ -809,7 +809,7 @@ r_object(RFILE *p)
retval
=
NULL
;
break
;
}
v
=
PyUnicode_DecodeUTF8
(
buffer
,
n
,
"surrogates"
);
v
=
PyUnicode_DecodeUTF8
(
buffer
,
n
,
"surrogate
pas
s"
);
PyMem_DEL
(
buffer
);
retval
=
v
;
break
;
...
...
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