summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorAmaury Forgeot d'Arc <amauryfa@gmail.com>2007-11-20 23:31:27 (GMT)
committerAmaury Forgeot d'Arc <amauryfa@gmail.com>2007-11-20 23:31:27 (GMT)
commit5087980c1e7e6733983245cd0f209d8770f9686e (patch)
tree21cb48e04503c87abd856791ba2a249a40ff1433 /Modules
parent8c4592a77ae6b71a4bab8d40bbdcea72a6378cb4 (diff)
downloadcpython-5087980c1e7e6733983245cd0f209d8770f9686e.zip
cpython-5087980c1e7e6733983245cd0f209d8770f9686e.tar.gz
cpython-5087980c1e7e6733983245cd0f209d8770f9686e.tar.bz2
The incremental decoder for utf-7 must preserve its state between calls.
Solves issue1460. Might not be a backport candidate: a new API function was added, and some code may rely on details in utf-7.py.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_codecsmodule.c19
1 files changed, 13 insertions, 6 deletions
diff --git a/Modules/_codecsmodule.c b/Modules/_codecsmodule.c
index 0716f3a..d4eb0d5 100644
--- a/Modules/_codecsmodule.c
+++ b/Modules/_codecsmodule.c
@@ -230,18 +230,25 @@ unicode_internal_decode(PyObject *self,
static PyObject *
utf_7_decode(PyObject *self,
- PyObject *args)
+ PyObject *args)
{
const char *data;
Py_ssize_t size;
const char *errors = NULL;
+ int final = 0;
+ Py_ssize_t consumed;
+ PyObject *decoded = NULL;
- if (!PyArg_ParseTuple(args, "t#|z:utf_7_decode",
- &data, &size, &errors))
- return NULL;
+ if (!PyArg_ParseTuple(args, "t#|zi:utf_7_decode",
+ &data, &size, &errors, &final))
+ return NULL;
+ consumed = size;
- return codec_tuple(PyUnicode_DecodeUTF7(data, size, errors),
- size);
+ decoded = PyUnicode_DecodeUTF7Stateful(data, size, errors,
+ final ? NULL : &consumed);
+ if (decoded == NULL)
+ return NULL;
+ return codec_tuple(decoded, consumed);
}
static PyObject *