summaryrefslogtreecommitdiff
path: root/Modules/cjkcodecs
diff options
context:
space:
mode:
authorBrett Cannon <brett@python.org>2014-08-22 11:45:03 -0400
committerBrett Cannon <brett@python.org>2014-08-22 11:45:03 -0400
commit9f6fc301a69d54a2ec7b516cab30043ddcfccc38 (patch)
tree305462497266ed02d500172a956b443851a8f544 /Modules/cjkcodecs
parent4092b14a79c4b69d2904b015f6cb371fc0a97b34 (diff)
downloadcpython-9f6fc301a69d54a2ec7b516cab30043ddcfccc38.tar.gz
Issue #20152: Convert _multibytecodecs to Argument Clinic.
Diffstat (limited to 'Modules/cjkcodecs')
-rw-r--r--Modules/cjkcodecs/clinic/multibytecodec.c.h301
-rw-r--r--Modules/cjkcodecs/multibytecodec.c333
2 files changed, 492 insertions, 142 deletions
diff --git a/Modules/cjkcodecs/clinic/multibytecodec.c.h b/Modules/cjkcodecs/clinic/multibytecodec.c.h
new file mode 100644
index 0000000000..2f9cb63927
--- /dev/null
+++ b/Modules/cjkcodecs/clinic/multibytecodec.c.h
@@ -0,0 +1,301 @@
+/*[clinic input]
+preserve
+[clinic start generated code]*/
+
+PyDoc_STRVAR(_multibytecodec_MultibyteCodec_encode__doc__,
+"encode($self, /, input, errors=None)\n"
+"--\n"
+"\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_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;
+}
+
+PyDoc_STRVAR(_multibytecodec_MultibyteCodec_decode__doc__,
+"decode($self, /, input, errors=None)\n"
+"--\n"
+"\n"
+"Decodes \'input\'.\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_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;
+}
+
+PyDoc_STRVAR(_multibytecodec_MultibyteIncrementalEncoder_encode__doc__,
+"encode($self, /, input, final=0)\n"
+"--");
+
+#define _MULTIBYTECODEC_MULTIBYTEINCREMENTALENCODER_ENCODE_METHODDEF \
+ {"encode", (PyCFunction)_multibytecodec_MultibyteIncrementalEncoder_encode, METH_VARARGS|METH_KEYWORDS, _multibytecodec_MultibyteIncrementalEncoder_encode__doc__},
+
+static PyObject *
+_multibytecodec_MultibyteIncrementalEncoder_encode_impl(MultibyteIncrementalEncoderObject *self, PyObject *input, int final);
+
+static PyObject *
+_multibytecodec_MultibyteIncrementalEncoder_encode(MultibyteIncrementalEncoderObject *self, PyObject *args, PyObject *kwargs)
+{
+ PyObject *return_value = NULL;
+ static char *_keywords[] = {"input", "final", NULL};
+ PyObject *input;
+ int final = 0;
+
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs,
+ "O|i:encode", _keywords,
+ &input, &final))
+ goto exit;
+ return_value = _multibytecodec_MultibyteIncrementalEncoder_encode_impl(self, input, final);
+
+exit:
+ return return_value;
+}
+
+PyDoc_STRVAR(_multibytecodec_MultibyteIncrementalEncoder_reset__doc__,
+"reset($self, /)\n"
+"--");
+
+#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);
+}
+
+PyDoc_STRVAR(_multibytecodec_MultibyteIncrementalDecoder_decode__doc__,
+"decode($self, /, input, final=0)\n"
+"--");
+
+#define _MULTIBYTECODEC_MULTIBYTEINCREMENTALDECODER_DECODE_METHODDEF \
+ {"decode", (PyCFunction)_multibytecodec_MultibyteIncrementalDecoder_decode, METH_VARARGS|METH_KEYWORDS, _multibytecodec_MultibyteIncrementalDecoder_decode__doc__},
+
+static PyObject *
+_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;
+}
+
+PyDoc_STRVAR(_multibytecodec_MultibyteIncrementalDecoder_reset__doc__,
+"reset($self, /)\n"
+"--");
+
+#define _MULTIBYTECODEC_MULTIBYTEINCREMENTALDECODER_RESET_METHODDEF \
+ {"reset", (PyCFunction)_multibytecodec_MultibyteIncrementalDecoder_reset, METH_NOARGS, _multibytecodec_MultibyteIncrementalDecoder_reset__doc__},
+
+static PyObject *
+_multibytecodec_MultibyteIncrementalDecoder_reset_impl(MultibyteIncrementalDecoderObject *self);
+
+static PyObject *
+_multibytecodec_MultibyteIncrementalDecoder_reset(MultibyteIncrementalDecoderObject *self, PyObject *Py_UNUSED(ignored))
+{
+ return _multibytecodec_MultibyteIncrementalDecoder_reset_impl(self);
+}
+
+PyDoc_STRVAR(_multibytecodec_MultibyteStreamReader_read__doc__,
+"read($self, sizeobj=None, /)\n"
+"--");
+
+#define _MULTIBYTECODEC_MULTIBYTESTREAMREADER_READ_METHODDEF \
+ {"read", (PyCFunction)_multibytecodec_MultibyteStreamReader_read, METH_VARARGS, _multibytecodec_MultibyteStreamReader_read__doc__},
+
+static PyObject *
+_multibytecodec_MultibyteStreamReader_read_impl(MultibyteStreamReaderObject *self, PyObject *sizeobj);
+
+static PyObject *
+_multibytecodec_MultibyteStreamReader_read(MultibyteStreamReaderObject *self, PyObject *args)
+{
+ 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;
+}
+
+PyDoc_STRVAR(_multibytecodec_MultibyteStreamReader_readline__doc__,
+"readline($self, sizeobj=None, /)\n"
+"--");
+
+#define _MULTIBYTECODEC_MULTIBYTESTREAMREADER_READLINE_METHODDEF \
+ {"readline", (PyCFunction)_multibytecodec_MultibyteStreamReader_readline, METH_VARARGS, _multibytecodec_MultibyteStreamReader_readline__doc__},
+
+static PyObject *
+_multibytecodec_MultibyteStreamReader_readline_impl(MultibyteStreamReaderObject *self, PyObject *sizeobj);
+
+static PyObject *
+_multibytecodec_MultibyteStreamReader_readline(MultibyteStreamReaderObject *self, PyObject *args)
+{
+ 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;
+}
+
+PyDoc_STRVAR(_multibytecodec_MultibyteStreamReader_readlines__doc__,
+"readlines($self, sizehintobj=None, /)\n"
+"--");
+
+#define _MULTIBYTECODEC_MULTIBYTESTREAMREADER_READLINES_METHODDEF \
+ {"readlines", (PyCFunction)_multibytecodec_MultibyteStreamReader_readlines, METH_VARARGS, _multibytecodec_MultibyteStreamReader_readlines__doc__},
+
+static PyObject *
+_multibytecodec_MultibyteStreamReader_readlines_impl(MultibyteStreamReaderObject *self, PyObject *sizehintobj);
+
+static PyObject *
+_multibytecodec_MultibyteStreamReader_readlines(MultibyteStreamReaderObject *self, PyObject *args)
+{
+ 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;
+}
+
+PyDoc_STRVAR(_multibytecodec_MultibyteStreamReader_reset__doc__,
+"reset($self, /)\n"
+"--");
+
+#define _MULTIBYTECODEC_MULTIBYTESTREAMREADER_RESET_METHODDEF \
+ {"reset", (PyCFunction)_multibytecodec_MultibyteStreamReader_reset, METH_NOARGS, _multibytecodec_MultibyteStreamReader_reset__doc__},
+
+static PyObject *
+_multibytecodec_MultibyteStreamReader_reset_impl(MultibyteStreamReaderObject *self);
+
+static PyObject *
+_multibytecodec_MultibyteStreamReader_reset(MultibyteStreamReaderObject *self, PyObject *Py_UNUSED(ignored))
+{
+ return _multibytecodec_MultibyteStreamReader_reset_impl(self);
+}
+
+PyDoc_STRVAR(_multibytecodec_MultibyteStreamWriter_write__doc__,
+"write($self, strobj, /)\n"
+"--");
+
+#define _MULTIBYTECODEC_MULTIBYTESTREAMWRITER_WRITE_METHODDEF \
+ {"write", (PyCFunction)_multibytecodec_MultibyteStreamWriter_write, METH_O, _multibytecodec_MultibyteStreamWriter_write__doc__},
+
+PyDoc_STRVAR(_multibytecodec_MultibyteStreamWriter_writelines__doc__,
+"writelines($self, lines, /)\n"
+"--");
+
+#define _MULTIBYTECODEC_MULTIBYTESTREAMWRITER_WRITELINES_METHODDEF \
+ {"writelines", (PyCFunction)_multibytecodec_MultibyteStreamWriter_writelines, METH_O, _multibytecodec_MultibyteStreamWriter_writelines__doc__},
+
+PyDoc_STRVAR(_multibytecodec_MultibyteStreamWriter_reset__doc__,
+"reset($self, /)\n"
+"--");
+
+#define _MULTIBYTECODEC_MULTIBYTESTREAMWRITER_RESET_METHODDEF \
+ {"reset", (PyCFunction)_multibytecodec_MultibyteStreamWriter_reset, METH_NOARGS, _multibytecodec_MultibyteStreamWriter_reset__doc__},
+
+static PyObject *
+_multibytecodec_MultibyteStreamWriter_reset_impl(MultibyteStreamWriterObject *self);
+
+static PyObject *
+_multibytecodec_MultibyteStreamWriter_reset(MultibyteStreamWriterObject *self, PyObject *Py_UNUSED(ignored))
+{
+ return _multibytecodec_MultibyteStreamWriter_reset_impl(self);
+}
+
+PyDoc_STRVAR(_multibytecodec___create_codec__doc__,
+"__create_codec($module, arg, /)\n"
+"--");
+
+#define _MULTIBYTECODEC___CREATE_CODEC_METHODDEF \
+ {"__create_codec", (PyCFunction)_multibytecodec___create_codec, METH_O, _multibytecodec___create_codec__doc__},
+/*[clinic end generated code: output=dff1459dec464796 input=a9049054013a1b77]*/
diff --git a/Modules/cjkcodecs/multibytecodec.c b/Modules/cjkcodecs/multibytecodec.c
index 087ae9b1af..74ecafd3d6 100644
--- a/Modules/cjkcodecs/multibytecodec.c
+++ b/Modules/cjkcodecs/multibytecodec.c
@@ -8,6 +8,18 @@
#include "Python.h"
#include "structmember.h"
#include "multibytecodec.h"
+#include "clinic/multibytecodec.c.h"
+
+/*[clinic input]
+output preset file
+module _multibytecodec
+[clinic start generated code]*/
+/*[clinic end generated code: output=da39a3ee5e6b4b0d input=e0cf1b7f3c472d17]*/
+
+/*[clinic input]
+class _multibytecodec.MultibyteCodec "MultibyteCodecObject *" "&MultibyteCodec_Type"
+[clinic start generated code]*/
+/*[clinic end generated code: output=da39a3ee5e6b4b0d input=d5b1fc1fec8eb003]*/
typedef struct {
PyObject *inobj;
@@ -22,27 +34,7 @@ typedef struct {
_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 +542,35 @@ errorexit:
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]*/
+
static PyObject *
-MultibyteCodec_Encode(MultibyteCodecObject *self,
- PyObject *args, PyObject *kwargs)
+_multibytecodec_MultibyteCodec_encode_impl(MultibyteCodecObject *self, PyObject *input, const char *errors)
+/*[clinic end generated code: output=a36bfa08783a0d0b 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 +578,11 @@ MultibyteCodec_Encode(MultibyteCodecObject *self,
}
}
- 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 +594,7 @@ MultibyteCodec_Encode(MultibyteCodecObject *self,
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 +609,39 @@ errorexit:
return NULL;
}
+/*[clinic input]
+_multibytecodec.MultibyteCodec.decode
+
+ input: Py_buffer
+ errors: str(nullable=True) = NULL
+
+Decodes 'input'.
+
+'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]*/
+
static PyObject *
-MultibyteCodec_Decode(MultibyteCodecObject *self,
- PyObject *args, PyObject *kwargs)
+_multibytecodec_MultibyteCodec_decode_impl(MultibyteCodecObject *self, Py_buffer *input, const char *errors)
+/*[clinic end generated code: output=4c8ee8b2931b014e input=37e1d9236e3ce8f3]*/
{
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 +674,11 @@ MultibyteCodec_Decode(MultibyteCodecObject *self,
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 +687,9 @@ errorexit:
}
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 +873,32 @@ decoder_feed_buffer(MultibyteStatefulDecoderContext *ctx,
}
-/**
- * MultibyteIncrementalEncoder object
- */
+/*[clinic input]
+ class _multibytecodec.MultibyteIncrementalEncoder "MultibyteIncrementalEncoderObject *" "&MultibyteIncrementalEncoder_Type"
+[clinic start generated code]*/
+/*[clinic end generated code: output=da39a3ee5e6b4b0d input=3be82909cd08924d]*/
-static PyObject *
-mbiencoder_encode(MultibyteIncrementalEncoderObject *self,
- PyObject *args, PyObject *kwargs)
-{
- PyObject *data;
- int final = 0;
+/*[clinic input]
+_multibytecodec.MultibyteIncrementalEncoder.encode
- if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|i:encode",
- incrementalkwarglist, &data, &final))
- return NULL;
+ input: object
+ final: int = 0
+[clinic start generated code]*/
- return encoder_encode_stateful(STATEFUL_ECTX(self), data, final);
+static PyObject *
+_multibytecodec_MultibyteIncrementalEncoder_encode_impl(MultibyteIncrementalEncoderObject *self, PyObject *input, int final)
+/*[clinic end generated code: output=3cd8780c8a719bbf input=456b76d73e464661]*/
+{
+ return encoder_encode_stateful(STATEFUL_ECTX(self), input, final);
}
+/*[clinic input]
+_multibytecodec.MultibyteIncrementalEncoder.reset
+[clinic start generated code]*/
+
static PyObject *
-mbiencoder_reset(MultibyteIncrementalEncoderObject *self)
+_multibytecodec_MultibyteIncrementalEncoder_reset_impl(MultibyteIncrementalEncoderObject *self)
+/*[clinic end generated code: output=b4125d8f537a253f input=930f06760707b6ea]*/
{
/* Longest output: 4 bytes (b'\x0F\x1F(B') with ISO 2022 */
unsigned char buffer[4], *outbuf;
@@ -906,11 +915,9 @@ mbiencoder_reset(MultibyteIncrementalEncoderObject *self)
}
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 +1028,29 @@ static PyTypeObject MultibyteIncrementalEncoder_Type = {
};
-/**
- * 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]*/
static PyObject *
-mbidecoder_decode(MultibyteIncrementalDecoderObject *self,
- PyObject *args, PyObject *kwargs)
+_multibytecodec_MultibyteIncrementalDecoder_decode_impl(MultibyteIncrementalDecoderObject *self, Py_buffer *input, int final)
+/*[clinic end generated code: output=a0f3f92aa7303cf7 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 +1101,12 @@ mbidecoder_decode(MultibyteIncrementalDecoderObject *self,
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 +1114,13 @@ errorexit:
return NULL;
}
+/*[clinic input]
+_multibytecodec.MultibyteIncrementalDecoder.reset
+[clinic start generated code]*/
+
static PyObject *
-mbidecoder_reset(MultibyteIncrementalDecoderObject *self)
+_multibytecodec_MultibyteIncrementalDecoder_reset_impl(MultibyteIncrementalDecoderObject *self)
+/*[clinic end generated code: output=da423b1782c23ed1 input=3b63b3be85b2fb45]*/
{
if (self->codec->decreset != NULL &&
self->codec->decreset(&self->state, self->codec->config) != 0)
@@ -1118,11 +1131,9 @@ mbidecoder_reset(MultibyteIncrementalDecoderObject *self)
}
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 +1244,10 @@ static PyTypeObject MultibyteIncrementalDecoder_Type = {
};
-/**
- * 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 +1354,20 @@ errorexit:
return NULL;
}
+/*[clinic input]
+ _multibytecodec.MultibyteStreamReader.read
+
+ sizeobj: object = None
+ /
+[clinic start generated code]*/
+
static PyObject *
-mbstreamreader_read(MultibyteStreamReaderObject *self, PyObject *args)
+_multibytecodec_MultibyteStreamReader_read_impl(MultibyteStreamReaderObject *self, PyObject *sizeobj)
+/*[clinic end generated code: output=f298ea6e1bd2083c input=015b0d3ff2fca485]*/
{
- PyObject *sizeobj = NULL;
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 +1382,20 @@ mbstreamreader_read(MultibyteStreamReaderObject *self, PyObject *args)
return mbstreamreader_iread(self, "read", size);
}
+/*[clinic input]
+ _multibytecodec.MultibyteStreamReader.readline
+
+ sizeobj: object = None
+ /
+[clinic start generated code]*/
+
static PyObject *
-mbstreamreader_readline(MultibyteStreamReaderObject *self, PyObject *args)
+_multibytecodec_MultibyteStreamReader_readline_impl(MultibyteStreamReaderObject *self, PyObject *sizeobj)
+/*[clinic end generated code: output=e5ac302a6d0999de input=41ccc64f9bb0cec3]*/
{
- PyObject *sizeobj = NULL;
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 +1410,21 @@ mbstreamreader_readline(MultibyteStreamReaderObject *self, PyObject *args)
return mbstreamreader_iread(self, "readline", size);
}
+/*[clinic input]
+ _multibytecodec.MultibyteStreamReader.readlines
+
+ sizehintobj: object = None
+ /
+[clinic start generated code]*/
+
static PyObject *
-mbstreamreader_readlines(MultibyteStreamReaderObject *self, PyObject *args)
+_multibytecodec_MultibyteStreamReader_readlines_impl(MultibyteStreamReaderObject *self, PyObject *sizehintobj)
+/*[clinic end generated code: output=68f024178b77cb0f input=54932f5d4d88e880]*/
{
- PyObject *sizehintobj = NULL, *r, *sr;
+ 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 +1445,13 @@ mbstreamreader_readlines(MultibyteStreamReaderObject *self, PyObject *args)
return sr;
}
+/*[clinic input]
+ _multibytecodec.MultibyteStreamReader.reset
+[clinic start generated code]*/
+
static PyObject *
-mbstreamreader_reset(MultibyteStreamReaderObject *self)
+_multibytecodec_MultibyteStreamReader_reset_impl(MultibyteStreamReaderObject *self)
+/*[clinic end generated code: output=138490370a680abc input=5d4140db84b5e1e2]*/
{
if (self->codec->decreset != NULL &&
self->codec->decreset(&self->state, self->codec->config) != 0)
@@ -1432,14 +1462,10 @@ mbstreamreader_reset(MultibyteStreamReaderObject *self)
}
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 +1588,10 @@ static PyTypeObject MultibyteStreamReader_Type = {
};
-/**
- * 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 +1612,16 @@ mbstreamwriter_iwrite(MultibyteStreamWriterObject *self,
return 0;
}
+/*[clinic input]
+ _multibytecodec.MultibyteStreamWriter.write
+
+ strobj: object
+ /
+[clinic start generated code]*/
+
static PyObject *
-mbstreamwriter_write(MultibyteStreamWriterObject *self, PyObject *strobj)
+_multibytecodec_MultibyteStreamWriter_write(MultibyteStreamWriterObject *self, PyObject *strobj)
+/*[clinic end generated code: output=44e9eb0db0374cb1 input=551dc4c018c10a2b]*/
{
if (mbstreamwriter_iwrite(self, strobj))
return NULL;
@@ -1594,8 +1629,16 @@ mbstreamwriter_write(MultibyteStreamWriterObject *self, PyObject *strobj)
Py_RETURN_NONE;
}
+/*[clinic input]
+ _multibytecodec.MultibyteStreamWriter.writelines
+
+ lines: object
+ /
+[clinic start generated code]*/
+
static PyObject *
-mbstreamwriter_writelines(MultibyteStreamWriterObject *self, PyObject *lines)
+_multibytecodec_MultibyteStreamWriter_writelines(MultibyteStreamWriterObject *self, PyObject *lines)
+/*[clinic end generated code: output=4facbb0638dde172 input=57797fe7008d4e96]*/
{
PyObject *strobj;
int i, r;
@@ -1621,8 +1664,13 @@ mbstreamwriter_writelines(MultibyteStreamWriterObject *self, PyObject *lines)
Py_RETURN_NONE;
}
+/*[clinic input]
+ _multibytecodec.MultibyteStreamWriter.reset
+[clinic start generated code]*/
+
static PyObject *
-mbstreamwriter_reset(MultibyteStreamWriterObject *self)
+_multibytecodec_MultibyteStreamWriter_reset_impl(MultibyteStreamWriterObject *self)
+/*[clinic end generated code: output=8f54a4d9b03db5ff input=b56dbcbaf35cc10c]*/
{
PyObject *pwrt;
@@ -1721,13 +1769,10 @@ mbstreamwriter_dealloc(MultibyteStreamWriterObject *self)
}
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 +1826,16 @@ static PyTypeObject MultibyteStreamWriter_Type = {
};
-/**
- * Exposed factory function
- */
+/*[clinic input]
+_multibytecodec.__create_codec
+
+ arg: object
+ /
+[clinic start generated code]*/
static PyObject *
-__create_codec(PyObject *ignore, PyObject *arg)
+_multibytecodec___create_codec(PyModuleDef *module, PyObject *arg)
+/*[clinic end generated code: output=fbe74f6510640163 input=6840b2a6b183fcfa]*/
{
MultibyteCodecObject *self;
MultibyteCodec *codec;
@@ -1809,7 +1858,7 @@ __create_codec(PyObject *ignore, PyObject *arg)
}
static struct PyMethodDef __methods[] = {
- {"__create_codec", (PyCFunction)__create_codec, METH_O},
+ _MULTIBYTECODEC___CREATE_CODEC_METHODDEF
{NULL, NULL},
};