[Python-checkins] r67837 - sandbox/trunk/io-c/_textio.c
amaury.forgeotdarc
python-checkins at python.org
Thu Dec 18 01:00:13 CET 2008
Author: amaury.forgeotdarc
Date: Thu Dec 18 01:00:13 2008
New Revision: 67837
Log:
Implement decoder state management, one more test passes
Modified:
sandbox/trunk/io-c/_textio.c
Modified: sandbox/trunk/io-c/_textio.c
==============================================================================
--- sandbox/trunk/io-c/_textio.c (original)
+++ sandbox/trunk/io-c/_textio.c Thu Dec 18 01:00:13 2008
@@ -199,7 +199,7 @@
break;
}
}
-
+
if (cr)
self->seennl |= SEEN_CR;
if (lf)
@@ -234,8 +234,52 @@
return NULL;
}
+static PyObject *
+IncrementalNewlineDecoder_getstate(PyNewLineDecoderObject *self, PyObject *args)
+{
+ PyObject *state = PyObject_CallMethod(self->decoder, "getstate", NULL);
+ PyObject *buffer;
+ unsigned PY_LONG_LONG flag;
+
+ if (state == NULL)
+ return NULL;
+
+ if (!PyArg_Parse(state, "OK", &buffer, &flag))
+ return NULL;
+ flag <<= 1;
+ if (self->pendingcr)
+ flag |= 1;
+ return Py_BuildValue("OK", buffer, flag);
+}
+
+static PyObject *
+IncrementalNewlineDecoder_setstate(PyNewLineDecoderObject *self, PyObject *state)
+{
+ PyObject *buffer;
+ unsigned PY_LONG_LONG flag;
+
+ if (!PyArg_Parse(state, "OK", &buffer, &flag))
+ return NULL;
+
+ self->pendingcr = flag & 1;
+ flag >>= 1;
+
+ return PyObject_CallMethod(self->decoder, "setstate", "(OK)", buffer, flag);
+}
+
+static PyObject *
+IncrementalNewlineDecoder_reset(PyNewLineDecoderObject *self, PyObject *args)
+{
+ self->seennl = 0;
+ self->pendingcr = 0;
+ return PyObject_CallMethod(self->decoder, "reset", NULL);
+}
+
static PyMethodDef IncrementalNewlineDecoder_methods[] = {
{"decode", (PyCFunction)IncrementalNewlineDecoder_decode, METH_VARARGS|METH_KEYWORDS},
+ {"getstate", (PyCFunction)IncrementalNewlineDecoder_getstate, METH_NOARGS},
+ {"setstate", (PyCFunction)IncrementalNewlineDecoder_setstate, METH_O},
+ {"reset", (PyCFunction)IncrementalNewlineDecoder_reset, METH_NOARGS},
{0}
};
More information about the Python-checkins
mailing list