summaryrefslogtreecommitdiff
path: root/Modules/cjkcodecs
diff options
context:
space:
mode:
Diffstat (limited to 'Modules/cjkcodecs')
-rw-r--r--Modules/cjkcodecs/_codecs_iso2022.c7
-rw-r--r--Modules/cjkcodecs/cjkcodecs.h4
-rw-r--r--Modules/cjkcodecs/clinic/multibytecodec.c.h320
-rw-r--r--Modules/cjkcodecs/multibytecodec.c345
4 files changed, 526 insertions, 150 deletions
diff --git a/Modules/cjkcodecs/_codecs_iso2022.c b/Modules/cjkcodecs/_codecs_iso2022.c
index 5c401aaf8e..1ce4218f30 100644
--- a/Modules/cjkcodecs/_codecs_iso2022.c
+++ b/Modules/cjkcodecs/_codecs_iso2022.c
@@ -292,7 +292,7 @@ iso2022processesc(const void *config, MultibyteCodec_State *state,
const unsigned char **inbuf, Py_ssize_t *inleft)
{
unsigned char charset, designation;
- Py_ssize_t i, esclen;
+ Py_ssize_t i, esclen = 0;
for (i = 1;i < MAX_ESCSEQLEN;i++) {
if (i >= *inleft)
@@ -307,10 +307,9 @@ iso2022processesc(const void *config, MultibyteCodec_State *state,
}
}
- if (i >= MAX_ESCSEQLEN)
- return 1; /* unterminated escape sequence */
-
switch (esclen) {
+ case 0:
+ return 1; /* unterminated escape sequence */
case 3:
if (INBYTE2 == '$') {
charset = INBYTE3 | CHARSET_DBCS;
diff --git a/Modules/cjkcodecs/cjkcodecs.h b/Modules/cjkcodecs/cjkcodecs.h
index d15ccfbb07..23642df9af 100644
--- a/Modules/cjkcodecs/cjkcodecs.h
+++ b/Modules/cjkcodecs/cjkcodecs.h
@@ -362,7 +362,7 @@ importmap(const char *modname, const char *symbol,
if (mod == NULL)
return -1;
- o = PyObject_GetAttrString(mod, (char*)symbol);
+ o = PyObject_GetAttrString(mod, symbol);
if (o == NULL)
goto errorexit;
else if (!PyCapsule_IsValid(o, PyMultibyteCodec_CAPSULE_NAME)) {
@@ -401,7 +401,7 @@ errorexit:
NULL, \
NULL \
}; \
- PyObject* \
+ PyMODINIT_FUNC \
PyInit__codecs_##loc(void) \
{ \
PyObject *m = PyModule_Create(&__module); \
diff --git a/Modules/cjkcodecs/clinic/multibytecodec.c.h b/Modules/cjkcodecs/clinic/multibytecodec.c.h
new file mode 100644
index 0000000000..8a47ff88a6
--- /dev/null
+++ b/Modules/cjkcodecs/clinic/multibytecodec.c.h
@@ -0,0 +1,320 @@
+/*[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=False)\n"
+"--\n"
+"\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"
+"--\n"
+"\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=False)\n"
+"--\n"
+"\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"
+"--\n"
+"\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"
+"--\n"
+"\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"
+"--\n"
+"\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"
+"--\n"
+"\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"
+"--\n"
+"\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"
+"--\n"
+"\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"
+"--\n"
+"\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"
+"--\n"
+"\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"
+"--\n"
+"\n");
+
+#define _MULTIBYTECODEC___CREATE_CODEC_METHODDEF \
+ {"__create_codec", (PyCFunction)_multibytecodec___create_codec, METH_O, _multibytecodec___create_codec__doc__},
+/*[clinic end generated code: output=eebb21e18c3043d1 input=a9049054013a1b77]*/
diff --git a/Modules/cjkcodecs/multibytecodec.c b/Modules/cjkcodecs/multibytecodec.c
index e0d9b678c2..e4547f75c9 100644
--- a/Modules/cjkcodecs/multibytecodec.c
+++ b/Modules/cjkcodecs/multibytecodec.c
@@ -8,6 +8,13 @@
#include "Python.h"
#include "structmember.h"
#include "multibytecodec.h"
+#include "clinic/multibytecodec.c.h"
+
+/*[clinic input]
+module _multibytecodec
+class _multibytecodec.MultibyteCodec "MultibyteCodecObject *" "&MultibyteCodec_Type"
+[clinic start generated code]*/
+/*[clinic end generated code: output=da39a3ee5e6b4b0d input=6ad689546cbb5450]*/
typedef struct {
PyObject *inobj;
@@ -22,27 +29,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 *,
@@ -553,26 +540,37 @@ errorexit:
return NULL;
}
+/*[clinic input]
+_multibytecodec.MultibyteCodec.encode
+
+ input: object
+ errors: str(accept={str, NoneType}) = 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=7b26652045ba56a9 input=05f6ced3c8dd0582]*/
{
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);
@@ -580,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) {
@@ -596,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;
@@ -611,31 +609,41 @@ errorexit:
return NULL;
}
+/*[clinic input]
+_multibytecodec.MultibyteCodec.decode
+
+ input: Py_buffer
+ errors: str(accept={str, NoneType}) = 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=ff419f65bad6cc77 input=a7d45f87f75e5e02]*/
{
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);
}
@@ -668,13 +676,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);
@@ -683,13 +689,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
@@ -873,26 +875,34 @@ 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(c_default="0") = False
+[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=123361b6c505e2c1 input=a345c688fa664f92]*/
+{
+ 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;
@@ -909,11 +919,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 *
@@ -1024,26 +1032,31 @@ 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(c_default="0") = False
+[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=b9b9090e8a9ce2ba input=576631c61906d39d]*/
{
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;
@@ -1094,14 +1107,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);
@@ -1109,8 +1120,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)
@@ -1121,11 +1137,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 *
@@ -1236,9 +1250,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,
@@ -1260,10 +1275,10 @@ mbstreamreader_iread(MultibyteStreamReaderObject *self,
if (sizehint < 0)
cres = PyObject_CallMethod(self->stream,
- (char *)method, NULL);
+ method, NULL);
else
cres = PyObject_CallMethod(self->stream,
- (char *)method, "i", sizehint);
+ method, "i", sizehint);
if (cres == NULL)
goto errorexit;
@@ -1345,16 +1360,21 @@ 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=35621eb75355d5b8 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);
@@ -1369,16 +1389,21 @@ 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=4fbfaae1ed457a11 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);
@@ -1393,16 +1418,22 @@ 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=e7c4310768ed2ad4 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);
@@ -1423,8 +1454,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)
@@ -1435,14 +1471,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},
};
@@ -1565,9 +1597,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,
@@ -1588,8 +1621,17 @@ 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=e13ae841c895251e input=551dc4c018c10a2b]*/
{
if (mbstreamwriter_iwrite(self, strobj))
return NULL;
@@ -1597,8 +1639,17 @@ 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=e5c4285ac8e7d522 input=57797fe7008d4e96]*/
{
PyObject *strobj;
int i, r;
@@ -1624,8 +1675,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;
@@ -1727,13 +1783,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[] = {
@@ -1787,12 +1840,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;
@@ -1815,7 +1872,7 @@ __create_codec(PyObject *ignore, PyObject *arg)
}
static struct PyMethodDef __methods[] = {
- {"__create_codec", (PyCFunction)__create_codec, METH_O},
+ _MULTIBYTECODEC___CREATE_CODEC_METHODDEF
{NULL, NULL},
};