summaryrefslogtreecommitdiffstats
path: root/Objects
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 /Objects
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 'Objects')
-rw-r--r--Objects/unicodeobject.c21
1 files changed, 19 insertions, 2 deletions
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index 7043d5f..18b861b 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -944,6 +944,14 @@ PyObject *PyUnicode_DecodeUTF7(const char *s,
Py_ssize_t size,
const char *errors)
{
+ return PyUnicode_DecodeUTF7Stateful(s, size, errors, NULL);
+}
+
+PyObject *PyUnicode_DecodeUTF7Stateful(const char *s,
+ Py_ssize_t size,
+ const char *errors,
+ Py_ssize_t *consumed)
+{
const char *starts = s;
Py_ssize_t startinpos;
Py_ssize_t endinpos;
@@ -962,8 +970,11 @@ PyObject *PyUnicode_DecodeUTF7(const char *s,
unicode = _PyUnicode_New(size);
if (!unicode)
return NULL;
- if (size == 0)
+ if (size == 0) {
+ if (consumed)
+ *consumed = 0;
return (PyObject *)unicode;
+ }
p = unicode->str;
e = s + size;
@@ -1049,7 +1060,7 @@ PyObject *PyUnicode_DecodeUTF7(const char *s,
goto onError;
}
- if (inShift) {
+ if (inShift && !consumed) {
outpos = p-PyUnicode_AS_UNICODE(unicode);
endinpos = size;
if (unicode_decode_call_errorhandler(
@@ -1061,6 +1072,12 @@ PyObject *PyUnicode_DecodeUTF7(const char *s,
if (s < e)
goto restart;
}
+ if (consumed) {
+ if(inShift)
+ *consumed = startinpos;
+ else
+ *consumed = s-starts;
+ }
if (_PyUnicode_Resize(&unicode, p - PyUnicode_AS_UNICODE(unicode)) < 0)
goto onError;