mirror of
https://github.com/python/cpython.git
synced 2025-11-01 02:38:53 +00:00
(Merge 3.2) Issue #12100: Don't reset incremental encoders of CJK codecs at
each call to their encode() method anymore, but continue to call the reset() method if the final argument is True.
This commit is contained in:
commit
eb734f77ad
3 changed files with 38 additions and 4 deletions
|
|
@ -479,7 +479,7 @@ multibytecodec_encode(MultibyteCodec *codec,
|
|||
MultibyteEncodeBuffer buf;
|
||||
Py_ssize_t finalsize, r = 0;
|
||||
|
||||
if (datalen == 0)
|
||||
if (datalen == 0 && !(flags & MBENC_RESET))
|
||||
return PyBytes_FromStringAndSize(NULL, 0);
|
||||
|
||||
buf.excobj = NULL;
|
||||
|
|
@ -515,7 +515,7 @@ multibytecodec_encode(MultibyteCodec *codec,
|
|||
break;
|
||||
}
|
||||
|
||||
if (codec->encreset != NULL)
|
||||
if (codec->encreset != NULL && (flags & MBENC_RESET))
|
||||
for (;;) {
|
||||
Py_ssize_t outleft;
|
||||
|
||||
|
|
@ -785,8 +785,8 @@ encoder_encode_stateful(MultibyteStatefulEncoderContext *ctx,
|
|||
inbuf_end = inbuf + datalen;
|
||||
|
||||
r = multibytecodec_encode(ctx->codec, &ctx->state,
|
||||
(const Py_UNICODE **)&inbuf,
|
||||
datalen, ctx->errors, final ? MBENC_FLUSH : 0);
|
||||
(const Py_UNICODE **)&inbuf, datalen,
|
||||
ctx->errors, final ? MBENC_FLUSH | MBENC_RESET : 0);
|
||||
if (r == NULL) {
|
||||
/* recover the original pending buffer */
|
||||
if (origpending > 0)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue