diff -r 4c496d53b1e1 Modules/cjkcodecs/multibytecodec.c --- a/Modules/cjkcodecs/multibytecodec.c Fri Jan 31 14:18:18 2014 +0100 +++ b/Modules/cjkcodecs/multibytecodec.c Fri Jan 31 08:55:42 2014 -0500 @@ -9,6 +9,16 @@ #include "structmember.h" #include "multibytecodec.h" +/*[clinic input] +module _multibytecodec +[clinic start generated code]*/ +/*[clinic end generated code: output=da39a3ee5e6b4b0d input=f576f5a5b01530ed]*/ + +/*[clinic input] +class _multibytecodec.MultibyteCodec "MultibyteCodecObject *" "&MultibyteCodec_Type" +[clinic start generated code]*/ +/*[clinic end generated code: output=da39a3ee5e6b4b0d input=d5b1fc1fec8eb003]*/ + typedef struct { PyObject *inobj; Py_ssize_t inpos, inlen; @@ -22,27 +32,7 @@ _PyUnicodeWriter writer; } MultibyteDecodeBuffer; -PyDoc_STRVAR(MultibyteCodec_Encode__doc__, -"I.encode(unicode[, errors]) -> (string, length consumed)\n\ -\n\ -Return an encoded string version of `unicode'. errors may be given to\n\ -set a different error handling scheme. Default is 'strict' meaning that\n\ -encoding errors raise a UnicodeEncodeError. Other possible values are\n\ -'ignore', 'replace' and 'xmlcharrefreplace' as well as any other name\n\ -registered with codecs.register_error that can handle UnicodeEncodeErrors."); - -PyDoc_STRVAR(MultibyteCodec_Decode__doc__, -"I.decode(string[, errors]) -> (unicodeobject, length consumed)\n\ -\n\ -Decodes `string' using I, an MultibyteCodec instance. errors may be given\n\ -to set a different error handling scheme. Default is 'strict' meaning\n\ -that encoding errors raise a UnicodeDecodeError. Other possible values\n\ -are 'ignore' and 'replace' as well as any other name registered with\n\ -codecs.register_error that is able to handle UnicodeDecodeErrors."); - -static char *codeckwarglist[] = {"input", "errors", NULL}; static char *incnewkwarglist[] = {"errors", NULL}; -static char *incrementalkwarglist[] = {"input", "final", NULL}; static char *streamkwarglist[] = {"stream", "errors", NULL}; static PyObject *multibytecodec_encode(MultibyteCodec *, @@ -550,26 +540,68 @@ return NULL; } +/*[clinic input] +_multibytecodec.MultibyteCodec.encode + + input: object + errors: str(nullable=True) = NULL + +Return an encoded string version of `input'. + +'errors' may be given to set a different error handling scheme. Default is +'strict' meaning that encoding errors raise a UnicodeEncodeError. Other possible +values are 'ignore', 'replace' and 'xmlcharrefreplace' as well as any other name +registered with codecs.register_error that can handle UnicodeEncodeErrors. +[clinic start generated code]*/ + +PyDoc_STRVAR(_multibytecodec_MultibyteCodec_encode__doc__, +"sig=($self, input, errors=None)\n" +"Return an encoded string version of `input\'.\n" +"\n" +"\'errors\' may be given to set a different error handling scheme. Default is\n" +"\'strict\' meaning that encoding errors raise a UnicodeEncodeError. Other possible\n" +"values are \'ignore\', \'replace\' and \'xmlcharrefreplace\' as well as any other name\n" +"registered with codecs.register_error that can handle UnicodeEncodeErrors."); + +#define _MULTIBYTECODEC_MULTIBYTECODEC_ENCODE_METHODDEF \ + {"encode", (PyCFunction)_multibytecodec_MultibyteCodec_encode, METH_VARARGS|METH_KEYWORDS, _multibytecodec_MultibyteCodec_encode__doc__}, + static PyObject * -MultibyteCodec_Encode(MultibyteCodecObject *self, - PyObject *args, PyObject *kwargs) +_multibytecodec_MultibyteCodec_encode_impl(MultibyteCodecObject *self, PyObject *input, const char *errors); + +static PyObject * +_multibytecodec_MultibyteCodec_encode(MultibyteCodecObject *self, PyObject *args, PyObject *kwargs) +{ + PyObject *return_value = NULL; + static char *_keywords[] = {"input", "errors", NULL}; + PyObject *input; + const char *errors = NULL; + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, + "O|z:encode", _keywords, + &input, &errors)) + goto exit; + return_value = _multibytecodec_MultibyteCodec_encode_impl(self, input, errors); + +exit: + return return_value; +} + +static PyObject * +_multibytecodec_MultibyteCodec_encode_impl(MultibyteCodecObject *self, PyObject *input, const char *errors) +/*[clinic end generated code: output=a4391383e9f75f62 input=252e7ee695867b2d]*/ { MultibyteCodec_State state; - PyObject *errorcb, *r, *arg, *ucvt; - const char *errors = NULL; + PyObject *errorcb, *r, *ucvt; Py_ssize_t datalen; - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|z:encode", - codeckwarglist, &arg, &errors)) - return NULL; - - if (PyUnicode_Check(arg)) + if (PyUnicode_Check(input)) ucvt = NULL; else { - arg = ucvt = PyObject_Str(arg); - if (arg == NULL) + input = ucvt = PyObject_Str(input); + if (input == NULL) return NULL; - else if (!PyUnicode_Check(arg)) { + else if (!PyUnicode_Check(input)) { PyErr_SetString(PyExc_TypeError, "couldn't convert the object to unicode."); Py_DECREF(ucvt); @@ -577,11 +609,11 @@ } } - if (PyUnicode_READY(arg) < 0) { + if (PyUnicode_READY(input) < 0) { Py_XDECREF(ucvt); return NULL; } - datalen = PyUnicode_GET_LENGTH(arg); + datalen = PyUnicode_GET_LENGTH(input); errorcb = internal_error_callback(errors); if (errorcb == NULL) { @@ -593,7 +625,7 @@ self->codec->encinit(&state, self->codec->config) != 0) goto errorexit; r = multibytecodec_encode(self->codec, &state, - arg, NULL, errorcb, + input, NULL, errorcb, MBENC_FLUSH | MBENC_RESET); if (r == NULL) goto errorexit; @@ -608,31 +640,76 @@ return NULL; } +/*[clinic input] +_multibytecodec.MultibyteCodec.decode + + input: Py_buffer + errors: str(nullable=True) = NULL + +Decodes `string' using I, an MultibyteCodec instance. + +'errors' may be given to set a different error handling scheme. Default is +'strict' meaning that encoding errors raise a UnicodeDecodeError. Other possible +values are 'ignore' and 'replace' as well as any other name registered with +codecs.register_error that is able to handle UnicodeDecodeErrors." +[clinic start generated code]*/ + +PyDoc_STRVAR(_multibytecodec_MultibyteCodec_decode__doc__, +"sig=($self, input, errors=None)\n" +"Decodes `string\' using I, an MultibyteCodec instance.\n" +"\n" +"\'errors\' may be given to set a different error handling scheme. Default is\n" +"\'strict\' meaning that encoding errors raise a UnicodeDecodeError. Other possible\n" +"values are \'ignore\' and \'replace\' as well as any other name registered with\n" +"codecs.register_error that is able to handle UnicodeDecodeErrors.\""); + +#define _MULTIBYTECODEC_MULTIBYTECODEC_DECODE_METHODDEF \ + {"decode", (PyCFunction)_multibytecodec_MultibyteCodec_decode, METH_VARARGS|METH_KEYWORDS, _multibytecodec_MultibyteCodec_decode__doc__}, + static PyObject * -MultibyteCodec_Decode(MultibyteCodecObject *self, - PyObject *args, PyObject *kwargs) +_multibytecodec_MultibyteCodec_decode_impl(MultibyteCodecObject *self, Py_buffer *input, const char *errors); + +static PyObject * +_multibytecodec_MultibyteCodec_decode(MultibyteCodecObject *self, PyObject *args, PyObject *kwargs) +{ + PyObject *return_value = NULL; + static char *_keywords[] = {"input", "errors", NULL}; + Py_buffer input = {NULL, NULL}; + const char *errors = NULL; + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, + "y*|z:decode", _keywords, + &input, &errors)) + goto exit; + return_value = _multibytecodec_MultibyteCodec_decode_impl(self, &input, errors); + +exit: + /* Cleanup for input */ + if (input.obj) + PyBuffer_Release(&input); + + return return_value; +} + +static PyObject * +_multibytecodec_MultibyteCodec_decode_impl(MultibyteCodecObject *self, Py_buffer *input, const char *errors) +/*[clinic end generated code: output=5d46a61a6ae3e495 input=690774ec480a67a4]*/ { MultibyteCodec_State state; MultibyteDecodeBuffer buf; PyObject *errorcb, *res; - Py_buffer pdata; - const char *data, *errors = NULL; + const char *data; Py_ssize_t datalen; - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "y*|z:decode", - codeckwarglist, &pdata, &errors)) - return NULL; - data = pdata.buf; - datalen = pdata.len; + data = input->buf; + datalen = input->len; errorcb = internal_error_callback(errors); if (errorcb == NULL) { - PyBuffer_Release(&pdata); return NULL; } if (datalen == 0) { - PyBuffer_Release(&pdata); ERROR_DECREF(errorcb); return make_tuple(PyUnicode_New(0, 0), 0); } @@ -665,13 +742,11 @@ if (res == NULL) goto errorexit; - PyBuffer_Release(&pdata); Py_XDECREF(buf.excobj); ERROR_DECREF(errorcb); return make_tuple(res, datalen); errorexit: - PyBuffer_Release(&pdata); ERROR_DECREF(errorcb); Py_XDECREF(buf.excobj); _PyUnicodeWriter_Dealloc(&buf.writer); @@ -680,13 +755,9 @@ } static struct PyMethodDef multibytecodec_methods[] = { - {"encode", (PyCFunction)MultibyteCodec_Encode, - METH_VARARGS | METH_KEYWORDS, - MultibyteCodec_Encode__doc__}, - {"decode", (PyCFunction)MultibyteCodec_Decode, - METH_VARARGS | METH_KEYWORDS, - MultibyteCodec_Decode__doc__}, - {NULL, NULL}, + _MULTIBYTECODEC_MULTIBYTECODEC_ENCODE_METHODDEF + _MULTIBYTECODEC_MULTIBYTECODEC_DECODE_METHODDEF + {NULL, NULL}, }; static void @@ -870,26 +941,74 @@ } -/** - * MultibyteIncrementalEncoder object - */ +/*[clinic input] + class _multibytecodec.MultibyteIncrementalEncoder "MultibyteIncrementalEncoderObject *" "&MultibyteIncrementalEncoder_Type" +[clinic start generated code]*/ +/*[clinic end generated code: output=da39a3ee5e6b4b0d input=3be82909cd08924d]*/ + +/*[clinic input] +_multibytecodec.MultibyteIncrementalEncoder.encode + + input: object + final: int = 0 +[clinic start generated code]*/ + +PyDoc_STRVAR(_multibytecodec_MultibyteIncrementalEncoder_encode__doc__, +"sig=($self, input, final=0)"); + +#define _MULTIBYTECODEC_MULTIBYTEINCREMENTALENCODER_ENCODE_METHODDEF \ + {"encode", (PyCFunction)_multibytecodec_MultibyteIncrementalEncoder_encode, METH_VARARGS|METH_KEYWORDS, _multibytecodec_MultibyteIncrementalEncoder_encode__doc__}, static PyObject * -mbiencoder_encode(MultibyteIncrementalEncoderObject *self, - PyObject *args, PyObject *kwargs) +_multibytecodec_MultibyteIncrementalEncoder_encode_impl(MultibyteIncrementalEncoderObject *self, PyObject *input, int final); + +static PyObject * +_multibytecodec_MultibyteIncrementalEncoder_encode(MultibyteIncrementalEncoderObject *self, PyObject *args, PyObject *kwargs) { - PyObject *data; + PyObject *return_value = NULL; + static char *_keywords[] = {"input", "final", NULL}; + PyObject *input; int final = 0; - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|i:encode", - incrementalkwarglist, &data, &final)) - return NULL; + if (!PyArg_ParseTupleAndKeywords(args, kwargs, + "O|i:encode", _keywords, + &input, &final)) + goto exit; + return_value = _multibytecodec_MultibyteIncrementalEncoder_encode_impl(self, input, final); - return encoder_encode_stateful(STATEFUL_ECTX(self), data, final); +exit: + return return_value; } static PyObject * -mbiencoder_reset(MultibyteIncrementalEncoderObject *self) +_multibytecodec_MultibyteIncrementalEncoder_encode_impl(MultibyteIncrementalEncoderObject *self, PyObject *input, int final) +/*[clinic end generated code: output=937c8a8bfe071b5b input=456b76d73e464661]*/ +{ + return encoder_encode_stateful(STATEFUL_ECTX(self), input, final); +} + +/*[clinic input] +_multibytecodec.MultibyteIncrementalEncoder.reset +[clinic start generated code]*/ + +PyDoc_STRVAR(_multibytecodec_MultibyteIncrementalEncoder_reset__doc__, +"sig=($self)"); + +#define _MULTIBYTECODEC_MULTIBYTEINCREMENTALENCODER_RESET_METHODDEF \ + {"reset", (PyCFunction)_multibytecodec_MultibyteIncrementalEncoder_reset, METH_NOARGS, _multibytecodec_MultibyteIncrementalEncoder_reset__doc__}, + +static PyObject * +_multibytecodec_MultibyteIncrementalEncoder_reset_impl(MultibyteIncrementalEncoderObject *self); + +static PyObject * +_multibytecodec_MultibyteIncrementalEncoder_reset(MultibyteIncrementalEncoderObject *self, PyObject *Py_UNUSED(ignored)) +{ + return _multibytecodec_MultibyteIncrementalEncoder_reset_impl(self); +} + +static PyObject * +_multibytecodec_MultibyteIncrementalEncoder_reset_impl(MultibyteIncrementalEncoderObject *self) +/*[clinic end generated code: output=b52c9925b1dfe6c8 input=930f06760707b6ea]*/ { /* Longest output: 4 bytes (b'\x0F\x1F(B') with ISO 2022 */ unsigned char buffer[4], *outbuf; @@ -906,11 +1025,9 @@ } static struct PyMethodDef mbiencoder_methods[] = { - {"encode", (PyCFunction)mbiencoder_encode, - METH_VARARGS | METH_KEYWORDS, NULL}, - {"reset", (PyCFunction)mbiencoder_reset, - METH_NOARGS, NULL}, - {NULL, NULL}, + _MULTIBYTECODEC_MULTIBYTEINCREMENTALENCODER_ENCODE_METHODDEF + _MULTIBYTECODEC_MULTIBYTEINCREMENTALENCODER_RESET_METHODDEF + {NULL, NULL}, }; static PyObject * @@ -1021,26 +1138,60 @@ }; -/** - * MultibyteIncrementalDecoder object - */ +/*[clinic input] + class _multibytecodec.MultibyteIncrementalDecoder "MultibyteIncrementalDecoderObject *" "&MultibyteIncrementalDecoder_Type" +[clinic start generated code]*/ +/*[clinic end generated code: output=da39a3ee5e6b4b0d input=f6003faaf2cea692]*/ + +/*[clinic input] +_multibytecodec.MultibyteIncrementalDecoder.decode + + input: Py_buffer + final: int = 0 +[clinic start generated code]*/ + +PyDoc_STRVAR(_multibytecodec_MultibyteIncrementalDecoder_decode__doc__, +"sig=($self, input, final=0)"); + +#define _MULTIBYTECODEC_MULTIBYTEINCREMENTALDECODER_DECODE_METHODDEF \ + {"decode", (PyCFunction)_multibytecodec_MultibyteIncrementalDecoder_decode, METH_VARARGS|METH_KEYWORDS, _multibytecodec_MultibyteIncrementalDecoder_decode__doc__}, static PyObject * -mbidecoder_decode(MultibyteIncrementalDecoderObject *self, - PyObject *args, PyObject *kwargs) +_multibytecodec_MultibyteIncrementalDecoder_decode_impl(MultibyteIncrementalDecoderObject *self, Py_buffer *input, int final); + +static PyObject * +_multibytecodec_MultibyteIncrementalDecoder_decode(MultibyteIncrementalDecoderObject *self, PyObject *args, PyObject *kwargs) +{ + PyObject *return_value = NULL; + static char *_keywords[] = {"input", "final", NULL}; + Py_buffer input = {NULL, NULL}; + int final = 0; + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, + "y*|i:decode", _keywords, + &input, &final)) + goto exit; + return_value = _multibytecodec_MultibyteIncrementalDecoder_decode_impl(self, &input, final); + +exit: + /* Cleanup for input */ + if (input.obj) + PyBuffer_Release(&input); + + return return_value; +} + +static PyObject * +_multibytecodec_MultibyteIncrementalDecoder_decode_impl(MultibyteIncrementalDecoderObject *self, Py_buffer *input, int final) +/*[clinic end generated code: output=97ae3707f3a232f5 input=eb18c2f6e83589e1]*/ { MultibyteDecodeBuffer buf; char *data, *wdata = NULL; - Py_buffer pdata; Py_ssize_t wsize, size, origpending; - int final = 0; PyObject *res; - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "y*|i:decode", - incrementalkwarglist, &pdata, &final)) - return NULL; - data = pdata.buf; - size = pdata.len; + data = input->buf; + size = input->len; _PyUnicodeWriter_Init(&buf.writer); buf.excobj = NULL; @@ -1091,14 +1242,12 @@ if (res == NULL) goto errorexit; - PyBuffer_Release(&pdata); if (wdata != data) PyMem_Del(wdata); Py_XDECREF(buf.excobj); return res; errorexit: - PyBuffer_Release(&pdata); if (wdata != NULL && wdata != data) PyMem_Del(wdata); Py_XDECREF(buf.excobj); @@ -1106,8 +1255,28 @@ return NULL; } +/*[clinic input] +_multibytecodec.MultibyteIncrementalDecoder.reset +[clinic start generated code]*/ + +PyDoc_STRVAR(_multibytecodec_MultibyteIncrementalDecoder_reset__doc__, +"sig=($self)"); + +#define _MULTIBYTECODEC_MULTIBYTEINCREMENTALDECODER_RESET_METHODDEF \ + {"reset", (PyCFunction)_multibytecodec_MultibyteIncrementalDecoder_reset, METH_NOARGS, _multibytecodec_MultibyteIncrementalDecoder_reset__doc__}, + static PyObject * -mbidecoder_reset(MultibyteIncrementalDecoderObject *self) +_multibytecodec_MultibyteIncrementalDecoder_reset_impl(MultibyteIncrementalDecoderObject *self); + +static PyObject * +_multibytecodec_MultibyteIncrementalDecoder_reset(MultibyteIncrementalDecoderObject *self, PyObject *Py_UNUSED(ignored)) +{ + return _multibytecodec_MultibyteIncrementalDecoder_reset_impl(self); +} + +static PyObject * +_multibytecodec_MultibyteIncrementalDecoder_reset_impl(MultibyteIncrementalDecoderObject *self) +/*[clinic end generated code: output=d5388d03378d2dc6 input=3b63b3be85b2fb45]*/ { if (self->codec->decreset != NULL && self->codec->decreset(&self->state, self->codec->config) != 0) @@ -1118,11 +1287,9 @@ } static struct PyMethodDef mbidecoder_methods[] = { - {"decode", (PyCFunction)mbidecoder_decode, - METH_VARARGS | METH_KEYWORDS, NULL}, - {"reset", (PyCFunction)mbidecoder_reset, - METH_NOARGS, NULL}, - {NULL, NULL}, + _MULTIBYTECODEC_MULTIBYTEINCREMENTALDECODER_DECODE_METHODDEF + _MULTIBYTECODEC_MULTIBYTEINCREMENTALDECODER_RESET_METHODDEF + {NULL, NULL}, }; static PyObject * @@ -1233,9 +1400,10 @@ }; -/** - * MultibyteStreamReader object - */ +/*[clinic input] + class _multibytecodec.MultibyteStreamReader "MultibyteStreamReaderObject *" "MultibyteStreamReader_Type" +[clinic start generated code]*/ +/*[clinic end generated code: output=da39a3ee5e6b4b0d input=d323634b74976f09]*/ static PyObject * mbstreamreader_iread(MultibyteStreamReaderObject *self, @@ -1342,16 +1510,45 @@ return NULL; } +/*[clinic input] + _multibytecodec.MultibyteStreamReader.read + + sizeobj: object = None + / +[clinic start generated code]*/ + +PyDoc_STRVAR(_multibytecodec_MultibyteStreamReader_read__doc__, +"sig=($self, sizeobj=None)"); + +#define _MULTIBYTECODEC_MULTIBYTESTREAMREADER_READ_METHODDEF \ + {"read", (PyCFunction)_multibytecodec_MultibyteStreamReader_read, METH_VARARGS, _multibytecodec_MultibyteStreamReader_read__doc__}, + static PyObject * -mbstreamreader_read(MultibyteStreamReaderObject *self, PyObject *args) +_multibytecodec_MultibyteStreamReader_read_impl(MultibyteStreamReaderObject *self, PyObject *sizeobj); + +static PyObject * +_multibytecodec_MultibyteStreamReader_read(MultibyteStreamReaderObject *self, PyObject *args) { - PyObject *sizeobj = NULL; + PyObject *return_value = NULL; + PyObject *sizeobj = Py_None; + + if (!PyArg_UnpackTuple(args, "read", + 0, 1, + &sizeobj)) + goto exit; + return_value = _multibytecodec_MultibyteStreamReader_read_impl(self, sizeobj); + +exit: + return return_value; +} + +static PyObject * +_multibytecodec_MultibyteStreamReader_read_impl(MultibyteStreamReaderObject *self, PyObject *sizeobj) +/*[clinic end generated code: output=71387f4ee1444906 input=015b0d3ff2fca485]*/ +{ Py_ssize_t size; - if (!PyArg_UnpackTuple(args, "read", 0, 1, &sizeobj)) - return NULL; - - if (sizeobj == Py_None || sizeobj == NULL) + if (sizeobj == Py_None) size = -1; else if (PyLong_Check(sizeobj)) size = PyLong_AsSsize_t(sizeobj); @@ -1366,16 +1563,45 @@ return mbstreamreader_iread(self, "read", size); } +/*[clinic input] + _multibytecodec.MultibyteStreamReader.readline + + sizeobj: object = None + / +[clinic start generated code]*/ + +PyDoc_STRVAR(_multibytecodec_MultibyteStreamReader_readline__doc__, +"sig=($self, sizeobj=None)"); + +#define _MULTIBYTECODEC_MULTIBYTESTREAMREADER_READLINE_METHODDEF \ + {"readline", (PyCFunction)_multibytecodec_MultibyteStreamReader_readline, METH_VARARGS, _multibytecodec_MultibyteStreamReader_readline__doc__}, + static PyObject * -mbstreamreader_readline(MultibyteStreamReaderObject *self, PyObject *args) +_multibytecodec_MultibyteStreamReader_readline_impl(MultibyteStreamReaderObject *self, PyObject *sizeobj); + +static PyObject * +_multibytecodec_MultibyteStreamReader_readline(MultibyteStreamReaderObject *self, PyObject *args) { - PyObject *sizeobj = NULL; + PyObject *return_value = NULL; + PyObject *sizeobj = Py_None; + + if (!PyArg_UnpackTuple(args, "readline", + 0, 1, + &sizeobj)) + goto exit; + return_value = _multibytecodec_MultibyteStreamReader_readline_impl(self, sizeobj); + +exit: + return return_value; +} + +static PyObject * +_multibytecodec_MultibyteStreamReader_readline_impl(MultibyteStreamReaderObject *self, PyObject *sizeobj) +/*[clinic end generated code: output=9ff9fc07a4574db4 input=41ccc64f9bb0cec3]*/ +{ Py_ssize_t size; - if (!PyArg_UnpackTuple(args, "readline", 0, 1, &sizeobj)) - return NULL; - - if (sizeobj == Py_None || sizeobj == NULL) + if (sizeobj == Py_None) size = -1; else if (PyLong_Check(sizeobj)) size = PyLong_AsSsize_t(sizeobj); @@ -1390,16 +1616,46 @@ return mbstreamreader_iread(self, "readline", size); } +/*[clinic input] + _multibytecodec.MultibyteStreamReader.readlines + + sizehintobj: object = None + / +[clinic start generated code]*/ + +PyDoc_STRVAR(_multibytecodec_MultibyteStreamReader_readlines__doc__, +"sig=($self, sizehintobj=None)"); + +#define _MULTIBYTECODEC_MULTIBYTESTREAMREADER_READLINES_METHODDEF \ + {"readlines", (PyCFunction)_multibytecodec_MultibyteStreamReader_readlines, METH_VARARGS, _multibytecodec_MultibyteStreamReader_readlines__doc__}, + static PyObject * -mbstreamreader_readlines(MultibyteStreamReaderObject *self, PyObject *args) +_multibytecodec_MultibyteStreamReader_readlines_impl(MultibyteStreamReaderObject *self, PyObject *sizehintobj); + +static PyObject * +_multibytecodec_MultibyteStreamReader_readlines(MultibyteStreamReaderObject *self, PyObject *args) { - PyObject *sizehintobj = NULL, *r, *sr; + PyObject *return_value = NULL; + PyObject *sizehintobj = Py_None; + + if (!PyArg_UnpackTuple(args, "readlines", + 0, 1, + &sizehintobj)) + goto exit; + return_value = _multibytecodec_MultibyteStreamReader_readlines_impl(self, sizehintobj); + +exit: + return return_value; +} + +static PyObject * +_multibytecodec_MultibyteStreamReader_readlines_impl(MultibyteStreamReaderObject *self, PyObject *sizehintobj) +/*[clinic end generated code: output=7d4fadf1e02868ef input=54932f5d4d88e880]*/ +{ + PyObject *r, *sr; Py_ssize_t sizehint; - if (!PyArg_UnpackTuple(args, "readlines", 0, 1, &sizehintobj)) - return NULL; - - if (sizehintobj == Py_None || sizehintobj == NULL) + if (sizehintobj == Py_None) sizehint = -1; else if (PyLong_Check(sizehintobj)) sizehint = PyLong_AsSsize_t(sizehintobj); @@ -1420,8 +1676,28 @@ return sr; } +/*[clinic input] + _multibytecodec.MultibyteStreamReader.reset +[clinic start generated code]*/ + +PyDoc_STRVAR(_multibytecodec_MultibyteStreamReader_reset__doc__, +"sig=($self)"); + +#define _MULTIBYTECODEC_MULTIBYTESTREAMREADER_RESET_METHODDEF \ + {"reset", (PyCFunction)_multibytecodec_MultibyteStreamReader_reset, METH_NOARGS, _multibytecodec_MultibyteStreamReader_reset__doc__}, + static PyObject * -mbstreamreader_reset(MultibyteStreamReaderObject *self) +_multibytecodec_MultibyteStreamReader_reset_impl(MultibyteStreamReaderObject *self); + +static PyObject * +_multibytecodec_MultibyteStreamReader_reset(MultibyteStreamReaderObject *self, PyObject *Py_UNUSED(ignored)) +{ + return _multibytecodec_MultibyteStreamReader_reset_impl(self); +} + +static PyObject * +_multibytecodec_MultibyteStreamReader_reset_impl(MultibyteStreamReaderObject *self) +/*[clinic end generated code: output=4a0be813f11a3948 input=5d4140db84b5e1e2]*/ { if (self->codec->decreset != NULL && self->codec->decreset(&self->state, self->codec->config) != 0) @@ -1432,14 +1708,10 @@ } static struct PyMethodDef mbstreamreader_methods[] = { - {"read", (PyCFunction)mbstreamreader_read, - METH_VARARGS, NULL}, - {"readline", (PyCFunction)mbstreamreader_readline, - METH_VARARGS, NULL}, - {"readlines", (PyCFunction)mbstreamreader_readlines, - METH_VARARGS, NULL}, - {"reset", (PyCFunction)mbstreamreader_reset, - METH_NOARGS, NULL}, + _MULTIBYTECODEC_MULTIBYTESTREAMREADER_READ_METHODDEF + _MULTIBYTECODEC_MULTIBYTESTREAMREADER_READLINE_METHODDEF + _MULTIBYTECODEC_MULTIBYTESTREAMREADER_READLINES_METHODDEF + _MULTIBYTECODEC_MULTIBYTESTREAMREADER_RESET_METHODDEF {NULL, NULL}, }; @@ -1562,9 +1834,10 @@ }; -/** - * MultibyteStreamWriter object - */ +/*[clinic input] + class _multibytecodec.MultibyteStreamWriter "MultibyteStreamWriterObject *" "&MultibyteStreamWriter_Type" +[clinic start generated code]*/ +/*[clinic end generated code: output=da39a3ee5e6b4b0d input=cde22780a215d6ac]*/ static int mbstreamwriter_iwrite(MultibyteStreamWriterObject *self, @@ -1585,8 +1858,22 @@ return 0; } +/*[clinic input] + _multibytecodec.MultibyteStreamWriter.write + + strobj: object + / +[clinic start generated code]*/ + +PyDoc_STRVAR(_multibytecodec_MultibyteStreamWriter_write__doc__, +"sig=($self, strobj)"); + +#define _MULTIBYTECODEC_MULTIBYTESTREAMWRITER_WRITE_METHODDEF \ + {"write", (PyCFunction)_multibytecodec_MultibyteStreamWriter_write, METH_O, _multibytecodec_MultibyteStreamWriter_write__doc__}, + static PyObject * -mbstreamwriter_write(MultibyteStreamWriterObject *self, PyObject *strobj) +_multibytecodec_MultibyteStreamWriter_write(MultibyteStreamWriterObject *self, PyObject *strobj) +/*[clinic end generated code: output=86397c4699f50e2f input=551dc4c018c10a2b]*/ { if (mbstreamwriter_iwrite(self, strobj)) return NULL; @@ -1594,8 +1881,22 @@ Py_RETURN_NONE; } +/*[clinic input] + _multibytecodec.MultibyteStreamWriter.writelines + + lines: object + / +[clinic start generated code]*/ + +PyDoc_STRVAR(_multibytecodec_MultibyteStreamWriter_writelines__doc__, +"sig=($self, lines)"); + +#define _MULTIBYTECODEC_MULTIBYTESTREAMWRITER_WRITELINES_METHODDEF \ + {"writelines", (PyCFunction)_multibytecodec_MultibyteStreamWriter_writelines, METH_O, _multibytecodec_MultibyteStreamWriter_writelines__doc__}, + static PyObject * -mbstreamwriter_writelines(MultibyteStreamWriterObject *self, PyObject *lines) +_multibytecodec_MultibyteStreamWriter_writelines(MultibyteStreamWriterObject *self, PyObject *lines) +/*[clinic end generated code: output=b6590ae9a42d3267 input=57797fe7008d4e96]*/ { PyObject *strobj; int i, r; @@ -1621,8 +1922,28 @@ Py_RETURN_NONE; } +/*[clinic input] + _multibytecodec.MultibyteStreamWriter.reset +[clinic start generated code]*/ + +PyDoc_STRVAR(_multibytecodec_MultibyteStreamWriter_reset__doc__, +"sig=($self)"); + +#define _MULTIBYTECODEC_MULTIBYTESTREAMWRITER_RESET_METHODDEF \ + {"reset", (PyCFunction)_multibytecodec_MultibyteStreamWriter_reset, METH_NOARGS, _multibytecodec_MultibyteStreamWriter_reset__doc__}, + static PyObject * -mbstreamwriter_reset(MultibyteStreamWriterObject *self) +_multibytecodec_MultibyteStreamWriter_reset_impl(MultibyteStreamWriterObject *self); + +static PyObject * +_multibytecodec_MultibyteStreamWriter_reset(MultibyteStreamWriterObject *self, PyObject *Py_UNUSED(ignored)) +{ + return _multibytecodec_MultibyteStreamWriter_reset_impl(self); +} + +static PyObject * +_multibytecodec_MultibyteStreamWriter_reset_impl(MultibyteStreamWriterObject *self) +/*[clinic end generated code: output=35dc783dca1058c3 input=b56dbcbaf35cc10c]*/ { PyObject *pwrt; @@ -1721,13 +2042,10 @@ } static struct PyMethodDef mbstreamwriter_methods[] = { - {"write", (PyCFunction)mbstreamwriter_write, - METH_O, NULL}, - {"writelines", (PyCFunction)mbstreamwriter_writelines, - METH_O, NULL}, - {"reset", (PyCFunction)mbstreamwriter_reset, - METH_NOARGS, NULL}, - {NULL, NULL}, + _MULTIBYTECODEC_MULTIBYTESTREAMWRITER_WRITE_METHODDEF + _MULTIBYTECODEC_MULTIBYTESTREAMWRITER_WRITELINES_METHODDEF + _MULTIBYTECODEC_MULTIBYTESTREAMWRITER_RESET_METHODDEF + {NULL, NULL}, }; static PyMemberDef mbstreamwriter_members[] = { @@ -1781,12 +2099,22 @@ }; -/** - * Exposed factory function - */ +/*[clinic input] +_multibytecodec.__create_codec + + arg: object + / +[clinic start generated code]*/ + +PyDoc_STRVAR(_multibytecodec___create_codec__doc__, +"sig=($module, arg)"); + +#define _MULTIBYTECODEC___CREATE_CODEC_METHODDEF \ + {"__create_codec", (PyCFunction)_multibytecodec___create_codec, METH_O, _multibytecodec___create_codec__doc__}, static PyObject * -__create_codec(PyObject *ignore, PyObject *arg) +_multibytecodec___create_codec(PyModuleDef *module, PyObject *arg) +/*[clinic end generated code: output=ee33ff9e5d789e85 input=6840b2a6b183fcfa]*/ { MultibyteCodecObject *self; MultibyteCodec *codec; @@ -1809,7 +2137,7 @@ } static struct PyMethodDef __methods[] = { - {"__create_codec", (PyCFunction)__create_codec, METH_O}, + _MULTIBYTECODEC___CREATE_CODEC_METHODDEF {NULL, NULL}, };