Brett Cannon | f2de1fc | 2014-08-22 11:45:03 -0400 | [diff] [blame] | 1 | /*[clinic input] |
| 2 | preserve |
| 3 | [clinic start generated code]*/ |
| 4 | |
| 5 | PyDoc_STRVAR(_multibytecodec_MultibyteCodec_encode__doc__, |
| 6 | "encode($self, /, input, errors=None)\n" |
| 7 | "--\n" |
| 8 | "\n" |
| 9 | "Return an encoded string version of `input\'.\n" |
| 10 | "\n" |
| 11 | "\'errors\' may be given to set a different error handling scheme. Default is\n" |
| 12 | "\'strict\' meaning that encoding errors raise a UnicodeEncodeError. Other possible\n" |
| 13 | "values are \'ignore\', \'replace\' and \'xmlcharrefreplace\' as well as any other name\n" |
| 14 | "registered with codecs.register_error that can handle UnicodeEncodeErrors."); |
| 15 | |
| 16 | #define _MULTIBYTECODEC_MULTIBYTECODEC_ENCODE_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 17 | {"encode", (PyCFunction)(void(*)(void))_multibytecodec_MultibyteCodec_encode, METH_FASTCALL|METH_KEYWORDS, _multibytecodec_MultibyteCodec_encode__doc__}, |
Brett Cannon | f2de1fc | 2014-08-22 11:45:03 -0400 | [diff] [blame] | 18 | |
| 19 | static PyObject * |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 20 | _multibytecodec_MultibyteCodec_encode_impl(MultibyteCodecObject *self, |
| 21 | PyObject *input, |
| 22 | const char *errors); |
Brett Cannon | f2de1fc | 2014-08-22 11:45:03 -0400 | [diff] [blame] | 23 | |
| 24 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 25 | _multibytecodec_MultibyteCodec_encode(MultibyteCodecObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Brett Cannon | f2de1fc | 2014-08-22 11:45:03 -0400 | [diff] [blame] | 26 | { |
| 27 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 28 | static const char * const _keywords[] = {"input", "errors", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 29 | static _PyArg_Parser _parser = {NULL, _keywords, "encode", 0}; |
| 30 | PyObject *argsbuf[2]; |
| 31 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
Brett Cannon | f2de1fc | 2014-08-22 11:45:03 -0400 | [diff] [blame] | 32 | PyObject *input; |
| 33 | const char *errors = NULL; |
| 34 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 35 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf); |
| 36 | if (!args) { |
Brett Cannon | f2de1fc | 2014-08-22 11:45:03 -0400 | [diff] [blame] | 37 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 38 | } |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 39 | input = args[0]; |
| 40 | if (!noptargs) { |
| 41 | goto skip_optional_pos; |
| 42 | } |
| 43 | if (args[1] == Py_None) { |
| 44 | errors = NULL; |
| 45 | } |
| 46 | else if (PyUnicode_Check(args[1])) { |
| 47 | Py_ssize_t errors_length; |
| 48 | errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); |
| 49 | if (errors == NULL) { |
| 50 | goto exit; |
| 51 | } |
| 52 | if (strlen(errors) != (size_t)errors_length) { |
| 53 | PyErr_SetString(PyExc_ValueError, "embedded null character"); |
| 54 | goto exit; |
| 55 | } |
| 56 | } |
| 57 | else { |
Rémi Lapeyre | 4901fe2 | 2019-08-29 16:49:08 +0200 | [diff] [blame] | 58 | _PyArg_BadArgument("encode", "argument 'errors'", "str or None", args[1]); |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 59 | goto exit; |
| 60 | } |
| 61 | skip_optional_pos: |
Brett Cannon | f2de1fc | 2014-08-22 11:45:03 -0400 | [diff] [blame] | 62 | return_value = _multibytecodec_MultibyteCodec_encode_impl(self, input, errors); |
| 63 | |
| 64 | exit: |
| 65 | return return_value; |
| 66 | } |
| 67 | |
| 68 | PyDoc_STRVAR(_multibytecodec_MultibyteCodec_decode__doc__, |
| 69 | "decode($self, /, input, errors=None)\n" |
| 70 | "--\n" |
| 71 | "\n" |
| 72 | "Decodes \'input\'.\n" |
| 73 | "\n" |
| 74 | "\'errors\' may be given to set a different error handling scheme. Default is\n" |
| 75 | "\'strict\' meaning that encoding errors raise a UnicodeDecodeError. Other possible\n" |
| 76 | "values are \'ignore\' and \'replace\' as well as any other name registered with\n" |
| 77 | "codecs.register_error that is able to handle UnicodeDecodeErrors.\""); |
| 78 | |
| 79 | #define _MULTIBYTECODEC_MULTIBYTECODEC_DECODE_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 80 | {"decode", (PyCFunction)(void(*)(void))_multibytecodec_MultibyteCodec_decode, METH_FASTCALL|METH_KEYWORDS, _multibytecodec_MultibyteCodec_decode__doc__}, |
Brett Cannon | f2de1fc | 2014-08-22 11:45:03 -0400 | [diff] [blame] | 81 | |
| 82 | static PyObject * |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 83 | _multibytecodec_MultibyteCodec_decode_impl(MultibyteCodecObject *self, |
| 84 | Py_buffer *input, |
| 85 | const char *errors); |
Brett Cannon | f2de1fc | 2014-08-22 11:45:03 -0400 | [diff] [blame] | 86 | |
| 87 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 88 | _multibytecodec_MultibyteCodec_decode(MultibyteCodecObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Brett Cannon | f2de1fc | 2014-08-22 11:45:03 -0400 | [diff] [blame] | 89 | { |
| 90 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 91 | static const char * const _keywords[] = {"input", "errors", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 92 | static _PyArg_Parser _parser = {NULL, _keywords, "decode", 0}; |
| 93 | PyObject *argsbuf[2]; |
| 94 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
Brett Cannon | f2de1fc | 2014-08-22 11:45:03 -0400 | [diff] [blame] | 95 | Py_buffer input = {NULL, NULL}; |
| 96 | const char *errors = NULL; |
| 97 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 98 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf); |
| 99 | if (!args) { |
Brett Cannon | f2de1fc | 2014-08-22 11:45:03 -0400 | [diff] [blame] | 100 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 101 | } |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 102 | if (PyObject_GetBuffer(args[0], &input, PyBUF_SIMPLE) != 0) { |
| 103 | goto exit; |
| 104 | } |
| 105 | if (!PyBuffer_IsContiguous(&input, 'C')) { |
Rémi Lapeyre | 4901fe2 | 2019-08-29 16:49:08 +0200 | [diff] [blame] | 106 | _PyArg_BadArgument("decode", "argument 'input'", "contiguous buffer", args[0]); |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 107 | goto exit; |
| 108 | } |
| 109 | if (!noptargs) { |
| 110 | goto skip_optional_pos; |
| 111 | } |
| 112 | if (args[1] == Py_None) { |
| 113 | errors = NULL; |
| 114 | } |
| 115 | else if (PyUnicode_Check(args[1])) { |
| 116 | Py_ssize_t errors_length; |
| 117 | errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length); |
| 118 | if (errors == NULL) { |
| 119 | goto exit; |
| 120 | } |
| 121 | if (strlen(errors) != (size_t)errors_length) { |
| 122 | PyErr_SetString(PyExc_ValueError, "embedded null character"); |
| 123 | goto exit; |
| 124 | } |
| 125 | } |
| 126 | else { |
Rémi Lapeyre | 4901fe2 | 2019-08-29 16:49:08 +0200 | [diff] [blame] | 127 | _PyArg_BadArgument("decode", "argument 'errors'", "str or None", args[1]); |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 128 | goto exit; |
| 129 | } |
| 130 | skip_optional_pos: |
Brett Cannon | f2de1fc | 2014-08-22 11:45:03 -0400 | [diff] [blame] | 131 | return_value = _multibytecodec_MultibyteCodec_decode_impl(self, &input, errors); |
| 132 | |
| 133 | exit: |
| 134 | /* Cleanup for input */ |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 135 | if (input.obj) { |
Brett Cannon | f2de1fc | 2014-08-22 11:45:03 -0400 | [diff] [blame] | 136 | PyBuffer_Release(&input); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 137 | } |
Brett Cannon | f2de1fc | 2014-08-22 11:45:03 -0400 | [diff] [blame] | 138 | |
| 139 | return return_value; |
| 140 | } |
| 141 | |
| 142 | PyDoc_STRVAR(_multibytecodec_MultibyteIncrementalEncoder_encode__doc__, |
Serhiy Storchaka | 8b2e8b6 | 2015-05-30 11:30:39 +0300 | [diff] [blame] | 143 | "encode($self, /, input, final=False)\n" |
Zachary Ware | 8ef887c | 2015-04-13 18:22:35 -0500 | [diff] [blame] | 144 | "--\n" |
| 145 | "\n"); |
Brett Cannon | f2de1fc | 2014-08-22 11:45:03 -0400 | [diff] [blame] | 146 | |
| 147 | #define _MULTIBYTECODEC_MULTIBYTEINCREMENTALENCODER_ENCODE_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 148 | {"encode", (PyCFunction)(void(*)(void))_multibytecodec_MultibyteIncrementalEncoder_encode, METH_FASTCALL|METH_KEYWORDS, _multibytecodec_MultibyteIncrementalEncoder_encode__doc__}, |
Brett Cannon | f2de1fc | 2014-08-22 11:45:03 -0400 | [diff] [blame] | 149 | |
| 150 | static PyObject * |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 151 | _multibytecodec_MultibyteIncrementalEncoder_encode_impl(MultibyteIncrementalEncoderObject *self, |
| 152 | PyObject *input, |
| 153 | int final); |
Brett Cannon | f2de1fc | 2014-08-22 11:45:03 -0400 | [diff] [blame] | 154 | |
| 155 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 156 | _multibytecodec_MultibyteIncrementalEncoder_encode(MultibyteIncrementalEncoderObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Brett Cannon | f2de1fc | 2014-08-22 11:45:03 -0400 | [diff] [blame] | 157 | { |
| 158 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 159 | static const char * const _keywords[] = {"input", "final", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 160 | static _PyArg_Parser _parser = {NULL, _keywords, "encode", 0}; |
| 161 | PyObject *argsbuf[2]; |
| 162 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
Brett Cannon | f2de1fc | 2014-08-22 11:45:03 -0400 | [diff] [blame] | 163 | PyObject *input; |
| 164 | int final = 0; |
| 165 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 166 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf); |
| 167 | if (!args) { |
Brett Cannon | f2de1fc | 2014-08-22 11:45:03 -0400 | [diff] [blame] | 168 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 169 | } |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 170 | input = args[0]; |
| 171 | if (!noptargs) { |
| 172 | goto skip_optional_pos; |
| 173 | } |
| 174 | if (PyFloat_Check(args[1])) { |
| 175 | PyErr_SetString(PyExc_TypeError, |
| 176 | "integer argument expected, got float" ); |
| 177 | goto exit; |
| 178 | } |
| 179 | final = _PyLong_AsInt(args[1]); |
| 180 | if (final == -1 && PyErr_Occurred()) { |
| 181 | goto exit; |
| 182 | } |
| 183 | skip_optional_pos: |
Brett Cannon | f2de1fc | 2014-08-22 11:45:03 -0400 | [diff] [blame] | 184 | return_value = _multibytecodec_MultibyteIncrementalEncoder_encode_impl(self, input, final); |
| 185 | |
| 186 | exit: |
| 187 | return return_value; |
| 188 | } |
| 189 | |
Christopher Thorne | ac22f6a | 2018-11-01 10:48:49 +0000 | [diff] [blame] | 190 | PyDoc_STRVAR(_multibytecodec_MultibyteIncrementalEncoder_getstate__doc__, |
| 191 | "getstate($self, /)\n" |
| 192 | "--\n" |
| 193 | "\n"); |
| 194 | |
| 195 | #define _MULTIBYTECODEC_MULTIBYTEINCREMENTALENCODER_GETSTATE_METHODDEF \ |
| 196 | {"getstate", (PyCFunction)_multibytecodec_MultibyteIncrementalEncoder_getstate, METH_NOARGS, _multibytecodec_MultibyteIncrementalEncoder_getstate__doc__}, |
| 197 | |
| 198 | static PyObject * |
| 199 | _multibytecodec_MultibyteIncrementalEncoder_getstate_impl(MultibyteIncrementalEncoderObject *self); |
| 200 | |
| 201 | static PyObject * |
| 202 | _multibytecodec_MultibyteIncrementalEncoder_getstate(MultibyteIncrementalEncoderObject *self, PyObject *Py_UNUSED(ignored)) |
| 203 | { |
| 204 | return _multibytecodec_MultibyteIncrementalEncoder_getstate_impl(self); |
| 205 | } |
| 206 | |
| 207 | PyDoc_STRVAR(_multibytecodec_MultibyteIncrementalEncoder_setstate__doc__, |
| 208 | "setstate($self, state, /)\n" |
| 209 | "--\n" |
| 210 | "\n"); |
| 211 | |
| 212 | #define _MULTIBYTECODEC_MULTIBYTEINCREMENTALENCODER_SETSTATE_METHODDEF \ |
| 213 | {"setstate", (PyCFunction)_multibytecodec_MultibyteIncrementalEncoder_setstate, METH_O, _multibytecodec_MultibyteIncrementalEncoder_setstate__doc__}, |
| 214 | |
| 215 | static PyObject * |
| 216 | _multibytecodec_MultibyteIncrementalEncoder_setstate_impl(MultibyteIncrementalEncoderObject *self, |
| 217 | PyLongObject *statelong); |
| 218 | |
| 219 | static PyObject * |
| 220 | _multibytecodec_MultibyteIncrementalEncoder_setstate(MultibyteIncrementalEncoderObject *self, PyObject *arg) |
| 221 | { |
| 222 | PyObject *return_value = NULL; |
| 223 | PyLongObject *statelong; |
| 224 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 225 | if (!PyLong_Check(arg)) { |
Rémi Lapeyre | 4901fe2 | 2019-08-29 16:49:08 +0200 | [diff] [blame] | 226 | _PyArg_BadArgument("setstate", "argument", "int", arg); |
Christopher Thorne | ac22f6a | 2018-11-01 10:48:49 +0000 | [diff] [blame] | 227 | goto exit; |
| 228 | } |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 229 | statelong = (PyLongObject *)arg; |
Christopher Thorne | ac22f6a | 2018-11-01 10:48:49 +0000 | [diff] [blame] | 230 | return_value = _multibytecodec_MultibyteIncrementalEncoder_setstate_impl(self, statelong); |
| 231 | |
| 232 | exit: |
| 233 | return return_value; |
| 234 | } |
| 235 | |
Brett Cannon | f2de1fc | 2014-08-22 11:45:03 -0400 | [diff] [blame] | 236 | PyDoc_STRVAR(_multibytecodec_MultibyteIncrementalEncoder_reset__doc__, |
| 237 | "reset($self, /)\n" |
Zachary Ware | 8ef887c | 2015-04-13 18:22:35 -0500 | [diff] [blame] | 238 | "--\n" |
| 239 | "\n"); |
Brett Cannon | f2de1fc | 2014-08-22 11:45:03 -0400 | [diff] [blame] | 240 | |
| 241 | #define _MULTIBYTECODEC_MULTIBYTEINCREMENTALENCODER_RESET_METHODDEF \ |
| 242 | {"reset", (PyCFunction)_multibytecodec_MultibyteIncrementalEncoder_reset, METH_NOARGS, _multibytecodec_MultibyteIncrementalEncoder_reset__doc__}, |
| 243 | |
| 244 | static PyObject * |
| 245 | _multibytecodec_MultibyteIncrementalEncoder_reset_impl(MultibyteIncrementalEncoderObject *self); |
| 246 | |
| 247 | static PyObject * |
| 248 | _multibytecodec_MultibyteIncrementalEncoder_reset(MultibyteIncrementalEncoderObject *self, PyObject *Py_UNUSED(ignored)) |
| 249 | { |
| 250 | return _multibytecodec_MultibyteIncrementalEncoder_reset_impl(self); |
| 251 | } |
| 252 | |
| 253 | PyDoc_STRVAR(_multibytecodec_MultibyteIncrementalDecoder_decode__doc__, |
Serhiy Storchaka | 8b2e8b6 | 2015-05-30 11:30:39 +0300 | [diff] [blame] | 254 | "decode($self, /, input, final=False)\n" |
Zachary Ware | 8ef887c | 2015-04-13 18:22:35 -0500 | [diff] [blame] | 255 | "--\n" |
| 256 | "\n"); |
Brett Cannon | f2de1fc | 2014-08-22 11:45:03 -0400 | [diff] [blame] | 257 | |
| 258 | #define _MULTIBYTECODEC_MULTIBYTEINCREMENTALDECODER_DECODE_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 259 | {"decode", (PyCFunction)(void(*)(void))_multibytecodec_MultibyteIncrementalDecoder_decode, METH_FASTCALL|METH_KEYWORDS, _multibytecodec_MultibyteIncrementalDecoder_decode__doc__}, |
Brett Cannon | f2de1fc | 2014-08-22 11:45:03 -0400 | [diff] [blame] | 260 | |
| 261 | static PyObject * |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 262 | _multibytecodec_MultibyteIncrementalDecoder_decode_impl(MultibyteIncrementalDecoderObject *self, |
| 263 | Py_buffer *input, |
| 264 | int final); |
Brett Cannon | f2de1fc | 2014-08-22 11:45:03 -0400 | [diff] [blame] | 265 | |
| 266 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 267 | _multibytecodec_MultibyteIncrementalDecoder_decode(MultibyteIncrementalDecoderObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Brett Cannon | f2de1fc | 2014-08-22 11:45:03 -0400 | [diff] [blame] | 268 | { |
| 269 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 270 | static const char * const _keywords[] = {"input", "final", NULL}; |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 271 | static _PyArg_Parser _parser = {NULL, _keywords, "decode", 0}; |
| 272 | PyObject *argsbuf[2]; |
| 273 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
Brett Cannon | f2de1fc | 2014-08-22 11:45:03 -0400 | [diff] [blame] | 274 | Py_buffer input = {NULL, NULL}; |
| 275 | int final = 0; |
| 276 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 277 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf); |
| 278 | if (!args) { |
Brett Cannon | f2de1fc | 2014-08-22 11:45:03 -0400 | [diff] [blame] | 279 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 280 | } |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 281 | if (PyObject_GetBuffer(args[0], &input, PyBUF_SIMPLE) != 0) { |
| 282 | goto exit; |
| 283 | } |
| 284 | if (!PyBuffer_IsContiguous(&input, 'C')) { |
Rémi Lapeyre | 4901fe2 | 2019-08-29 16:49:08 +0200 | [diff] [blame] | 285 | _PyArg_BadArgument("decode", "argument 'input'", "contiguous buffer", args[0]); |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 286 | goto exit; |
| 287 | } |
| 288 | if (!noptargs) { |
| 289 | goto skip_optional_pos; |
| 290 | } |
| 291 | if (PyFloat_Check(args[1])) { |
| 292 | PyErr_SetString(PyExc_TypeError, |
| 293 | "integer argument expected, got float" ); |
| 294 | goto exit; |
| 295 | } |
| 296 | final = _PyLong_AsInt(args[1]); |
| 297 | if (final == -1 && PyErr_Occurred()) { |
| 298 | goto exit; |
| 299 | } |
| 300 | skip_optional_pos: |
Brett Cannon | f2de1fc | 2014-08-22 11:45:03 -0400 | [diff] [blame] | 301 | return_value = _multibytecodec_MultibyteIncrementalDecoder_decode_impl(self, &input, final); |
| 302 | |
| 303 | exit: |
| 304 | /* Cleanup for input */ |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 305 | if (input.obj) { |
Brett Cannon | f2de1fc | 2014-08-22 11:45:03 -0400 | [diff] [blame] | 306 | PyBuffer_Release(&input); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 307 | } |
Brett Cannon | f2de1fc | 2014-08-22 11:45:03 -0400 | [diff] [blame] | 308 | |
| 309 | return return_value; |
| 310 | } |
| 311 | |
Christopher Thorne | ac22f6a | 2018-11-01 10:48:49 +0000 | [diff] [blame] | 312 | PyDoc_STRVAR(_multibytecodec_MultibyteIncrementalDecoder_getstate__doc__, |
| 313 | "getstate($self, /)\n" |
| 314 | "--\n" |
| 315 | "\n"); |
| 316 | |
| 317 | #define _MULTIBYTECODEC_MULTIBYTEINCREMENTALDECODER_GETSTATE_METHODDEF \ |
| 318 | {"getstate", (PyCFunction)_multibytecodec_MultibyteIncrementalDecoder_getstate, METH_NOARGS, _multibytecodec_MultibyteIncrementalDecoder_getstate__doc__}, |
| 319 | |
| 320 | static PyObject * |
| 321 | _multibytecodec_MultibyteIncrementalDecoder_getstate_impl(MultibyteIncrementalDecoderObject *self); |
| 322 | |
| 323 | static PyObject * |
| 324 | _multibytecodec_MultibyteIncrementalDecoder_getstate(MultibyteIncrementalDecoderObject *self, PyObject *Py_UNUSED(ignored)) |
| 325 | { |
| 326 | return _multibytecodec_MultibyteIncrementalDecoder_getstate_impl(self); |
| 327 | } |
| 328 | |
| 329 | PyDoc_STRVAR(_multibytecodec_MultibyteIncrementalDecoder_setstate__doc__, |
| 330 | "setstate($self, state, /)\n" |
| 331 | "--\n" |
| 332 | "\n"); |
| 333 | |
| 334 | #define _MULTIBYTECODEC_MULTIBYTEINCREMENTALDECODER_SETSTATE_METHODDEF \ |
| 335 | {"setstate", (PyCFunction)_multibytecodec_MultibyteIncrementalDecoder_setstate, METH_O, _multibytecodec_MultibyteIncrementalDecoder_setstate__doc__}, |
| 336 | |
| 337 | static PyObject * |
| 338 | _multibytecodec_MultibyteIncrementalDecoder_setstate_impl(MultibyteIncrementalDecoderObject *self, |
| 339 | PyObject *state); |
| 340 | |
| 341 | static PyObject * |
| 342 | _multibytecodec_MultibyteIncrementalDecoder_setstate(MultibyteIncrementalDecoderObject *self, PyObject *arg) |
| 343 | { |
| 344 | PyObject *return_value = NULL; |
| 345 | PyObject *state; |
| 346 | |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 347 | if (!PyTuple_Check(arg)) { |
Rémi Lapeyre | 4901fe2 | 2019-08-29 16:49:08 +0200 | [diff] [blame] | 348 | _PyArg_BadArgument("setstate", "argument", "tuple", arg); |
Christopher Thorne | ac22f6a | 2018-11-01 10:48:49 +0000 | [diff] [blame] | 349 | goto exit; |
| 350 | } |
Serhiy Storchaka | 32d96a2 | 2018-12-25 13:23:47 +0200 | [diff] [blame] | 351 | state = arg; |
Christopher Thorne | ac22f6a | 2018-11-01 10:48:49 +0000 | [diff] [blame] | 352 | return_value = _multibytecodec_MultibyteIncrementalDecoder_setstate_impl(self, state); |
| 353 | |
| 354 | exit: |
| 355 | return return_value; |
| 356 | } |
| 357 | |
Brett Cannon | f2de1fc | 2014-08-22 11:45:03 -0400 | [diff] [blame] | 358 | PyDoc_STRVAR(_multibytecodec_MultibyteIncrementalDecoder_reset__doc__, |
| 359 | "reset($self, /)\n" |
Zachary Ware | 8ef887c | 2015-04-13 18:22:35 -0500 | [diff] [blame] | 360 | "--\n" |
| 361 | "\n"); |
Brett Cannon | f2de1fc | 2014-08-22 11:45:03 -0400 | [diff] [blame] | 362 | |
| 363 | #define _MULTIBYTECODEC_MULTIBYTEINCREMENTALDECODER_RESET_METHODDEF \ |
| 364 | {"reset", (PyCFunction)_multibytecodec_MultibyteIncrementalDecoder_reset, METH_NOARGS, _multibytecodec_MultibyteIncrementalDecoder_reset__doc__}, |
| 365 | |
| 366 | static PyObject * |
| 367 | _multibytecodec_MultibyteIncrementalDecoder_reset_impl(MultibyteIncrementalDecoderObject *self); |
| 368 | |
| 369 | static PyObject * |
| 370 | _multibytecodec_MultibyteIncrementalDecoder_reset(MultibyteIncrementalDecoderObject *self, PyObject *Py_UNUSED(ignored)) |
| 371 | { |
| 372 | return _multibytecodec_MultibyteIncrementalDecoder_reset_impl(self); |
| 373 | } |
| 374 | |
| 375 | PyDoc_STRVAR(_multibytecodec_MultibyteStreamReader_read__doc__, |
| 376 | "read($self, sizeobj=None, /)\n" |
Zachary Ware | 8ef887c | 2015-04-13 18:22:35 -0500 | [diff] [blame] | 377 | "--\n" |
| 378 | "\n"); |
Brett Cannon | f2de1fc | 2014-08-22 11:45:03 -0400 | [diff] [blame] | 379 | |
| 380 | #define _MULTIBYTECODEC_MULTIBYTESTREAMREADER_READ_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 381 | {"read", (PyCFunction)(void(*)(void))_multibytecodec_MultibyteStreamReader_read, METH_FASTCALL, _multibytecodec_MultibyteStreamReader_read__doc__}, |
Brett Cannon | f2de1fc | 2014-08-22 11:45:03 -0400 | [diff] [blame] | 382 | |
| 383 | static PyObject * |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 384 | _multibytecodec_MultibyteStreamReader_read_impl(MultibyteStreamReaderObject *self, |
| 385 | PyObject *sizeobj); |
Brett Cannon | f2de1fc | 2014-08-22 11:45:03 -0400 | [diff] [blame] | 386 | |
| 387 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 388 | _multibytecodec_MultibyteStreamReader_read(MultibyteStreamReaderObject *self, PyObject *const *args, Py_ssize_t nargs) |
Brett Cannon | f2de1fc | 2014-08-22 11:45:03 -0400 | [diff] [blame] | 389 | { |
| 390 | PyObject *return_value = NULL; |
| 391 | PyObject *sizeobj = Py_None; |
| 392 | |
Serhiy Storchaka | 2a39d25 | 2019-01-11 18:01:42 +0200 | [diff] [blame] | 393 | if (!_PyArg_CheckPositional("read", nargs, 0, 1)) { |
Victor Stinner | 0c4a828 | 2017-01-17 02:21:47 +0100 | [diff] [blame] | 394 | goto exit; |
| 395 | } |
Serhiy Storchaka | 2a39d25 | 2019-01-11 18:01:42 +0200 | [diff] [blame] | 396 | if (nargs < 1) { |
| 397 | goto skip_optional; |
| 398 | } |
| 399 | sizeobj = args[0]; |
| 400 | skip_optional: |
Brett Cannon | f2de1fc | 2014-08-22 11:45:03 -0400 | [diff] [blame] | 401 | return_value = _multibytecodec_MultibyteStreamReader_read_impl(self, sizeobj); |
| 402 | |
| 403 | exit: |
| 404 | return return_value; |
| 405 | } |
| 406 | |
| 407 | PyDoc_STRVAR(_multibytecodec_MultibyteStreamReader_readline__doc__, |
| 408 | "readline($self, sizeobj=None, /)\n" |
Zachary Ware | 8ef887c | 2015-04-13 18:22:35 -0500 | [diff] [blame] | 409 | "--\n" |
| 410 | "\n"); |
Brett Cannon | f2de1fc | 2014-08-22 11:45:03 -0400 | [diff] [blame] | 411 | |
| 412 | #define _MULTIBYTECODEC_MULTIBYTESTREAMREADER_READLINE_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 413 | {"readline", (PyCFunction)(void(*)(void))_multibytecodec_MultibyteStreamReader_readline, METH_FASTCALL, _multibytecodec_MultibyteStreamReader_readline__doc__}, |
Brett Cannon | f2de1fc | 2014-08-22 11:45:03 -0400 | [diff] [blame] | 414 | |
| 415 | static PyObject * |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 416 | _multibytecodec_MultibyteStreamReader_readline_impl(MultibyteStreamReaderObject *self, |
| 417 | PyObject *sizeobj); |
Brett Cannon | f2de1fc | 2014-08-22 11:45:03 -0400 | [diff] [blame] | 418 | |
| 419 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 420 | _multibytecodec_MultibyteStreamReader_readline(MultibyteStreamReaderObject *self, PyObject *const *args, Py_ssize_t nargs) |
Brett Cannon | f2de1fc | 2014-08-22 11:45:03 -0400 | [diff] [blame] | 421 | { |
| 422 | PyObject *return_value = NULL; |
| 423 | PyObject *sizeobj = Py_None; |
| 424 | |
Serhiy Storchaka | 2a39d25 | 2019-01-11 18:01:42 +0200 | [diff] [blame] | 425 | if (!_PyArg_CheckPositional("readline", nargs, 0, 1)) { |
Victor Stinner | 0c4a828 | 2017-01-17 02:21:47 +0100 | [diff] [blame] | 426 | goto exit; |
| 427 | } |
Serhiy Storchaka | 2a39d25 | 2019-01-11 18:01:42 +0200 | [diff] [blame] | 428 | if (nargs < 1) { |
| 429 | goto skip_optional; |
| 430 | } |
| 431 | sizeobj = args[0]; |
| 432 | skip_optional: |
Brett Cannon | f2de1fc | 2014-08-22 11:45:03 -0400 | [diff] [blame] | 433 | return_value = _multibytecodec_MultibyteStreamReader_readline_impl(self, sizeobj); |
| 434 | |
| 435 | exit: |
| 436 | return return_value; |
| 437 | } |
| 438 | |
| 439 | PyDoc_STRVAR(_multibytecodec_MultibyteStreamReader_readlines__doc__, |
| 440 | "readlines($self, sizehintobj=None, /)\n" |
Zachary Ware | 8ef887c | 2015-04-13 18:22:35 -0500 | [diff] [blame] | 441 | "--\n" |
| 442 | "\n"); |
Brett Cannon | f2de1fc | 2014-08-22 11:45:03 -0400 | [diff] [blame] | 443 | |
| 444 | #define _MULTIBYTECODEC_MULTIBYTESTREAMREADER_READLINES_METHODDEF \ |
Serhiy Storchaka | 4a934d4 | 2018-11-27 11:27:36 +0200 | [diff] [blame] | 445 | {"readlines", (PyCFunction)(void(*)(void))_multibytecodec_MultibyteStreamReader_readlines, METH_FASTCALL, _multibytecodec_MultibyteStreamReader_readlines__doc__}, |
Brett Cannon | f2de1fc | 2014-08-22 11:45:03 -0400 | [diff] [blame] | 446 | |
| 447 | static PyObject * |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 448 | _multibytecodec_MultibyteStreamReader_readlines_impl(MultibyteStreamReaderObject *self, |
| 449 | PyObject *sizehintobj); |
Brett Cannon | f2de1fc | 2014-08-22 11:45:03 -0400 | [diff] [blame] | 450 | |
| 451 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 452 | _multibytecodec_MultibyteStreamReader_readlines(MultibyteStreamReaderObject *self, PyObject *const *args, Py_ssize_t nargs) |
Brett Cannon | f2de1fc | 2014-08-22 11:45:03 -0400 | [diff] [blame] | 453 | { |
| 454 | PyObject *return_value = NULL; |
| 455 | PyObject *sizehintobj = Py_None; |
| 456 | |
Serhiy Storchaka | 2a39d25 | 2019-01-11 18:01:42 +0200 | [diff] [blame] | 457 | if (!_PyArg_CheckPositional("readlines", nargs, 0, 1)) { |
Victor Stinner | 0c4a828 | 2017-01-17 02:21:47 +0100 | [diff] [blame] | 458 | goto exit; |
| 459 | } |
Serhiy Storchaka | 2a39d25 | 2019-01-11 18:01:42 +0200 | [diff] [blame] | 460 | if (nargs < 1) { |
| 461 | goto skip_optional; |
| 462 | } |
| 463 | sizehintobj = args[0]; |
| 464 | skip_optional: |
Brett Cannon | f2de1fc | 2014-08-22 11:45:03 -0400 | [diff] [blame] | 465 | return_value = _multibytecodec_MultibyteStreamReader_readlines_impl(self, sizehintobj); |
| 466 | |
| 467 | exit: |
| 468 | return return_value; |
| 469 | } |
| 470 | |
| 471 | PyDoc_STRVAR(_multibytecodec_MultibyteStreamReader_reset__doc__, |
| 472 | "reset($self, /)\n" |
Zachary Ware | 8ef887c | 2015-04-13 18:22:35 -0500 | [diff] [blame] | 473 | "--\n" |
| 474 | "\n"); |
Brett Cannon | f2de1fc | 2014-08-22 11:45:03 -0400 | [diff] [blame] | 475 | |
| 476 | #define _MULTIBYTECODEC_MULTIBYTESTREAMREADER_RESET_METHODDEF \ |
| 477 | {"reset", (PyCFunction)_multibytecodec_MultibyteStreamReader_reset, METH_NOARGS, _multibytecodec_MultibyteStreamReader_reset__doc__}, |
| 478 | |
| 479 | static PyObject * |
| 480 | _multibytecodec_MultibyteStreamReader_reset_impl(MultibyteStreamReaderObject *self); |
| 481 | |
| 482 | static PyObject * |
| 483 | _multibytecodec_MultibyteStreamReader_reset(MultibyteStreamReaderObject *self, PyObject *Py_UNUSED(ignored)) |
| 484 | { |
| 485 | return _multibytecodec_MultibyteStreamReader_reset_impl(self); |
| 486 | } |
| 487 | |
| 488 | PyDoc_STRVAR(_multibytecodec_MultibyteStreamWriter_write__doc__, |
| 489 | "write($self, strobj, /)\n" |
Zachary Ware | 8ef887c | 2015-04-13 18:22:35 -0500 | [diff] [blame] | 490 | "--\n" |
| 491 | "\n"); |
Brett Cannon | f2de1fc | 2014-08-22 11:45:03 -0400 | [diff] [blame] | 492 | |
| 493 | #define _MULTIBYTECODEC_MULTIBYTESTREAMWRITER_WRITE_METHODDEF \ |
| 494 | {"write", (PyCFunction)_multibytecodec_MultibyteStreamWriter_write, METH_O, _multibytecodec_MultibyteStreamWriter_write__doc__}, |
| 495 | |
| 496 | PyDoc_STRVAR(_multibytecodec_MultibyteStreamWriter_writelines__doc__, |
| 497 | "writelines($self, lines, /)\n" |
Zachary Ware | 8ef887c | 2015-04-13 18:22:35 -0500 | [diff] [blame] | 498 | "--\n" |
| 499 | "\n"); |
Brett Cannon | f2de1fc | 2014-08-22 11:45:03 -0400 | [diff] [blame] | 500 | |
| 501 | #define _MULTIBYTECODEC_MULTIBYTESTREAMWRITER_WRITELINES_METHODDEF \ |
| 502 | {"writelines", (PyCFunction)_multibytecodec_MultibyteStreamWriter_writelines, METH_O, _multibytecodec_MultibyteStreamWriter_writelines__doc__}, |
| 503 | |
| 504 | PyDoc_STRVAR(_multibytecodec_MultibyteStreamWriter_reset__doc__, |
| 505 | "reset($self, /)\n" |
Zachary Ware | 8ef887c | 2015-04-13 18:22:35 -0500 | [diff] [blame] | 506 | "--\n" |
| 507 | "\n"); |
Brett Cannon | f2de1fc | 2014-08-22 11:45:03 -0400 | [diff] [blame] | 508 | |
| 509 | #define _MULTIBYTECODEC_MULTIBYTESTREAMWRITER_RESET_METHODDEF \ |
| 510 | {"reset", (PyCFunction)_multibytecodec_MultibyteStreamWriter_reset, METH_NOARGS, _multibytecodec_MultibyteStreamWriter_reset__doc__}, |
| 511 | |
| 512 | static PyObject * |
| 513 | _multibytecodec_MultibyteStreamWriter_reset_impl(MultibyteStreamWriterObject *self); |
| 514 | |
| 515 | static PyObject * |
| 516 | _multibytecodec_MultibyteStreamWriter_reset(MultibyteStreamWriterObject *self, PyObject *Py_UNUSED(ignored)) |
| 517 | { |
| 518 | return _multibytecodec_MultibyteStreamWriter_reset_impl(self); |
| 519 | } |
| 520 | |
| 521 | PyDoc_STRVAR(_multibytecodec___create_codec__doc__, |
| 522 | "__create_codec($module, arg, /)\n" |
Zachary Ware | 8ef887c | 2015-04-13 18:22:35 -0500 | [diff] [blame] | 523 | "--\n" |
| 524 | "\n"); |
Brett Cannon | f2de1fc | 2014-08-22 11:45:03 -0400 | [diff] [blame] | 525 | |
| 526 | #define _MULTIBYTECODEC___CREATE_CODEC_METHODDEF \ |
| 527 | {"__create_codec", (PyCFunction)_multibytecodec___create_codec, METH_O, _multibytecodec___create_codec__doc__}, |
Rémi Lapeyre | 4901fe2 | 2019-08-29 16:49:08 +0200 | [diff] [blame] | 528 | /*[clinic end generated code: output=5ce6fd4ca1f95620 input=a9049054013a1b77]*/ |