diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2021-10-14 21:23:39 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-14 21:23:39 +0300 |
commit | 4641afef661e6a22bc64194bd334b161c95edfe2 (patch) | |
tree | d053338921b36eb41bd0a1880c801a33cbec7878 /Modules/_codecsmodule.c | |
parent | 0bff4ccbfd3297b0adf690655d3e9ddb0033bc69 (diff) | |
download | cpython-git-4641afef661e6a22bc64194bd334b161c95edfe2.tar.gz |
[3.10] bpo-45467: Fix IncrementalDecoder and StreamReader in the "raw-unicode-escape" codec (GH-28944) (GH-28952)
They support now splitting escape sequences between input chunks.
Add the third parameter "final" in codecs.raw_unicode_escape_decode().
It is True by default to match the former behavior.
(cherry picked from commit 39aa98346d5dd8ac591a7cafb467af21c53f1e5d)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Diffstat (limited to 'Modules/_codecsmodule.c')
-rw-r--r-- | Modules/_codecsmodule.c | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/Modules/_codecsmodule.c b/Modules/_codecsmodule.c index fc74127ce5..50afc097b3 100644 --- a/Modules/_codecsmodule.c +++ b/Modules/_codecsmodule.c @@ -509,17 +509,20 @@ _codecs_unicode_escape_decode_impl(PyObject *module, Py_buffer *data, _codecs.raw_unicode_escape_decode data: Py_buffer(accept={str, buffer}) errors: str(accept={str, NoneType}) = None + final: bool(accept={int}) = True / [clinic start generated code]*/ static PyObject * _codecs_raw_unicode_escape_decode_impl(PyObject *module, Py_buffer *data, - const char *errors) -/*[clinic end generated code: output=c98eeb56028070a6 input=d2f5159ce3b3392f]*/ + const char *errors, int final) +/*[clinic end generated code: output=11dbd96301e2879e input=2d166191beb3235a]*/ { - PyObject *decoded = PyUnicode_DecodeRawUnicodeEscape(data->buf, data->len, - errors); - return codec_tuple(decoded, data->len); + Py_ssize_t consumed = data->len; + PyObject *decoded = _PyUnicode_DecodeRawUnicodeEscapeStateful(data->buf, data->len, + errors, + final ? NULL : &consumed); + return codec_tuple(decoded, consumed); } /*[clinic input] |