Skip to content

Commit e0a2b72

Browse files
committed
Rename the surrogates error handler to surrogatepass.
1 parent cf7925d commit e0a2b72

File tree

6 files changed

+25
-25
lines changed

6 files changed

+25
-25
lines changed

Doc/library/codecs.rst

+7-7
Original file line numberDiff line numberDiff line change
@@ -327,15 +327,15 @@ and implemented by all standard Python codecs:
327327

328328
In addition, the following error handlers are specific to a single codec:
329329

330-
+------------------+---------+--------------------------------------------+
331-
| Value | Codec | Meaning |
332-
+==================+=========+============================================+
333-
| ``'surrogates'`` | utf-8 | Allow encoding and decoding of surrogate |
334-
| | | codes in UTF-8. |
335-
+------------------+---------+--------------------------------------------+
330+
+-------------------+---------+-------------------------------------------+
331+
| Value | Codec | Meaning |
332+
+===================+=========+===========================================+
333+
|``'surrogatepass'``| utf-8 | Allow encoding and decoding of surrogate |
334+
| | | codes in UTF-8. |
335+
+-------------------+---------+-------------------------------------------+
336336

337337
.. versionadded:: 3.1
338-
The ``'utf8b'`` and ``'surrogates'`` error handlers.
338+
The ``'utf8b'`` and ``'surrogatepass'`` error handlers.
339339

340340
The set of allowed values can be extended via :meth:`register_error`.
341341

Lib/test/test_codecs.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -545,12 +545,12 @@ def test_lone_surrogates(self):
545545
self.assertRaises(UnicodeEncodeError, "\ud800".encode, "utf-8")
546546
self.assertRaises(UnicodeDecodeError, b"\xed\xa0\x80".decode, "utf-8")
547547

548-
def test_surrogates_handler(self):
549-
self.assertEquals("abc\ud800def".encode("utf-8", "surrogates"),
548+
def test_surrogatepass_handler(self):
549+
self.assertEquals("abc\ud800def".encode("utf-8", "surrogatepass"),
550550
b"abc\xed\xa0\x80def")
551-
self.assertEquals(b"abc\xed\xa0\x80def".decode("utf-8", "surrogates"),
551+
self.assertEquals(b"abc\xed\xa0\x80def".decode("utf-8", "surrogatepass"),
552552
"abc\ud800def")
553-
self.assertTrue(codecs.lookup_error("surrogates"))
553+
self.assertTrue(codecs.lookup_error("surrogatepass"))
554554

555555
class UTF7Test(ReadTest):
556556
encoding = "utf-7"
@@ -1040,12 +1040,12 @@ def test_nameprep(self):
10401040
# Skipped
10411041
continue
10421042
# The Unicode strings are given in UTF-8
1043-
orig = str(orig, "utf-8", "surrogates")
1043+
orig = str(orig, "utf-8", "surrogatepass")
10441044
if prepped is None:
10451045
# Input contains prohibited characters
10461046
self.assertRaises(UnicodeError, nameprep, orig)
10471047
else:
1048-
prepped = str(prepped, "utf-8", "surrogates")
1048+
prepped = str(prepped, "utf-8", "surrogatepass")
10491049
try:
10501050
self.assertEquals(nameprep(orig), prepped)
10511051
except Exception as e:

Lib/test/test_unicode.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -906,10 +906,10 @@ def test_codecs_utf8(self):
906906
self.assertEqual('\u20ac'.encode('utf-8'), b'\xe2\x82\xac')
907907
self.assertEqual('\ud800\udc02'.encode('utf-8'), b'\xf0\x90\x80\x82')
908908
self.assertEqual('\ud84d\udc56'.encode('utf-8'), b'\xf0\xa3\x91\x96')
909-
self.assertEqual('\ud800'.encode('utf-8', 'surrogates'), b'\xed\xa0\x80')
910-
self.assertEqual('\udc00'.encode('utf-8', 'surrogates'), b'\xed\xb0\x80')
909+
self.assertEqual('\ud800'.encode('utf-8', 'surrogatepass'), b'\xed\xa0\x80')
910+
self.assertEqual('\udc00'.encode('utf-8', 'surrogatepass'), b'\xed\xb0\x80')
911911
self.assertEqual(
912-
('\ud800\udc02'*1000).encode('utf-8', 'surrogates'),
912+
('\ud800\udc02'*1000).encode('utf-8', 'surrogatepass'),
913913
b'\xf0\x90\x80\x82'*1000
914914
)
915915
self.assertEqual(

Misc/NEWS

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ Core and Builtins
5656
- Issue #4426: The UTF-7 decoder was too strict and didn't accept some legal
5757
sequences. Patch by Nick Barnes and Victor Stinner.
5858

59-
- Issue #3672: Reject surrogates in utf-8 codec; add surrogates error handler.
59+
- Issue #3672: Reject surrogates in utf-8 codec; add surrogatepass error handler.
6060

6161
- Issue #5883: In the io module, the BufferedIOBase and TextIOBase ABCs have
6262
received a new method, detach(). detach() disconnects the underlying stream

Python/codecs.c

+6-6
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,7 @@ PyObject *PyCodec_BackslashReplaceErrors(PyObject *exc)
751751
/* This handler is declared static until someone demonstrates
752752
a need to call it directly. */
753753
static PyObject *
754-
PyCodec_SurrogateErrors(PyObject *exc)
754+
PyCodec_SurrogatePassErrors(PyObject *exc)
755755
{
756756
PyObject *restuple;
757757
PyObject *object;
@@ -935,9 +935,9 @@ static PyObject *backslashreplace_errors(PyObject *self, PyObject *exc)
935935
return PyCodec_BackslashReplaceErrors(exc);
936936
}
937937

938-
static PyObject *surrogates_errors(PyObject *self, PyObject *exc)
938+
static PyObject *surrogatepass_errors(PyObject *self, PyObject *exc)
939939
{
940-
return PyCodec_SurrogateErrors(exc);
940+
return PyCodec_SurrogatePassErrors(exc);
941941
}
942942

943943
static PyObject *utf8b_errors(PyObject *self, PyObject *exc)
@@ -993,10 +993,10 @@ static int _PyCodecRegistry_Init(void)
993993
}
994994
},
995995
{
996-
"surrogates",
996+
"surrogatepass",
997997
{
998-
"surrogates",
999-
surrogates_errors,
998+
"surrogatepass",
999+
surrogatepass_errors,
10001000
METH_O
10011001
}
10021002
},

Python/marshal.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ w_object(PyObject *v, WFILE *p)
314314
PyObject *utf8;
315315
utf8 = PyUnicode_EncodeUTF8(PyUnicode_AS_UNICODE(v),
316316
PyUnicode_GET_SIZE(v),
317-
"surrogates");
317+
"surrogatepass");
318318
if (utf8 == NULL) {
319319
p->depth--;
320320
p->error = WFERR_UNMARSHALLABLE;
@@ -809,7 +809,7 @@ r_object(RFILE *p)
809809
retval = NULL;
810810
break;
811811
}
812-
v = PyUnicode_DecodeUTF8(buffer, n, "surrogates");
812+
v = PyUnicode_DecodeUTF8(buffer, n, "surrogatepass");
813813
PyMem_DEL(buffer);
814814
retval = v;
815815
break;

0 commit comments

Comments
 (0)