blob: e2ebb6861299e460b320b22c6f1103df5af1760b [file] [log] [blame]
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001/*[clinic input]
2preserve
3[clinic start generated code]*/
4
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03005PyDoc_STRVAR(_codecs_register__doc__,
6"register($module, search_function, /)\n"
7"--\n"
8"\n"
9"Register a codec search function.\n"
10"\n"
11"Search functions are expected to take one argument, the encoding name in\n"
12"all lower case letters, and either return None, or a tuple of functions\n"
13"(encoder, decoder, stream_reader, stream_writer) (or a CodecInfo object).");
14
15#define _CODECS_REGISTER_METHODDEF \
16 {"register", (PyCFunction)_codecs_register, METH_O, _codecs_register__doc__},
17
Hai Shid332e7b2020-09-29 05:41:11 +080018PyDoc_STRVAR(_codecs_unregister__doc__,
19"unregister($module, search_function, /)\n"
20"--\n"
21"\n"
22"Unregister a codec search function and clear the registry\'s cache.\n"
23"\n"
24"If the search function is not registered, do nothing.");
25
26#define _CODECS_UNREGISTER_METHODDEF \
27 {"unregister", (PyCFunction)_codecs_unregister, METH_O, _codecs_unregister__doc__},
28
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +030029PyDoc_STRVAR(_codecs_lookup__doc__,
30"lookup($module, encoding, /)\n"
31"--\n"
32"\n"
33"Looks up a codec tuple in the Python codec registry and returns a CodecInfo object.");
34
35#define _CODECS_LOOKUP_METHODDEF \
36 {"lookup", (PyCFunction)_codecs_lookup, METH_O, _codecs_lookup__doc__},
37
38static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +030039_codecs_lookup_impl(PyObject *module, const char *encoding);
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +030040
41static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +030042_codecs_lookup(PyObject *module, PyObject *arg)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +030043{
44 PyObject *return_value = NULL;
45 const char *encoding;
46
Serhiy Storchaka32d96a22018-12-25 13:23:47 +020047 if (!PyUnicode_Check(arg)) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +020048 _PyArg_BadArgument("lookup", "argument", "str", arg);
Serhiy Storchaka32d96a22018-12-25 13:23:47 +020049 goto exit;
50 }
51 Py_ssize_t encoding_length;
52 encoding = PyUnicode_AsUTF8AndSize(arg, &encoding_length);
53 if (encoding == NULL) {
54 goto exit;
55 }
56 if (strlen(encoding) != (size_t)encoding_length) {
57 PyErr_SetString(PyExc_ValueError, "embedded null character");
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +030058 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030059 }
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +030060 return_value = _codecs_lookup_impl(module, encoding);
61
62exit:
63 return return_value;
64}
65
66PyDoc_STRVAR(_codecs_encode__doc__,
Serhiy Storchakac97a9622015-08-09 12:23:08 +030067"encode($module, /, obj, encoding=\'utf-8\', errors=\'strict\')\n"
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +030068"--\n"
69"\n"
70"Encodes obj using the codec registered for encoding.\n"
71"\n"
Serhiy Storchakac97a9622015-08-09 12:23:08 +030072"The default encoding is \'utf-8\'. errors may be given to set a\n"
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +030073"different error handling scheme. Default is \'strict\' meaning that encoding\n"
74"errors raise a ValueError. Other possible values are \'ignore\', \'replace\'\n"
75"and \'backslashreplace\' as well as any other name registered with\n"
76"codecs.register_error that can handle ValueErrors.");
77
78#define _CODECS_ENCODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +020079 {"encode", (PyCFunction)(void(*)(void))_codecs_encode, METH_FASTCALL|METH_KEYWORDS, _codecs_encode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +030080
81static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +030082_codecs_encode_impl(PyObject *module, PyObject *obj, const char *encoding,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +030083 const char *errors);
84
85static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +020086_codecs_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +030087{
88 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +030089 static const char * const _keywords[] = {"obj", "encoding", "errors", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +020090 static _PyArg_Parser _parser = {NULL, _keywords, "encode", 0};
91 PyObject *argsbuf[3];
92 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +030093 PyObject *obj;
94 const char *encoding = NULL;
95 const char *errors = NULL;
96
Serhiy Storchaka31913912019-03-14 10:32:22 +020097 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 3, 0, argsbuf);
98 if (!args) {
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +030099 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300100 }
Serhiy Storchaka31913912019-03-14 10:32:22 +0200101 obj = args[0];
102 if (!noptargs) {
103 goto skip_optional_pos;
104 }
105 if (args[1]) {
106 if (!PyUnicode_Check(args[1])) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +0200107 _PyArg_BadArgument("encode", "argument 'encoding'", "str", args[1]);
Serhiy Storchaka31913912019-03-14 10:32:22 +0200108 goto exit;
109 }
110 Py_ssize_t encoding_length;
111 encoding = PyUnicode_AsUTF8AndSize(args[1], &encoding_length);
112 if (encoding == NULL) {
113 goto exit;
114 }
115 if (strlen(encoding) != (size_t)encoding_length) {
116 PyErr_SetString(PyExc_ValueError, "embedded null character");
117 goto exit;
118 }
119 if (!--noptargs) {
120 goto skip_optional_pos;
121 }
122 }
123 if (!PyUnicode_Check(args[2])) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +0200124 _PyArg_BadArgument("encode", "argument 'errors'", "str", args[2]);
Serhiy Storchaka31913912019-03-14 10:32:22 +0200125 goto exit;
126 }
127 Py_ssize_t errors_length;
128 errors = PyUnicode_AsUTF8AndSize(args[2], &errors_length);
129 if (errors == NULL) {
130 goto exit;
131 }
132 if (strlen(errors) != (size_t)errors_length) {
133 PyErr_SetString(PyExc_ValueError, "embedded null character");
134 goto exit;
135 }
136skip_optional_pos:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300137 return_value = _codecs_encode_impl(module, obj, encoding, errors);
138
139exit:
140 return return_value;
141}
142
143PyDoc_STRVAR(_codecs_decode__doc__,
Serhiy Storchakac97a9622015-08-09 12:23:08 +0300144"decode($module, /, obj, encoding=\'utf-8\', errors=\'strict\')\n"
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300145"--\n"
146"\n"
147"Decodes obj using the codec registered for encoding.\n"
148"\n"
Serhiy Storchakac97a9622015-08-09 12:23:08 +0300149"Default encoding is \'utf-8\'. errors may be given to set a\n"
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300150"different error handling scheme. Default is \'strict\' meaning that encoding\n"
151"errors raise a ValueError. Other possible values are \'ignore\', \'replace\'\n"
152"and \'backslashreplace\' as well as any other name registered with\n"
153"codecs.register_error that can handle ValueErrors.");
154
155#define _CODECS_DECODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200156 {"decode", (PyCFunction)(void(*)(void))_codecs_decode, METH_FASTCALL|METH_KEYWORDS, _codecs_decode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300157
158static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300159_codecs_decode_impl(PyObject *module, PyObject *obj, const char *encoding,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300160 const char *errors);
161
162static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200163_codecs_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300164{
165 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300166 static const char * const _keywords[] = {"obj", "encoding", "errors", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +0200167 static _PyArg_Parser _parser = {NULL, _keywords, "decode", 0};
168 PyObject *argsbuf[3];
169 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300170 PyObject *obj;
171 const char *encoding = NULL;
172 const char *errors = NULL;
173
Serhiy Storchaka31913912019-03-14 10:32:22 +0200174 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 3, 0, argsbuf);
175 if (!args) {
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300176 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300177 }
Serhiy Storchaka31913912019-03-14 10:32:22 +0200178 obj = args[0];
179 if (!noptargs) {
180 goto skip_optional_pos;
181 }
182 if (args[1]) {
183 if (!PyUnicode_Check(args[1])) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +0200184 _PyArg_BadArgument("decode", "argument 'encoding'", "str", args[1]);
Serhiy Storchaka31913912019-03-14 10:32:22 +0200185 goto exit;
186 }
187 Py_ssize_t encoding_length;
188 encoding = PyUnicode_AsUTF8AndSize(args[1], &encoding_length);
189 if (encoding == NULL) {
190 goto exit;
191 }
192 if (strlen(encoding) != (size_t)encoding_length) {
193 PyErr_SetString(PyExc_ValueError, "embedded null character");
194 goto exit;
195 }
196 if (!--noptargs) {
197 goto skip_optional_pos;
198 }
199 }
200 if (!PyUnicode_Check(args[2])) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +0200201 _PyArg_BadArgument("decode", "argument 'errors'", "str", args[2]);
Serhiy Storchaka31913912019-03-14 10:32:22 +0200202 goto exit;
203 }
204 Py_ssize_t errors_length;
205 errors = PyUnicode_AsUTF8AndSize(args[2], &errors_length);
206 if (errors == NULL) {
207 goto exit;
208 }
209 if (strlen(errors) != (size_t)errors_length) {
210 PyErr_SetString(PyExc_ValueError, "embedded null character");
211 goto exit;
212 }
213skip_optional_pos:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300214 return_value = _codecs_decode_impl(module, obj, encoding, errors);
215
216exit:
217 return return_value;
218}
219
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300220PyDoc_STRVAR(_codecs__forget_codec__doc__,
221"_forget_codec($module, encoding, /)\n"
222"--\n"
223"\n"
224"Purge the named codec from the internal codec lookup cache");
225
226#define _CODECS__FORGET_CODEC_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300227 {"_forget_codec", (PyCFunction)_codecs__forget_codec, METH_O, _codecs__forget_codec__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300228
229static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300230_codecs__forget_codec_impl(PyObject *module, const char *encoding);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300231
232static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300233_codecs__forget_codec(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300234{
235 PyObject *return_value = NULL;
236 const char *encoding;
237
Serhiy Storchaka32d96a22018-12-25 13:23:47 +0200238 if (!PyUnicode_Check(arg)) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +0200239 _PyArg_BadArgument("_forget_codec", "argument", "str", arg);
Serhiy Storchaka32d96a22018-12-25 13:23:47 +0200240 goto exit;
241 }
242 Py_ssize_t encoding_length;
243 encoding = PyUnicode_AsUTF8AndSize(arg, &encoding_length);
244 if (encoding == NULL) {
245 goto exit;
246 }
247 if (strlen(encoding) != (size_t)encoding_length) {
248 PyErr_SetString(PyExc_ValueError, "embedded null character");
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300249 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300250 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300251 return_value = _codecs__forget_codec_impl(module, encoding);
252
253exit:
254 return return_value;
255}
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300256
257PyDoc_STRVAR(_codecs_escape_decode__doc__,
258"escape_decode($module, data, errors=None, /)\n"
259"--\n"
260"\n");
261
262#define _CODECS_ESCAPE_DECODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200263 {"escape_decode", (PyCFunction)(void(*)(void))_codecs_escape_decode, METH_FASTCALL, _codecs_escape_decode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300264
265static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300266_codecs_escape_decode_impl(PyObject *module, Py_buffer *data,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300267 const char *errors);
268
269static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200270_codecs_escape_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300271{
272 PyObject *return_value = NULL;
273 Py_buffer data = {NULL, NULL};
274 const char *errors = NULL;
275
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200276 if (!_PyArg_CheckPositional("escape_decode", nargs, 1, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100277 goto exit;
278 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200279 if (PyUnicode_Check(args[0])) {
280 Py_ssize_t len;
281 const char *ptr = PyUnicode_AsUTF8AndSize(args[0], &len);
282 if (ptr == NULL) {
283 goto exit;
284 }
285 PyBuffer_FillInfo(&data, args[0], (void *)ptr, len, 1, 0);
286 }
287 else { /* any bytes-like object */
288 if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
289 goto exit;
290 }
291 if (!PyBuffer_IsContiguous(&data, 'C')) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +0200292 _PyArg_BadArgument("escape_decode", "argument 1", "contiguous buffer", args[0]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200293 goto exit;
294 }
295 }
296 if (nargs < 2) {
297 goto skip_optional;
298 }
299 if (args[1] == Py_None) {
300 errors = NULL;
301 }
302 else if (PyUnicode_Check(args[1])) {
303 Py_ssize_t errors_length;
304 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
305 if (errors == NULL) {
306 goto exit;
307 }
308 if (strlen(errors) != (size_t)errors_length) {
309 PyErr_SetString(PyExc_ValueError, "embedded null character");
310 goto exit;
311 }
312 }
313 else {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +0200314 _PyArg_BadArgument("escape_decode", "argument 2", "str or None", args[1]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200315 goto exit;
316 }
317skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300318 return_value = _codecs_escape_decode_impl(module, &data, errors);
319
320exit:
321 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300322 if (data.obj) {
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300323 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300324 }
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300325
326 return return_value;
327}
328
329PyDoc_STRVAR(_codecs_escape_encode__doc__,
330"escape_encode($module, data, errors=None, /)\n"
331"--\n"
332"\n");
333
334#define _CODECS_ESCAPE_ENCODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200335 {"escape_encode", (PyCFunction)(void(*)(void))_codecs_escape_encode, METH_FASTCALL, _codecs_escape_encode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300336
337static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300338_codecs_escape_encode_impl(PyObject *module, PyObject *data,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300339 const char *errors);
340
341static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200342_codecs_escape_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300343{
344 PyObject *return_value = NULL;
345 PyObject *data;
346 const char *errors = NULL;
347
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200348 if (!_PyArg_CheckPositional("escape_encode", nargs, 1, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100349 goto exit;
350 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200351 if (!PyBytes_Check(args[0])) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +0200352 _PyArg_BadArgument("escape_encode", "argument 1", "bytes", args[0]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200353 goto exit;
354 }
355 data = args[0];
356 if (nargs < 2) {
357 goto skip_optional;
358 }
359 if (args[1] == Py_None) {
360 errors = NULL;
361 }
362 else if (PyUnicode_Check(args[1])) {
363 Py_ssize_t errors_length;
364 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
365 if (errors == NULL) {
366 goto exit;
367 }
368 if (strlen(errors) != (size_t)errors_length) {
369 PyErr_SetString(PyExc_ValueError, "embedded null character");
370 goto exit;
371 }
372 }
373 else {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +0200374 _PyArg_BadArgument("escape_encode", "argument 2", "str or None", args[1]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200375 goto exit;
376 }
377skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300378 return_value = _codecs_escape_encode_impl(module, data, errors);
379
380exit:
381 return return_value;
382}
383
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300384PyDoc_STRVAR(_codecs_utf_7_decode__doc__,
385"utf_7_decode($module, data, errors=None, final=False, /)\n"
386"--\n"
387"\n");
388
389#define _CODECS_UTF_7_DECODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200390 {"utf_7_decode", (PyCFunction)(void(*)(void))_codecs_utf_7_decode, METH_FASTCALL, _codecs_utf_7_decode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300391
392static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300393_codecs_utf_7_decode_impl(PyObject *module, Py_buffer *data,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300394 const char *errors, int final);
395
396static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200397_codecs_utf_7_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300398{
399 PyObject *return_value = NULL;
400 Py_buffer data = {NULL, NULL};
401 const char *errors = NULL;
402 int final = 0;
403
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200404 if (!_PyArg_CheckPositional("utf_7_decode", nargs, 1, 3)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100405 goto exit;
406 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200407 if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
408 goto exit;
409 }
410 if (!PyBuffer_IsContiguous(&data, 'C')) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +0200411 _PyArg_BadArgument("utf_7_decode", "argument 1", "contiguous buffer", args[0]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200412 goto exit;
413 }
414 if (nargs < 2) {
415 goto skip_optional;
416 }
417 if (args[1] == Py_None) {
418 errors = NULL;
419 }
420 else if (PyUnicode_Check(args[1])) {
421 Py_ssize_t errors_length;
422 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
423 if (errors == NULL) {
424 goto exit;
425 }
426 if (strlen(errors) != (size_t)errors_length) {
427 PyErr_SetString(PyExc_ValueError, "embedded null character");
428 goto exit;
429 }
430 }
431 else {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +0200432 _PyArg_BadArgument("utf_7_decode", "argument 2", "str or None", args[1]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200433 goto exit;
434 }
435 if (nargs < 3) {
436 goto skip_optional;
437 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200438 final = _PyLong_AsInt(args[2]);
439 if (final == -1 && PyErr_Occurred()) {
440 goto exit;
441 }
442skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300443 return_value = _codecs_utf_7_decode_impl(module, &data, errors, final);
444
445exit:
446 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300447 if (data.obj) {
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300448 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300449 }
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300450
451 return return_value;
452}
453
454PyDoc_STRVAR(_codecs_utf_8_decode__doc__,
455"utf_8_decode($module, data, errors=None, final=False, /)\n"
456"--\n"
457"\n");
458
459#define _CODECS_UTF_8_DECODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200460 {"utf_8_decode", (PyCFunction)(void(*)(void))_codecs_utf_8_decode, METH_FASTCALL, _codecs_utf_8_decode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300461
462static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300463_codecs_utf_8_decode_impl(PyObject *module, Py_buffer *data,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300464 const char *errors, int final);
465
466static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200467_codecs_utf_8_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300468{
469 PyObject *return_value = NULL;
470 Py_buffer data = {NULL, NULL};
471 const char *errors = NULL;
472 int final = 0;
473
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200474 if (!_PyArg_CheckPositional("utf_8_decode", nargs, 1, 3)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100475 goto exit;
476 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200477 if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
478 goto exit;
479 }
480 if (!PyBuffer_IsContiguous(&data, 'C')) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +0200481 _PyArg_BadArgument("utf_8_decode", "argument 1", "contiguous buffer", args[0]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200482 goto exit;
483 }
484 if (nargs < 2) {
485 goto skip_optional;
486 }
487 if (args[1] == Py_None) {
488 errors = NULL;
489 }
490 else if (PyUnicode_Check(args[1])) {
491 Py_ssize_t errors_length;
492 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
493 if (errors == NULL) {
494 goto exit;
495 }
496 if (strlen(errors) != (size_t)errors_length) {
497 PyErr_SetString(PyExc_ValueError, "embedded null character");
498 goto exit;
499 }
500 }
501 else {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +0200502 _PyArg_BadArgument("utf_8_decode", "argument 2", "str or None", args[1]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200503 goto exit;
504 }
505 if (nargs < 3) {
506 goto skip_optional;
507 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200508 final = _PyLong_AsInt(args[2]);
509 if (final == -1 && PyErr_Occurred()) {
510 goto exit;
511 }
512skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300513 return_value = _codecs_utf_8_decode_impl(module, &data, errors, final);
514
515exit:
516 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300517 if (data.obj) {
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300518 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300519 }
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300520
521 return return_value;
522}
523
524PyDoc_STRVAR(_codecs_utf_16_decode__doc__,
525"utf_16_decode($module, data, errors=None, final=False, /)\n"
526"--\n"
527"\n");
528
529#define _CODECS_UTF_16_DECODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200530 {"utf_16_decode", (PyCFunction)(void(*)(void))_codecs_utf_16_decode, METH_FASTCALL, _codecs_utf_16_decode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300531
532static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300533_codecs_utf_16_decode_impl(PyObject *module, Py_buffer *data,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300534 const char *errors, int final);
535
536static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200537_codecs_utf_16_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300538{
539 PyObject *return_value = NULL;
540 Py_buffer data = {NULL, NULL};
541 const char *errors = NULL;
542 int final = 0;
543
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200544 if (!_PyArg_CheckPositional("utf_16_decode", nargs, 1, 3)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100545 goto exit;
546 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200547 if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
548 goto exit;
549 }
550 if (!PyBuffer_IsContiguous(&data, 'C')) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +0200551 _PyArg_BadArgument("utf_16_decode", "argument 1", "contiguous buffer", args[0]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200552 goto exit;
553 }
554 if (nargs < 2) {
555 goto skip_optional;
556 }
557 if (args[1] == Py_None) {
558 errors = NULL;
559 }
560 else if (PyUnicode_Check(args[1])) {
561 Py_ssize_t errors_length;
562 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
563 if (errors == NULL) {
564 goto exit;
565 }
566 if (strlen(errors) != (size_t)errors_length) {
567 PyErr_SetString(PyExc_ValueError, "embedded null character");
568 goto exit;
569 }
570 }
571 else {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +0200572 _PyArg_BadArgument("utf_16_decode", "argument 2", "str or None", args[1]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200573 goto exit;
574 }
575 if (nargs < 3) {
576 goto skip_optional;
577 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200578 final = _PyLong_AsInt(args[2]);
579 if (final == -1 && PyErr_Occurred()) {
580 goto exit;
581 }
582skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300583 return_value = _codecs_utf_16_decode_impl(module, &data, errors, final);
584
585exit:
586 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300587 if (data.obj) {
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300588 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300589 }
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300590
591 return return_value;
592}
593
594PyDoc_STRVAR(_codecs_utf_16_le_decode__doc__,
595"utf_16_le_decode($module, data, errors=None, final=False, /)\n"
596"--\n"
597"\n");
598
599#define _CODECS_UTF_16_LE_DECODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200600 {"utf_16_le_decode", (PyCFunction)(void(*)(void))_codecs_utf_16_le_decode, METH_FASTCALL, _codecs_utf_16_le_decode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300601
602static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300603_codecs_utf_16_le_decode_impl(PyObject *module, Py_buffer *data,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300604 const char *errors, int final);
605
606static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200607_codecs_utf_16_le_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300608{
609 PyObject *return_value = NULL;
610 Py_buffer data = {NULL, NULL};
611 const char *errors = NULL;
612 int final = 0;
613
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200614 if (!_PyArg_CheckPositional("utf_16_le_decode", nargs, 1, 3)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100615 goto exit;
616 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200617 if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
618 goto exit;
619 }
620 if (!PyBuffer_IsContiguous(&data, 'C')) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +0200621 _PyArg_BadArgument("utf_16_le_decode", "argument 1", "contiguous buffer", args[0]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200622 goto exit;
623 }
624 if (nargs < 2) {
625 goto skip_optional;
626 }
627 if (args[1] == Py_None) {
628 errors = NULL;
629 }
630 else if (PyUnicode_Check(args[1])) {
631 Py_ssize_t errors_length;
632 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
633 if (errors == NULL) {
634 goto exit;
635 }
636 if (strlen(errors) != (size_t)errors_length) {
637 PyErr_SetString(PyExc_ValueError, "embedded null character");
638 goto exit;
639 }
640 }
641 else {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +0200642 _PyArg_BadArgument("utf_16_le_decode", "argument 2", "str or None", args[1]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200643 goto exit;
644 }
645 if (nargs < 3) {
646 goto skip_optional;
647 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200648 final = _PyLong_AsInt(args[2]);
649 if (final == -1 && PyErr_Occurred()) {
650 goto exit;
651 }
652skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300653 return_value = _codecs_utf_16_le_decode_impl(module, &data, errors, final);
654
655exit:
656 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300657 if (data.obj) {
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300658 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300659 }
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300660
661 return return_value;
662}
663
664PyDoc_STRVAR(_codecs_utf_16_be_decode__doc__,
665"utf_16_be_decode($module, data, errors=None, final=False, /)\n"
666"--\n"
667"\n");
668
669#define _CODECS_UTF_16_BE_DECODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200670 {"utf_16_be_decode", (PyCFunction)(void(*)(void))_codecs_utf_16_be_decode, METH_FASTCALL, _codecs_utf_16_be_decode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300671
672static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300673_codecs_utf_16_be_decode_impl(PyObject *module, Py_buffer *data,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300674 const char *errors, int final);
675
676static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200677_codecs_utf_16_be_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300678{
679 PyObject *return_value = NULL;
680 Py_buffer data = {NULL, NULL};
681 const char *errors = NULL;
682 int final = 0;
683
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200684 if (!_PyArg_CheckPositional("utf_16_be_decode", nargs, 1, 3)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100685 goto exit;
686 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200687 if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
688 goto exit;
689 }
690 if (!PyBuffer_IsContiguous(&data, 'C')) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +0200691 _PyArg_BadArgument("utf_16_be_decode", "argument 1", "contiguous buffer", args[0]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200692 goto exit;
693 }
694 if (nargs < 2) {
695 goto skip_optional;
696 }
697 if (args[1] == Py_None) {
698 errors = NULL;
699 }
700 else if (PyUnicode_Check(args[1])) {
701 Py_ssize_t errors_length;
702 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
703 if (errors == NULL) {
704 goto exit;
705 }
706 if (strlen(errors) != (size_t)errors_length) {
707 PyErr_SetString(PyExc_ValueError, "embedded null character");
708 goto exit;
709 }
710 }
711 else {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +0200712 _PyArg_BadArgument("utf_16_be_decode", "argument 2", "str or None", args[1]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200713 goto exit;
714 }
715 if (nargs < 3) {
716 goto skip_optional;
717 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200718 final = _PyLong_AsInt(args[2]);
719 if (final == -1 && PyErr_Occurred()) {
720 goto exit;
721 }
722skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300723 return_value = _codecs_utf_16_be_decode_impl(module, &data, errors, final);
724
725exit:
726 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300727 if (data.obj) {
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300728 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300729 }
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300730
731 return return_value;
732}
733
734PyDoc_STRVAR(_codecs_utf_16_ex_decode__doc__,
735"utf_16_ex_decode($module, data, errors=None, byteorder=0, final=False,\n"
736" /)\n"
737"--\n"
738"\n");
739
740#define _CODECS_UTF_16_EX_DECODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200741 {"utf_16_ex_decode", (PyCFunction)(void(*)(void))_codecs_utf_16_ex_decode, METH_FASTCALL, _codecs_utf_16_ex_decode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300742
743static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300744_codecs_utf_16_ex_decode_impl(PyObject *module, Py_buffer *data,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300745 const char *errors, int byteorder, int final);
746
747static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200748_codecs_utf_16_ex_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300749{
750 PyObject *return_value = NULL;
751 Py_buffer data = {NULL, NULL};
752 const char *errors = NULL;
753 int byteorder = 0;
754 int final = 0;
755
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200756 if (!_PyArg_CheckPositional("utf_16_ex_decode", nargs, 1, 4)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100757 goto exit;
758 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200759 if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
760 goto exit;
761 }
762 if (!PyBuffer_IsContiguous(&data, 'C')) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +0200763 _PyArg_BadArgument("utf_16_ex_decode", "argument 1", "contiguous buffer", args[0]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200764 goto exit;
765 }
766 if (nargs < 2) {
767 goto skip_optional;
768 }
769 if (args[1] == Py_None) {
770 errors = NULL;
771 }
772 else if (PyUnicode_Check(args[1])) {
773 Py_ssize_t errors_length;
774 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
775 if (errors == NULL) {
776 goto exit;
777 }
778 if (strlen(errors) != (size_t)errors_length) {
779 PyErr_SetString(PyExc_ValueError, "embedded null character");
780 goto exit;
781 }
782 }
783 else {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +0200784 _PyArg_BadArgument("utf_16_ex_decode", "argument 2", "str or None", args[1]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200785 goto exit;
786 }
787 if (nargs < 3) {
788 goto skip_optional;
789 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200790 byteorder = _PyLong_AsInt(args[2]);
791 if (byteorder == -1 && PyErr_Occurred()) {
792 goto exit;
793 }
794 if (nargs < 4) {
795 goto skip_optional;
796 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200797 final = _PyLong_AsInt(args[3]);
798 if (final == -1 && PyErr_Occurred()) {
799 goto exit;
800 }
801skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300802 return_value = _codecs_utf_16_ex_decode_impl(module, &data, errors, byteorder, final);
803
804exit:
805 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300806 if (data.obj) {
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300807 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300808 }
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300809
810 return return_value;
811}
812
813PyDoc_STRVAR(_codecs_utf_32_decode__doc__,
814"utf_32_decode($module, data, errors=None, final=False, /)\n"
815"--\n"
816"\n");
817
818#define _CODECS_UTF_32_DECODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200819 {"utf_32_decode", (PyCFunction)(void(*)(void))_codecs_utf_32_decode, METH_FASTCALL, _codecs_utf_32_decode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300820
821static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300822_codecs_utf_32_decode_impl(PyObject *module, Py_buffer *data,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300823 const char *errors, int final);
824
825static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200826_codecs_utf_32_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300827{
828 PyObject *return_value = NULL;
829 Py_buffer data = {NULL, NULL};
830 const char *errors = NULL;
831 int final = 0;
832
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200833 if (!_PyArg_CheckPositional("utf_32_decode", nargs, 1, 3)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100834 goto exit;
835 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200836 if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
837 goto exit;
838 }
839 if (!PyBuffer_IsContiguous(&data, 'C')) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +0200840 _PyArg_BadArgument("utf_32_decode", "argument 1", "contiguous buffer", args[0]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200841 goto exit;
842 }
843 if (nargs < 2) {
844 goto skip_optional;
845 }
846 if (args[1] == Py_None) {
847 errors = NULL;
848 }
849 else if (PyUnicode_Check(args[1])) {
850 Py_ssize_t errors_length;
851 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
852 if (errors == NULL) {
853 goto exit;
854 }
855 if (strlen(errors) != (size_t)errors_length) {
856 PyErr_SetString(PyExc_ValueError, "embedded null character");
857 goto exit;
858 }
859 }
860 else {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +0200861 _PyArg_BadArgument("utf_32_decode", "argument 2", "str or None", args[1]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200862 goto exit;
863 }
864 if (nargs < 3) {
865 goto skip_optional;
866 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200867 final = _PyLong_AsInt(args[2]);
868 if (final == -1 && PyErr_Occurred()) {
869 goto exit;
870 }
871skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300872 return_value = _codecs_utf_32_decode_impl(module, &data, errors, final);
873
874exit:
875 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300876 if (data.obj) {
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300877 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300878 }
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300879
880 return return_value;
881}
882
883PyDoc_STRVAR(_codecs_utf_32_le_decode__doc__,
884"utf_32_le_decode($module, data, errors=None, final=False, /)\n"
885"--\n"
886"\n");
887
888#define _CODECS_UTF_32_LE_DECODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200889 {"utf_32_le_decode", (PyCFunction)(void(*)(void))_codecs_utf_32_le_decode, METH_FASTCALL, _codecs_utf_32_le_decode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300890
891static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300892_codecs_utf_32_le_decode_impl(PyObject *module, Py_buffer *data,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300893 const char *errors, int final);
894
895static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200896_codecs_utf_32_le_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300897{
898 PyObject *return_value = NULL;
899 Py_buffer data = {NULL, NULL};
900 const char *errors = NULL;
901 int final = 0;
902
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200903 if (!_PyArg_CheckPositional("utf_32_le_decode", nargs, 1, 3)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100904 goto exit;
905 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200906 if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
907 goto exit;
908 }
909 if (!PyBuffer_IsContiguous(&data, 'C')) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +0200910 _PyArg_BadArgument("utf_32_le_decode", "argument 1", "contiguous buffer", args[0]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200911 goto exit;
912 }
913 if (nargs < 2) {
914 goto skip_optional;
915 }
916 if (args[1] == Py_None) {
917 errors = NULL;
918 }
919 else if (PyUnicode_Check(args[1])) {
920 Py_ssize_t errors_length;
921 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
922 if (errors == NULL) {
923 goto exit;
924 }
925 if (strlen(errors) != (size_t)errors_length) {
926 PyErr_SetString(PyExc_ValueError, "embedded null character");
927 goto exit;
928 }
929 }
930 else {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +0200931 _PyArg_BadArgument("utf_32_le_decode", "argument 2", "str or None", args[1]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200932 goto exit;
933 }
934 if (nargs < 3) {
935 goto skip_optional;
936 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200937 final = _PyLong_AsInt(args[2]);
938 if (final == -1 && PyErr_Occurred()) {
939 goto exit;
940 }
941skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300942 return_value = _codecs_utf_32_le_decode_impl(module, &data, errors, final);
943
944exit:
945 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300946 if (data.obj) {
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300947 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300948 }
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300949
950 return return_value;
951}
952
953PyDoc_STRVAR(_codecs_utf_32_be_decode__doc__,
954"utf_32_be_decode($module, data, errors=None, final=False, /)\n"
955"--\n"
956"\n");
957
958#define _CODECS_UTF_32_BE_DECODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200959 {"utf_32_be_decode", (PyCFunction)(void(*)(void))_codecs_utf_32_be_decode, METH_FASTCALL, _codecs_utf_32_be_decode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300960
961static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300962_codecs_utf_32_be_decode_impl(PyObject *module, Py_buffer *data,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300963 const char *errors, int final);
964
965static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200966_codecs_utf_32_be_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300967{
968 PyObject *return_value = NULL;
969 Py_buffer data = {NULL, NULL};
970 const char *errors = NULL;
971 int final = 0;
972
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200973 if (!_PyArg_CheckPositional("utf_32_be_decode", nargs, 1, 3)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100974 goto exit;
975 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200976 if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
977 goto exit;
978 }
979 if (!PyBuffer_IsContiguous(&data, 'C')) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +0200980 _PyArg_BadArgument("utf_32_be_decode", "argument 1", "contiguous buffer", args[0]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200981 goto exit;
982 }
983 if (nargs < 2) {
984 goto skip_optional;
985 }
986 if (args[1] == Py_None) {
987 errors = NULL;
988 }
989 else if (PyUnicode_Check(args[1])) {
990 Py_ssize_t errors_length;
991 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
992 if (errors == NULL) {
993 goto exit;
994 }
995 if (strlen(errors) != (size_t)errors_length) {
996 PyErr_SetString(PyExc_ValueError, "embedded null character");
997 goto exit;
998 }
999 }
1000 else {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02001001 _PyArg_BadArgument("utf_32_be_decode", "argument 2", "str or None", args[1]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001002 goto exit;
1003 }
1004 if (nargs < 3) {
1005 goto skip_optional;
1006 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001007 final = _PyLong_AsInt(args[2]);
1008 if (final == -1 && PyErr_Occurred()) {
1009 goto exit;
1010 }
1011skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001012 return_value = _codecs_utf_32_be_decode_impl(module, &data, errors, final);
1013
1014exit:
1015 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001016 if (data.obj) {
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001017 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001018 }
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001019
1020 return return_value;
1021}
1022
1023PyDoc_STRVAR(_codecs_utf_32_ex_decode__doc__,
1024"utf_32_ex_decode($module, data, errors=None, byteorder=0, final=False,\n"
1025" /)\n"
1026"--\n"
1027"\n");
1028
1029#define _CODECS_UTF_32_EX_DECODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001030 {"utf_32_ex_decode", (PyCFunction)(void(*)(void))_codecs_utf_32_ex_decode, METH_FASTCALL, _codecs_utf_32_ex_decode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001031
1032static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001033_codecs_utf_32_ex_decode_impl(PyObject *module, Py_buffer *data,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001034 const char *errors, int byteorder, int final);
1035
1036static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001037_codecs_utf_32_ex_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001038{
1039 PyObject *return_value = NULL;
1040 Py_buffer data = {NULL, NULL};
1041 const char *errors = NULL;
1042 int byteorder = 0;
1043 int final = 0;
1044
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001045 if (!_PyArg_CheckPositional("utf_32_ex_decode", nargs, 1, 4)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01001046 goto exit;
1047 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001048 if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
1049 goto exit;
1050 }
1051 if (!PyBuffer_IsContiguous(&data, 'C')) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02001052 _PyArg_BadArgument("utf_32_ex_decode", "argument 1", "contiguous buffer", args[0]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001053 goto exit;
1054 }
1055 if (nargs < 2) {
1056 goto skip_optional;
1057 }
1058 if (args[1] == Py_None) {
1059 errors = NULL;
1060 }
1061 else if (PyUnicode_Check(args[1])) {
1062 Py_ssize_t errors_length;
1063 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
1064 if (errors == NULL) {
1065 goto exit;
1066 }
1067 if (strlen(errors) != (size_t)errors_length) {
1068 PyErr_SetString(PyExc_ValueError, "embedded null character");
1069 goto exit;
1070 }
1071 }
1072 else {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02001073 _PyArg_BadArgument("utf_32_ex_decode", "argument 2", "str or None", args[1]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001074 goto exit;
1075 }
1076 if (nargs < 3) {
1077 goto skip_optional;
1078 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001079 byteorder = _PyLong_AsInt(args[2]);
1080 if (byteorder == -1 && PyErr_Occurred()) {
1081 goto exit;
1082 }
1083 if (nargs < 4) {
1084 goto skip_optional;
1085 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001086 final = _PyLong_AsInt(args[3]);
1087 if (final == -1 && PyErr_Occurred()) {
1088 goto exit;
1089 }
1090skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001091 return_value = _codecs_utf_32_ex_decode_impl(module, &data, errors, byteorder, final);
1092
1093exit:
1094 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001095 if (data.obj) {
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001096 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001097 }
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001098
1099 return return_value;
1100}
1101
1102PyDoc_STRVAR(_codecs_unicode_escape_decode__doc__,
1103"unicode_escape_decode($module, data, errors=None, /)\n"
1104"--\n"
1105"\n");
1106
1107#define _CODECS_UNICODE_ESCAPE_DECODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001108 {"unicode_escape_decode", (PyCFunction)(void(*)(void))_codecs_unicode_escape_decode, METH_FASTCALL, _codecs_unicode_escape_decode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001109
1110static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001111_codecs_unicode_escape_decode_impl(PyObject *module, Py_buffer *data,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001112 const char *errors);
1113
1114static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001115_codecs_unicode_escape_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001116{
1117 PyObject *return_value = NULL;
1118 Py_buffer data = {NULL, NULL};
1119 const char *errors = NULL;
1120
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001121 if (!_PyArg_CheckPositional("unicode_escape_decode", nargs, 1, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01001122 goto exit;
1123 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001124 if (PyUnicode_Check(args[0])) {
1125 Py_ssize_t len;
1126 const char *ptr = PyUnicode_AsUTF8AndSize(args[0], &len);
1127 if (ptr == NULL) {
1128 goto exit;
1129 }
1130 PyBuffer_FillInfo(&data, args[0], (void *)ptr, len, 1, 0);
1131 }
1132 else { /* any bytes-like object */
1133 if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
1134 goto exit;
1135 }
1136 if (!PyBuffer_IsContiguous(&data, 'C')) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02001137 _PyArg_BadArgument("unicode_escape_decode", "argument 1", "contiguous buffer", args[0]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001138 goto exit;
1139 }
1140 }
1141 if (nargs < 2) {
1142 goto skip_optional;
1143 }
1144 if (args[1] == Py_None) {
1145 errors = NULL;
1146 }
1147 else if (PyUnicode_Check(args[1])) {
1148 Py_ssize_t errors_length;
1149 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
1150 if (errors == NULL) {
1151 goto exit;
1152 }
1153 if (strlen(errors) != (size_t)errors_length) {
1154 PyErr_SetString(PyExc_ValueError, "embedded null character");
1155 goto exit;
1156 }
1157 }
1158 else {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02001159 _PyArg_BadArgument("unicode_escape_decode", "argument 2", "str or None", args[1]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001160 goto exit;
1161 }
1162skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001163 return_value = _codecs_unicode_escape_decode_impl(module, &data, errors);
1164
1165exit:
1166 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001167 if (data.obj) {
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001168 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001169 }
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001170
1171 return return_value;
1172}
1173
1174PyDoc_STRVAR(_codecs_raw_unicode_escape_decode__doc__,
1175"raw_unicode_escape_decode($module, data, errors=None, /)\n"
1176"--\n"
1177"\n");
1178
1179#define _CODECS_RAW_UNICODE_ESCAPE_DECODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001180 {"raw_unicode_escape_decode", (PyCFunction)(void(*)(void))_codecs_raw_unicode_escape_decode, METH_FASTCALL, _codecs_raw_unicode_escape_decode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001181
1182static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001183_codecs_raw_unicode_escape_decode_impl(PyObject *module, Py_buffer *data,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001184 const char *errors);
1185
1186static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001187_codecs_raw_unicode_escape_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001188{
1189 PyObject *return_value = NULL;
1190 Py_buffer data = {NULL, NULL};
1191 const char *errors = NULL;
1192
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001193 if (!_PyArg_CheckPositional("raw_unicode_escape_decode", nargs, 1, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01001194 goto exit;
1195 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001196 if (PyUnicode_Check(args[0])) {
1197 Py_ssize_t len;
1198 const char *ptr = PyUnicode_AsUTF8AndSize(args[0], &len);
1199 if (ptr == NULL) {
1200 goto exit;
1201 }
1202 PyBuffer_FillInfo(&data, args[0], (void *)ptr, len, 1, 0);
1203 }
1204 else { /* any bytes-like object */
1205 if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
1206 goto exit;
1207 }
1208 if (!PyBuffer_IsContiguous(&data, 'C')) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02001209 _PyArg_BadArgument("raw_unicode_escape_decode", "argument 1", "contiguous buffer", args[0]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001210 goto exit;
1211 }
1212 }
1213 if (nargs < 2) {
1214 goto skip_optional;
1215 }
1216 if (args[1] == Py_None) {
1217 errors = NULL;
1218 }
1219 else if (PyUnicode_Check(args[1])) {
1220 Py_ssize_t errors_length;
1221 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
1222 if (errors == NULL) {
1223 goto exit;
1224 }
1225 if (strlen(errors) != (size_t)errors_length) {
1226 PyErr_SetString(PyExc_ValueError, "embedded null character");
1227 goto exit;
1228 }
1229 }
1230 else {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02001231 _PyArg_BadArgument("raw_unicode_escape_decode", "argument 2", "str or None", args[1]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001232 goto exit;
1233 }
1234skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001235 return_value = _codecs_raw_unicode_escape_decode_impl(module, &data, errors);
1236
1237exit:
1238 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001239 if (data.obj) {
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001240 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001241 }
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001242
1243 return return_value;
1244}
1245
1246PyDoc_STRVAR(_codecs_latin_1_decode__doc__,
1247"latin_1_decode($module, data, errors=None, /)\n"
1248"--\n"
1249"\n");
1250
1251#define _CODECS_LATIN_1_DECODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001252 {"latin_1_decode", (PyCFunction)(void(*)(void))_codecs_latin_1_decode, METH_FASTCALL, _codecs_latin_1_decode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001253
1254static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001255_codecs_latin_1_decode_impl(PyObject *module, Py_buffer *data,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001256 const char *errors);
1257
1258static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001259_codecs_latin_1_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001260{
1261 PyObject *return_value = NULL;
1262 Py_buffer data = {NULL, NULL};
1263 const char *errors = NULL;
1264
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001265 if (!_PyArg_CheckPositional("latin_1_decode", nargs, 1, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01001266 goto exit;
1267 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001268 if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
1269 goto exit;
1270 }
1271 if (!PyBuffer_IsContiguous(&data, 'C')) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02001272 _PyArg_BadArgument("latin_1_decode", "argument 1", "contiguous buffer", args[0]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001273 goto exit;
1274 }
1275 if (nargs < 2) {
1276 goto skip_optional;
1277 }
1278 if (args[1] == Py_None) {
1279 errors = NULL;
1280 }
1281 else if (PyUnicode_Check(args[1])) {
1282 Py_ssize_t errors_length;
1283 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
1284 if (errors == NULL) {
1285 goto exit;
1286 }
1287 if (strlen(errors) != (size_t)errors_length) {
1288 PyErr_SetString(PyExc_ValueError, "embedded null character");
1289 goto exit;
1290 }
1291 }
1292 else {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02001293 _PyArg_BadArgument("latin_1_decode", "argument 2", "str or None", args[1]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001294 goto exit;
1295 }
1296skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001297 return_value = _codecs_latin_1_decode_impl(module, &data, errors);
1298
1299exit:
1300 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001301 if (data.obj) {
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001302 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001303 }
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001304
1305 return return_value;
1306}
1307
1308PyDoc_STRVAR(_codecs_ascii_decode__doc__,
1309"ascii_decode($module, data, errors=None, /)\n"
1310"--\n"
1311"\n");
1312
1313#define _CODECS_ASCII_DECODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001314 {"ascii_decode", (PyCFunction)(void(*)(void))_codecs_ascii_decode, METH_FASTCALL, _codecs_ascii_decode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001315
1316static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001317_codecs_ascii_decode_impl(PyObject *module, Py_buffer *data,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001318 const char *errors);
1319
1320static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001321_codecs_ascii_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001322{
1323 PyObject *return_value = NULL;
1324 Py_buffer data = {NULL, NULL};
1325 const char *errors = NULL;
1326
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001327 if (!_PyArg_CheckPositional("ascii_decode", nargs, 1, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01001328 goto exit;
1329 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001330 if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
1331 goto exit;
1332 }
1333 if (!PyBuffer_IsContiguous(&data, 'C')) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02001334 _PyArg_BadArgument("ascii_decode", "argument 1", "contiguous buffer", args[0]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001335 goto exit;
1336 }
1337 if (nargs < 2) {
1338 goto skip_optional;
1339 }
1340 if (args[1] == Py_None) {
1341 errors = NULL;
1342 }
1343 else if (PyUnicode_Check(args[1])) {
1344 Py_ssize_t errors_length;
1345 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
1346 if (errors == NULL) {
1347 goto exit;
1348 }
1349 if (strlen(errors) != (size_t)errors_length) {
1350 PyErr_SetString(PyExc_ValueError, "embedded null character");
1351 goto exit;
1352 }
1353 }
1354 else {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02001355 _PyArg_BadArgument("ascii_decode", "argument 2", "str or None", args[1]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001356 goto exit;
1357 }
1358skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001359 return_value = _codecs_ascii_decode_impl(module, &data, errors);
1360
1361exit:
1362 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001363 if (data.obj) {
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001364 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001365 }
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001366
1367 return return_value;
1368}
1369
1370PyDoc_STRVAR(_codecs_charmap_decode__doc__,
1371"charmap_decode($module, data, errors=None, mapping=None, /)\n"
1372"--\n"
1373"\n");
1374
1375#define _CODECS_CHARMAP_DECODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001376 {"charmap_decode", (PyCFunction)(void(*)(void))_codecs_charmap_decode, METH_FASTCALL, _codecs_charmap_decode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001377
1378static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001379_codecs_charmap_decode_impl(PyObject *module, Py_buffer *data,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001380 const char *errors, PyObject *mapping);
1381
1382static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001383_codecs_charmap_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001384{
1385 PyObject *return_value = NULL;
1386 Py_buffer data = {NULL, NULL};
1387 const char *errors = NULL;
Serhiy Storchaka279f4462019-09-14 12:24:05 +03001388 PyObject *mapping = Py_None;
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001389
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001390 if (!_PyArg_CheckPositional("charmap_decode", nargs, 1, 3)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01001391 goto exit;
1392 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001393 if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
1394 goto exit;
1395 }
1396 if (!PyBuffer_IsContiguous(&data, 'C')) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02001397 _PyArg_BadArgument("charmap_decode", "argument 1", "contiguous buffer", args[0]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001398 goto exit;
1399 }
1400 if (nargs < 2) {
1401 goto skip_optional;
1402 }
1403 if (args[1] == Py_None) {
1404 errors = NULL;
1405 }
1406 else if (PyUnicode_Check(args[1])) {
1407 Py_ssize_t errors_length;
1408 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
1409 if (errors == NULL) {
1410 goto exit;
1411 }
1412 if (strlen(errors) != (size_t)errors_length) {
1413 PyErr_SetString(PyExc_ValueError, "embedded null character");
1414 goto exit;
1415 }
1416 }
1417 else {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02001418 _PyArg_BadArgument("charmap_decode", "argument 2", "str or None", args[1]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001419 goto exit;
1420 }
1421 if (nargs < 3) {
1422 goto skip_optional;
1423 }
1424 mapping = args[2];
1425skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001426 return_value = _codecs_charmap_decode_impl(module, &data, errors, mapping);
1427
1428exit:
1429 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001430 if (data.obj) {
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001431 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001432 }
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001433
1434 return return_value;
1435}
1436
Steve Dowercc16be82016-09-08 10:35:16 -07001437#if defined(MS_WINDOWS)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001438
1439PyDoc_STRVAR(_codecs_mbcs_decode__doc__,
1440"mbcs_decode($module, data, errors=None, final=False, /)\n"
1441"--\n"
1442"\n");
1443
1444#define _CODECS_MBCS_DECODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001445 {"mbcs_decode", (PyCFunction)(void(*)(void))_codecs_mbcs_decode, METH_FASTCALL, _codecs_mbcs_decode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001446
1447static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001448_codecs_mbcs_decode_impl(PyObject *module, Py_buffer *data,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001449 const char *errors, int final);
1450
1451static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001452_codecs_mbcs_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001453{
1454 PyObject *return_value = NULL;
1455 Py_buffer data = {NULL, NULL};
1456 const char *errors = NULL;
1457 int final = 0;
1458
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001459 if (!_PyArg_CheckPositional("mbcs_decode", nargs, 1, 3)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01001460 goto exit;
1461 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001462 if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
1463 goto exit;
1464 }
1465 if (!PyBuffer_IsContiguous(&data, 'C')) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02001466 _PyArg_BadArgument("mbcs_decode", "argument 1", "contiguous buffer", args[0]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001467 goto exit;
1468 }
1469 if (nargs < 2) {
1470 goto skip_optional;
1471 }
1472 if (args[1] == Py_None) {
1473 errors = NULL;
1474 }
1475 else if (PyUnicode_Check(args[1])) {
1476 Py_ssize_t errors_length;
1477 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
1478 if (errors == NULL) {
1479 goto exit;
1480 }
1481 if (strlen(errors) != (size_t)errors_length) {
1482 PyErr_SetString(PyExc_ValueError, "embedded null character");
1483 goto exit;
1484 }
1485 }
1486 else {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02001487 _PyArg_BadArgument("mbcs_decode", "argument 2", "str or None", args[1]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001488 goto exit;
1489 }
1490 if (nargs < 3) {
1491 goto skip_optional;
1492 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001493 final = _PyLong_AsInt(args[2]);
1494 if (final == -1 && PyErr_Occurred()) {
1495 goto exit;
1496 }
1497skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001498 return_value = _codecs_mbcs_decode_impl(module, &data, errors, final);
1499
1500exit:
1501 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001502 if (data.obj) {
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001503 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001504 }
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001505
1506 return return_value;
1507}
1508
Steve Dowercc16be82016-09-08 10:35:16 -07001509#endif /* defined(MS_WINDOWS) */
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001510
Steve Dowercc16be82016-09-08 10:35:16 -07001511#if defined(MS_WINDOWS)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001512
Steve Dowerf5aba582016-09-06 19:42:27 -07001513PyDoc_STRVAR(_codecs_oem_decode__doc__,
1514"oem_decode($module, data, errors=None, final=False, /)\n"
1515"--\n"
1516"\n");
1517
1518#define _CODECS_OEM_DECODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001519 {"oem_decode", (PyCFunction)(void(*)(void))_codecs_oem_decode, METH_FASTCALL, _codecs_oem_decode__doc__},
Steve Dowerf5aba582016-09-06 19:42:27 -07001520
1521static PyObject *
1522_codecs_oem_decode_impl(PyObject *module, Py_buffer *data,
1523 const char *errors, int final);
1524
1525static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001526_codecs_oem_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Steve Dowerf5aba582016-09-06 19:42:27 -07001527{
1528 PyObject *return_value = NULL;
1529 Py_buffer data = {NULL, NULL};
1530 const char *errors = NULL;
1531 int final = 0;
1532
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001533 if (!_PyArg_CheckPositional("oem_decode", nargs, 1, 3)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01001534 goto exit;
1535 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001536 if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
1537 goto exit;
1538 }
1539 if (!PyBuffer_IsContiguous(&data, 'C')) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02001540 _PyArg_BadArgument("oem_decode", "argument 1", "contiguous buffer", args[0]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001541 goto exit;
1542 }
1543 if (nargs < 2) {
1544 goto skip_optional;
1545 }
1546 if (args[1] == Py_None) {
1547 errors = NULL;
1548 }
1549 else if (PyUnicode_Check(args[1])) {
1550 Py_ssize_t errors_length;
1551 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
1552 if (errors == NULL) {
1553 goto exit;
1554 }
1555 if (strlen(errors) != (size_t)errors_length) {
1556 PyErr_SetString(PyExc_ValueError, "embedded null character");
1557 goto exit;
1558 }
1559 }
1560 else {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02001561 _PyArg_BadArgument("oem_decode", "argument 2", "str or None", args[1]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001562 goto exit;
1563 }
1564 if (nargs < 3) {
1565 goto skip_optional;
1566 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001567 final = _PyLong_AsInt(args[2]);
1568 if (final == -1 && PyErr_Occurred()) {
1569 goto exit;
1570 }
1571skip_optional:
Steve Dowerf5aba582016-09-06 19:42:27 -07001572 return_value = _codecs_oem_decode_impl(module, &data, errors, final);
1573
1574exit:
1575 /* Cleanup for data */
1576 if (data.obj) {
1577 PyBuffer_Release(&data);
1578 }
1579
1580 return return_value;
1581}
1582
Steve Dowercc16be82016-09-08 10:35:16 -07001583#endif /* defined(MS_WINDOWS) */
Steve Dowerf5aba582016-09-06 19:42:27 -07001584
Steve Dowercc16be82016-09-08 10:35:16 -07001585#if defined(MS_WINDOWS)
Steve Dowerf5aba582016-09-06 19:42:27 -07001586
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001587PyDoc_STRVAR(_codecs_code_page_decode__doc__,
1588"code_page_decode($module, codepage, data, errors=None, final=False, /)\n"
1589"--\n"
1590"\n");
1591
1592#define _CODECS_CODE_PAGE_DECODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001593 {"code_page_decode", (PyCFunction)(void(*)(void))_codecs_code_page_decode, METH_FASTCALL, _codecs_code_page_decode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001594
1595static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001596_codecs_code_page_decode_impl(PyObject *module, int codepage,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001597 Py_buffer *data, const char *errors, int final);
1598
1599static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001600_codecs_code_page_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001601{
1602 PyObject *return_value = NULL;
1603 int codepage;
1604 Py_buffer data = {NULL, NULL};
1605 const char *errors = NULL;
1606 int final = 0;
1607
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001608 if (!_PyArg_CheckPositional("code_page_decode", nargs, 2, 4)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01001609 goto exit;
1610 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001611 codepage = _PyLong_AsInt(args[0]);
1612 if (codepage == -1 && PyErr_Occurred()) {
1613 goto exit;
1614 }
1615 if (PyObject_GetBuffer(args[1], &data, PyBUF_SIMPLE) != 0) {
1616 goto exit;
1617 }
1618 if (!PyBuffer_IsContiguous(&data, 'C')) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02001619 _PyArg_BadArgument("code_page_decode", "argument 2", "contiguous buffer", args[1]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001620 goto exit;
1621 }
1622 if (nargs < 3) {
1623 goto skip_optional;
1624 }
1625 if (args[2] == Py_None) {
1626 errors = NULL;
1627 }
1628 else if (PyUnicode_Check(args[2])) {
1629 Py_ssize_t errors_length;
1630 errors = PyUnicode_AsUTF8AndSize(args[2], &errors_length);
1631 if (errors == NULL) {
1632 goto exit;
1633 }
1634 if (strlen(errors) != (size_t)errors_length) {
1635 PyErr_SetString(PyExc_ValueError, "embedded null character");
1636 goto exit;
1637 }
1638 }
1639 else {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02001640 _PyArg_BadArgument("code_page_decode", "argument 3", "str or None", args[2]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001641 goto exit;
1642 }
1643 if (nargs < 4) {
1644 goto skip_optional;
1645 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001646 final = _PyLong_AsInt(args[3]);
1647 if (final == -1 && PyErr_Occurred()) {
1648 goto exit;
1649 }
1650skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001651 return_value = _codecs_code_page_decode_impl(module, codepage, &data, errors, final);
1652
1653exit:
1654 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001655 if (data.obj) {
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001656 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001657 }
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001658
1659 return return_value;
1660}
1661
Steve Dowercc16be82016-09-08 10:35:16 -07001662#endif /* defined(MS_WINDOWS) */
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001663
1664PyDoc_STRVAR(_codecs_readbuffer_encode__doc__,
1665"readbuffer_encode($module, data, errors=None, /)\n"
1666"--\n"
1667"\n");
1668
1669#define _CODECS_READBUFFER_ENCODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001670 {"readbuffer_encode", (PyCFunction)(void(*)(void))_codecs_readbuffer_encode, METH_FASTCALL, _codecs_readbuffer_encode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001671
1672static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001673_codecs_readbuffer_encode_impl(PyObject *module, Py_buffer *data,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001674 const char *errors);
1675
1676static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001677_codecs_readbuffer_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001678{
1679 PyObject *return_value = NULL;
1680 Py_buffer data = {NULL, NULL};
1681 const char *errors = NULL;
1682
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001683 if (!_PyArg_CheckPositional("readbuffer_encode", nargs, 1, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01001684 goto exit;
1685 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001686 if (PyUnicode_Check(args[0])) {
1687 Py_ssize_t len;
1688 const char *ptr = PyUnicode_AsUTF8AndSize(args[0], &len);
1689 if (ptr == NULL) {
1690 goto exit;
1691 }
1692 PyBuffer_FillInfo(&data, args[0], (void *)ptr, len, 1, 0);
1693 }
1694 else { /* any bytes-like object */
1695 if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
1696 goto exit;
1697 }
1698 if (!PyBuffer_IsContiguous(&data, 'C')) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02001699 _PyArg_BadArgument("readbuffer_encode", "argument 1", "contiguous buffer", args[0]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001700 goto exit;
1701 }
1702 }
1703 if (nargs < 2) {
1704 goto skip_optional;
1705 }
1706 if (args[1] == Py_None) {
1707 errors = NULL;
1708 }
1709 else if (PyUnicode_Check(args[1])) {
1710 Py_ssize_t errors_length;
1711 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
1712 if (errors == NULL) {
1713 goto exit;
1714 }
1715 if (strlen(errors) != (size_t)errors_length) {
1716 PyErr_SetString(PyExc_ValueError, "embedded null character");
1717 goto exit;
1718 }
1719 }
1720 else {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02001721 _PyArg_BadArgument("readbuffer_encode", "argument 2", "str or None", args[1]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001722 goto exit;
1723 }
1724skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001725 return_value = _codecs_readbuffer_encode_impl(module, &data, errors);
1726
1727exit:
1728 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001729 if (data.obj) {
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001730 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001731 }
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001732
1733 return return_value;
1734}
1735
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001736PyDoc_STRVAR(_codecs_utf_7_encode__doc__,
1737"utf_7_encode($module, str, errors=None, /)\n"
1738"--\n"
1739"\n");
1740
1741#define _CODECS_UTF_7_ENCODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001742 {"utf_7_encode", (PyCFunction)(void(*)(void))_codecs_utf_7_encode, METH_FASTCALL, _codecs_utf_7_encode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001743
1744static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001745_codecs_utf_7_encode_impl(PyObject *module, PyObject *str,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001746 const char *errors);
1747
1748static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001749_codecs_utf_7_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001750{
1751 PyObject *return_value = NULL;
1752 PyObject *str;
1753 const char *errors = NULL;
1754
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001755 if (!_PyArg_CheckPositional("utf_7_encode", nargs, 1, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01001756 goto exit;
1757 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001758 if (!PyUnicode_Check(args[0])) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02001759 _PyArg_BadArgument("utf_7_encode", "argument 1", "str", args[0]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001760 goto exit;
1761 }
1762 if (PyUnicode_READY(args[0]) == -1) {
1763 goto exit;
1764 }
1765 str = args[0];
1766 if (nargs < 2) {
1767 goto skip_optional;
1768 }
1769 if (args[1] == Py_None) {
1770 errors = NULL;
1771 }
1772 else if (PyUnicode_Check(args[1])) {
1773 Py_ssize_t errors_length;
1774 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
1775 if (errors == NULL) {
1776 goto exit;
1777 }
1778 if (strlen(errors) != (size_t)errors_length) {
1779 PyErr_SetString(PyExc_ValueError, "embedded null character");
1780 goto exit;
1781 }
1782 }
1783 else {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02001784 _PyArg_BadArgument("utf_7_encode", "argument 2", "str or None", args[1]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001785 goto exit;
1786 }
1787skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001788 return_value = _codecs_utf_7_encode_impl(module, str, errors);
1789
1790exit:
1791 return return_value;
1792}
1793
1794PyDoc_STRVAR(_codecs_utf_8_encode__doc__,
1795"utf_8_encode($module, str, errors=None, /)\n"
1796"--\n"
1797"\n");
1798
1799#define _CODECS_UTF_8_ENCODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001800 {"utf_8_encode", (PyCFunction)(void(*)(void))_codecs_utf_8_encode, METH_FASTCALL, _codecs_utf_8_encode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001801
1802static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001803_codecs_utf_8_encode_impl(PyObject *module, PyObject *str,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001804 const char *errors);
1805
1806static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001807_codecs_utf_8_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001808{
1809 PyObject *return_value = NULL;
1810 PyObject *str;
1811 const char *errors = NULL;
1812
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001813 if (!_PyArg_CheckPositional("utf_8_encode", nargs, 1, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01001814 goto exit;
1815 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001816 if (!PyUnicode_Check(args[0])) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02001817 _PyArg_BadArgument("utf_8_encode", "argument 1", "str", args[0]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001818 goto exit;
1819 }
1820 if (PyUnicode_READY(args[0]) == -1) {
1821 goto exit;
1822 }
1823 str = args[0];
1824 if (nargs < 2) {
1825 goto skip_optional;
1826 }
1827 if (args[1] == Py_None) {
1828 errors = NULL;
1829 }
1830 else if (PyUnicode_Check(args[1])) {
1831 Py_ssize_t errors_length;
1832 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
1833 if (errors == NULL) {
1834 goto exit;
1835 }
1836 if (strlen(errors) != (size_t)errors_length) {
1837 PyErr_SetString(PyExc_ValueError, "embedded null character");
1838 goto exit;
1839 }
1840 }
1841 else {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02001842 _PyArg_BadArgument("utf_8_encode", "argument 2", "str or None", args[1]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001843 goto exit;
1844 }
1845skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001846 return_value = _codecs_utf_8_encode_impl(module, str, errors);
1847
1848exit:
1849 return return_value;
1850}
1851
1852PyDoc_STRVAR(_codecs_utf_16_encode__doc__,
1853"utf_16_encode($module, str, errors=None, byteorder=0, /)\n"
1854"--\n"
1855"\n");
1856
1857#define _CODECS_UTF_16_ENCODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001858 {"utf_16_encode", (PyCFunction)(void(*)(void))_codecs_utf_16_encode, METH_FASTCALL, _codecs_utf_16_encode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001859
1860static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001861_codecs_utf_16_encode_impl(PyObject *module, PyObject *str,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001862 const char *errors, int byteorder);
1863
1864static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001865_codecs_utf_16_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001866{
1867 PyObject *return_value = NULL;
1868 PyObject *str;
1869 const char *errors = NULL;
1870 int byteorder = 0;
1871
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001872 if (!_PyArg_CheckPositional("utf_16_encode", nargs, 1, 3)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01001873 goto exit;
1874 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001875 if (!PyUnicode_Check(args[0])) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02001876 _PyArg_BadArgument("utf_16_encode", "argument 1", "str", args[0]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001877 goto exit;
1878 }
1879 if (PyUnicode_READY(args[0]) == -1) {
1880 goto exit;
1881 }
1882 str = args[0];
1883 if (nargs < 2) {
1884 goto skip_optional;
1885 }
1886 if (args[1] == Py_None) {
1887 errors = NULL;
1888 }
1889 else if (PyUnicode_Check(args[1])) {
1890 Py_ssize_t errors_length;
1891 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
1892 if (errors == NULL) {
1893 goto exit;
1894 }
1895 if (strlen(errors) != (size_t)errors_length) {
1896 PyErr_SetString(PyExc_ValueError, "embedded null character");
1897 goto exit;
1898 }
1899 }
1900 else {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02001901 _PyArg_BadArgument("utf_16_encode", "argument 2", "str or None", args[1]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001902 goto exit;
1903 }
1904 if (nargs < 3) {
1905 goto skip_optional;
1906 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001907 byteorder = _PyLong_AsInt(args[2]);
1908 if (byteorder == -1 && PyErr_Occurred()) {
1909 goto exit;
1910 }
1911skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001912 return_value = _codecs_utf_16_encode_impl(module, str, errors, byteorder);
1913
1914exit:
1915 return return_value;
1916}
1917
1918PyDoc_STRVAR(_codecs_utf_16_le_encode__doc__,
1919"utf_16_le_encode($module, str, errors=None, /)\n"
1920"--\n"
1921"\n");
1922
1923#define _CODECS_UTF_16_LE_ENCODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001924 {"utf_16_le_encode", (PyCFunction)(void(*)(void))_codecs_utf_16_le_encode, METH_FASTCALL, _codecs_utf_16_le_encode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001925
1926static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001927_codecs_utf_16_le_encode_impl(PyObject *module, PyObject *str,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001928 const char *errors);
1929
1930static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001931_codecs_utf_16_le_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001932{
1933 PyObject *return_value = NULL;
1934 PyObject *str;
1935 const char *errors = NULL;
1936
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001937 if (!_PyArg_CheckPositional("utf_16_le_encode", nargs, 1, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01001938 goto exit;
1939 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001940 if (!PyUnicode_Check(args[0])) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02001941 _PyArg_BadArgument("utf_16_le_encode", "argument 1", "str", args[0]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001942 goto exit;
1943 }
1944 if (PyUnicode_READY(args[0]) == -1) {
1945 goto exit;
1946 }
1947 str = args[0];
1948 if (nargs < 2) {
1949 goto skip_optional;
1950 }
1951 if (args[1] == Py_None) {
1952 errors = NULL;
1953 }
1954 else if (PyUnicode_Check(args[1])) {
1955 Py_ssize_t errors_length;
1956 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
1957 if (errors == NULL) {
1958 goto exit;
1959 }
1960 if (strlen(errors) != (size_t)errors_length) {
1961 PyErr_SetString(PyExc_ValueError, "embedded null character");
1962 goto exit;
1963 }
1964 }
1965 else {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02001966 _PyArg_BadArgument("utf_16_le_encode", "argument 2", "str or None", args[1]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001967 goto exit;
1968 }
1969skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001970 return_value = _codecs_utf_16_le_encode_impl(module, str, errors);
1971
1972exit:
1973 return return_value;
1974}
1975
1976PyDoc_STRVAR(_codecs_utf_16_be_encode__doc__,
1977"utf_16_be_encode($module, str, errors=None, /)\n"
1978"--\n"
1979"\n");
1980
1981#define _CODECS_UTF_16_BE_ENCODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001982 {"utf_16_be_encode", (PyCFunction)(void(*)(void))_codecs_utf_16_be_encode, METH_FASTCALL, _codecs_utf_16_be_encode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001983
1984static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001985_codecs_utf_16_be_encode_impl(PyObject *module, PyObject *str,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001986 const char *errors);
1987
1988static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001989_codecs_utf_16_be_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001990{
1991 PyObject *return_value = NULL;
1992 PyObject *str;
1993 const char *errors = NULL;
1994
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001995 if (!_PyArg_CheckPositional("utf_16_be_encode", nargs, 1, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01001996 goto exit;
1997 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001998 if (!PyUnicode_Check(args[0])) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02001999 _PyArg_BadArgument("utf_16_be_encode", "argument 1", "str", args[0]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002000 goto exit;
2001 }
2002 if (PyUnicode_READY(args[0]) == -1) {
2003 goto exit;
2004 }
2005 str = args[0];
2006 if (nargs < 2) {
2007 goto skip_optional;
2008 }
2009 if (args[1] == Py_None) {
2010 errors = NULL;
2011 }
2012 else if (PyUnicode_Check(args[1])) {
2013 Py_ssize_t errors_length;
2014 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
2015 if (errors == NULL) {
2016 goto exit;
2017 }
2018 if (strlen(errors) != (size_t)errors_length) {
2019 PyErr_SetString(PyExc_ValueError, "embedded null character");
2020 goto exit;
2021 }
2022 }
2023 else {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02002024 _PyArg_BadArgument("utf_16_be_encode", "argument 2", "str or None", args[1]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002025 goto exit;
2026 }
2027skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002028 return_value = _codecs_utf_16_be_encode_impl(module, str, errors);
2029
2030exit:
2031 return return_value;
2032}
2033
2034PyDoc_STRVAR(_codecs_utf_32_encode__doc__,
2035"utf_32_encode($module, str, errors=None, byteorder=0, /)\n"
2036"--\n"
2037"\n");
2038
2039#define _CODECS_UTF_32_ENCODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002040 {"utf_32_encode", (PyCFunction)(void(*)(void))_codecs_utf_32_encode, METH_FASTCALL, _codecs_utf_32_encode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002041
2042static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002043_codecs_utf_32_encode_impl(PyObject *module, PyObject *str,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002044 const char *errors, int byteorder);
2045
2046static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002047_codecs_utf_32_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002048{
2049 PyObject *return_value = NULL;
2050 PyObject *str;
2051 const char *errors = NULL;
2052 int byteorder = 0;
2053
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002054 if (!_PyArg_CheckPositional("utf_32_encode", nargs, 1, 3)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002055 goto exit;
2056 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002057 if (!PyUnicode_Check(args[0])) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02002058 _PyArg_BadArgument("utf_32_encode", "argument 1", "str", args[0]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002059 goto exit;
2060 }
2061 if (PyUnicode_READY(args[0]) == -1) {
2062 goto exit;
2063 }
2064 str = args[0];
2065 if (nargs < 2) {
2066 goto skip_optional;
2067 }
2068 if (args[1] == Py_None) {
2069 errors = NULL;
2070 }
2071 else if (PyUnicode_Check(args[1])) {
2072 Py_ssize_t errors_length;
2073 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
2074 if (errors == NULL) {
2075 goto exit;
2076 }
2077 if (strlen(errors) != (size_t)errors_length) {
2078 PyErr_SetString(PyExc_ValueError, "embedded null character");
2079 goto exit;
2080 }
2081 }
2082 else {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02002083 _PyArg_BadArgument("utf_32_encode", "argument 2", "str or None", args[1]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002084 goto exit;
2085 }
2086 if (nargs < 3) {
2087 goto skip_optional;
2088 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002089 byteorder = _PyLong_AsInt(args[2]);
2090 if (byteorder == -1 && PyErr_Occurred()) {
2091 goto exit;
2092 }
2093skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002094 return_value = _codecs_utf_32_encode_impl(module, str, errors, byteorder);
2095
2096exit:
2097 return return_value;
2098}
2099
2100PyDoc_STRVAR(_codecs_utf_32_le_encode__doc__,
2101"utf_32_le_encode($module, str, errors=None, /)\n"
2102"--\n"
2103"\n");
2104
2105#define _CODECS_UTF_32_LE_ENCODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002106 {"utf_32_le_encode", (PyCFunction)(void(*)(void))_codecs_utf_32_le_encode, METH_FASTCALL, _codecs_utf_32_le_encode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002107
2108static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002109_codecs_utf_32_le_encode_impl(PyObject *module, PyObject *str,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002110 const char *errors);
2111
2112static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002113_codecs_utf_32_le_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002114{
2115 PyObject *return_value = NULL;
2116 PyObject *str;
2117 const char *errors = NULL;
2118
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002119 if (!_PyArg_CheckPositional("utf_32_le_encode", nargs, 1, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002120 goto exit;
2121 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002122 if (!PyUnicode_Check(args[0])) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02002123 _PyArg_BadArgument("utf_32_le_encode", "argument 1", "str", args[0]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002124 goto exit;
2125 }
2126 if (PyUnicode_READY(args[0]) == -1) {
2127 goto exit;
2128 }
2129 str = args[0];
2130 if (nargs < 2) {
2131 goto skip_optional;
2132 }
2133 if (args[1] == Py_None) {
2134 errors = NULL;
2135 }
2136 else if (PyUnicode_Check(args[1])) {
2137 Py_ssize_t errors_length;
2138 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
2139 if (errors == NULL) {
2140 goto exit;
2141 }
2142 if (strlen(errors) != (size_t)errors_length) {
2143 PyErr_SetString(PyExc_ValueError, "embedded null character");
2144 goto exit;
2145 }
2146 }
2147 else {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02002148 _PyArg_BadArgument("utf_32_le_encode", "argument 2", "str or None", args[1]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002149 goto exit;
2150 }
2151skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002152 return_value = _codecs_utf_32_le_encode_impl(module, str, errors);
2153
2154exit:
2155 return return_value;
2156}
2157
2158PyDoc_STRVAR(_codecs_utf_32_be_encode__doc__,
2159"utf_32_be_encode($module, str, errors=None, /)\n"
2160"--\n"
2161"\n");
2162
2163#define _CODECS_UTF_32_BE_ENCODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002164 {"utf_32_be_encode", (PyCFunction)(void(*)(void))_codecs_utf_32_be_encode, METH_FASTCALL, _codecs_utf_32_be_encode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002165
2166static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002167_codecs_utf_32_be_encode_impl(PyObject *module, PyObject *str,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002168 const char *errors);
2169
2170static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002171_codecs_utf_32_be_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002172{
2173 PyObject *return_value = NULL;
2174 PyObject *str;
2175 const char *errors = NULL;
2176
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002177 if (!_PyArg_CheckPositional("utf_32_be_encode", nargs, 1, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002178 goto exit;
2179 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002180 if (!PyUnicode_Check(args[0])) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02002181 _PyArg_BadArgument("utf_32_be_encode", "argument 1", "str", args[0]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002182 goto exit;
2183 }
2184 if (PyUnicode_READY(args[0]) == -1) {
2185 goto exit;
2186 }
2187 str = args[0];
2188 if (nargs < 2) {
2189 goto skip_optional;
2190 }
2191 if (args[1] == Py_None) {
2192 errors = NULL;
2193 }
2194 else if (PyUnicode_Check(args[1])) {
2195 Py_ssize_t errors_length;
2196 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
2197 if (errors == NULL) {
2198 goto exit;
2199 }
2200 if (strlen(errors) != (size_t)errors_length) {
2201 PyErr_SetString(PyExc_ValueError, "embedded null character");
2202 goto exit;
2203 }
2204 }
2205 else {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02002206 _PyArg_BadArgument("utf_32_be_encode", "argument 2", "str or None", args[1]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002207 goto exit;
2208 }
2209skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002210 return_value = _codecs_utf_32_be_encode_impl(module, str, errors);
2211
2212exit:
2213 return return_value;
2214}
2215
2216PyDoc_STRVAR(_codecs_unicode_escape_encode__doc__,
2217"unicode_escape_encode($module, str, errors=None, /)\n"
2218"--\n"
2219"\n");
2220
2221#define _CODECS_UNICODE_ESCAPE_ENCODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002222 {"unicode_escape_encode", (PyCFunction)(void(*)(void))_codecs_unicode_escape_encode, METH_FASTCALL, _codecs_unicode_escape_encode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002223
2224static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002225_codecs_unicode_escape_encode_impl(PyObject *module, PyObject *str,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002226 const char *errors);
2227
2228static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002229_codecs_unicode_escape_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002230{
2231 PyObject *return_value = NULL;
2232 PyObject *str;
2233 const char *errors = NULL;
2234
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002235 if (!_PyArg_CheckPositional("unicode_escape_encode", nargs, 1, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002236 goto exit;
2237 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002238 if (!PyUnicode_Check(args[0])) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02002239 _PyArg_BadArgument("unicode_escape_encode", "argument 1", "str", args[0]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002240 goto exit;
2241 }
2242 if (PyUnicode_READY(args[0]) == -1) {
2243 goto exit;
2244 }
2245 str = args[0];
2246 if (nargs < 2) {
2247 goto skip_optional;
2248 }
2249 if (args[1] == Py_None) {
2250 errors = NULL;
2251 }
2252 else if (PyUnicode_Check(args[1])) {
2253 Py_ssize_t errors_length;
2254 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
2255 if (errors == NULL) {
2256 goto exit;
2257 }
2258 if (strlen(errors) != (size_t)errors_length) {
2259 PyErr_SetString(PyExc_ValueError, "embedded null character");
2260 goto exit;
2261 }
2262 }
2263 else {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02002264 _PyArg_BadArgument("unicode_escape_encode", "argument 2", "str or None", args[1]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002265 goto exit;
2266 }
2267skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002268 return_value = _codecs_unicode_escape_encode_impl(module, str, errors);
2269
2270exit:
2271 return return_value;
2272}
2273
2274PyDoc_STRVAR(_codecs_raw_unicode_escape_encode__doc__,
2275"raw_unicode_escape_encode($module, str, errors=None, /)\n"
2276"--\n"
2277"\n");
2278
2279#define _CODECS_RAW_UNICODE_ESCAPE_ENCODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002280 {"raw_unicode_escape_encode", (PyCFunction)(void(*)(void))_codecs_raw_unicode_escape_encode, METH_FASTCALL, _codecs_raw_unicode_escape_encode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002281
2282static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002283_codecs_raw_unicode_escape_encode_impl(PyObject *module, PyObject *str,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002284 const char *errors);
2285
2286static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002287_codecs_raw_unicode_escape_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002288{
2289 PyObject *return_value = NULL;
2290 PyObject *str;
2291 const char *errors = NULL;
2292
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002293 if (!_PyArg_CheckPositional("raw_unicode_escape_encode", nargs, 1, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002294 goto exit;
2295 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002296 if (!PyUnicode_Check(args[0])) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02002297 _PyArg_BadArgument("raw_unicode_escape_encode", "argument 1", "str", args[0]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002298 goto exit;
2299 }
2300 if (PyUnicode_READY(args[0]) == -1) {
2301 goto exit;
2302 }
2303 str = args[0];
2304 if (nargs < 2) {
2305 goto skip_optional;
2306 }
2307 if (args[1] == Py_None) {
2308 errors = NULL;
2309 }
2310 else if (PyUnicode_Check(args[1])) {
2311 Py_ssize_t errors_length;
2312 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
2313 if (errors == NULL) {
2314 goto exit;
2315 }
2316 if (strlen(errors) != (size_t)errors_length) {
2317 PyErr_SetString(PyExc_ValueError, "embedded null character");
2318 goto exit;
2319 }
2320 }
2321 else {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02002322 _PyArg_BadArgument("raw_unicode_escape_encode", "argument 2", "str or None", args[1]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002323 goto exit;
2324 }
2325skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002326 return_value = _codecs_raw_unicode_escape_encode_impl(module, str, errors);
2327
2328exit:
2329 return return_value;
2330}
2331
2332PyDoc_STRVAR(_codecs_latin_1_encode__doc__,
2333"latin_1_encode($module, str, errors=None, /)\n"
2334"--\n"
2335"\n");
2336
2337#define _CODECS_LATIN_1_ENCODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002338 {"latin_1_encode", (PyCFunction)(void(*)(void))_codecs_latin_1_encode, METH_FASTCALL, _codecs_latin_1_encode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002339
2340static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002341_codecs_latin_1_encode_impl(PyObject *module, PyObject *str,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002342 const char *errors);
2343
2344static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002345_codecs_latin_1_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002346{
2347 PyObject *return_value = NULL;
2348 PyObject *str;
2349 const char *errors = NULL;
2350
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002351 if (!_PyArg_CheckPositional("latin_1_encode", nargs, 1, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002352 goto exit;
2353 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002354 if (!PyUnicode_Check(args[0])) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02002355 _PyArg_BadArgument("latin_1_encode", "argument 1", "str", args[0]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002356 goto exit;
2357 }
2358 if (PyUnicode_READY(args[0]) == -1) {
2359 goto exit;
2360 }
2361 str = args[0];
2362 if (nargs < 2) {
2363 goto skip_optional;
2364 }
2365 if (args[1] == Py_None) {
2366 errors = NULL;
2367 }
2368 else if (PyUnicode_Check(args[1])) {
2369 Py_ssize_t errors_length;
2370 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
2371 if (errors == NULL) {
2372 goto exit;
2373 }
2374 if (strlen(errors) != (size_t)errors_length) {
2375 PyErr_SetString(PyExc_ValueError, "embedded null character");
2376 goto exit;
2377 }
2378 }
2379 else {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02002380 _PyArg_BadArgument("latin_1_encode", "argument 2", "str or None", args[1]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002381 goto exit;
2382 }
2383skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002384 return_value = _codecs_latin_1_encode_impl(module, str, errors);
2385
2386exit:
2387 return return_value;
2388}
2389
2390PyDoc_STRVAR(_codecs_ascii_encode__doc__,
2391"ascii_encode($module, str, errors=None, /)\n"
2392"--\n"
2393"\n");
2394
2395#define _CODECS_ASCII_ENCODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002396 {"ascii_encode", (PyCFunction)(void(*)(void))_codecs_ascii_encode, METH_FASTCALL, _codecs_ascii_encode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002397
2398static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002399_codecs_ascii_encode_impl(PyObject *module, PyObject *str,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002400 const char *errors);
2401
2402static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002403_codecs_ascii_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002404{
2405 PyObject *return_value = NULL;
2406 PyObject *str;
2407 const char *errors = NULL;
2408
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002409 if (!_PyArg_CheckPositional("ascii_encode", nargs, 1, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002410 goto exit;
2411 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002412 if (!PyUnicode_Check(args[0])) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02002413 _PyArg_BadArgument("ascii_encode", "argument 1", "str", args[0]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002414 goto exit;
2415 }
2416 if (PyUnicode_READY(args[0]) == -1) {
2417 goto exit;
2418 }
2419 str = args[0];
2420 if (nargs < 2) {
2421 goto skip_optional;
2422 }
2423 if (args[1] == Py_None) {
2424 errors = NULL;
2425 }
2426 else if (PyUnicode_Check(args[1])) {
2427 Py_ssize_t errors_length;
2428 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
2429 if (errors == NULL) {
2430 goto exit;
2431 }
2432 if (strlen(errors) != (size_t)errors_length) {
2433 PyErr_SetString(PyExc_ValueError, "embedded null character");
2434 goto exit;
2435 }
2436 }
2437 else {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02002438 _PyArg_BadArgument("ascii_encode", "argument 2", "str or None", args[1]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002439 goto exit;
2440 }
2441skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002442 return_value = _codecs_ascii_encode_impl(module, str, errors);
2443
2444exit:
2445 return return_value;
2446}
2447
2448PyDoc_STRVAR(_codecs_charmap_encode__doc__,
2449"charmap_encode($module, str, errors=None, mapping=None, /)\n"
2450"--\n"
2451"\n");
2452
2453#define _CODECS_CHARMAP_ENCODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002454 {"charmap_encode", (PyCFunction)(void(*)(void))_codecs_charmap_encode, METH_FASTCALL, _codecs_charmap_encode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002455
2456static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002457_codecs_charmap_encode_impl(PyObject *module, PyObject *str,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002458 const char *errors, PyObject *mapping);
2459
2460static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002461_codecs_charmap_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002462{
2463 PyObject *return_value = NULL;
2464 PyObject *str;
2465 const char *errors = NULL;
Serhiy Storchaka279f4462019-09-14 12:24:05 +03002466 PyObject *mapping = Py_None;
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002467
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002468 if (!_PyArg_CheckPositional("charmap_encode", nargs, 1, 3)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002469 goto exit;
2470 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002471 if (!PyUnicode_Check(args[0])) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02002472 _PyArg_BadArgument("charmap_encode", "argument 1", "str", args[0]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002473 goto exit;
2474 }
2475 if (PyUnicode_READY(args[0]) == -1) {
2476 goto exit;
2477 }
2478 str = args[0];
2479 if (nargs < 2) {
2480 goto skip_optional;
2481 }
2482 if (args[1] == Py_None) {
2483 errors = NULL;
2484 }
2485 else if (PyUnicode_Check(args[1])) {
2486 Py_ssize_t errors_length;
2487 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
2488 if (errors == NULL) {
2489 goto exit;
2490 }
2491 if (strlen(errors) != (size_t)errors_length) {
2492 PyErr_SetString(PyExc_ValueError, "embedded null character");
2493 goto exit;
2494 }
2495 }
2496 else {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02002497 _PyArg_BadArgument("charmap_encode", "argument 2", "str or None", args[1]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002498 goto exit;
2499 }
2500 if (nargs < 3) {
2501 goto skip_optional;
2502 }
2503 mapping = args[2];
2504skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002505 return_value = _codecs_charmap_encode_impl(module, str, errors, mapping);
2506
2507exit:
2508 return return_value;
2509}
2510
2511PyDoc_STRVAR(_codecs_charmap_build__doc__,
2512"charmap_build($module, map, /)\n"
2513"--\n"
2514"\n");
2515
2516#define _CODECS_CHARMAP_BUILD_METHODDEF \
2517 {"charmap_build", (PyCFunction)_codecs_charmap_build, METH_O, _codecs_charmap_build__doc__},
2518
2519static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002520_codecs_charmap_build_impl(PyObject *module, PyObject *map);
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002521
2522static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002523_codecs_charmap_build(PyObject *module, PyObject *arg)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002524{
2525 PyObject *return_value = NULL;
2526 PyObject *map;
2527
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02002528 if (!PyUnicode_Check(arg)) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02002529 _PyArg_BadArgument("charmap_build", "argument", "str", arg);
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002530 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002531 }
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02002532 if (PyUnicode_READY(arg) == -1) {
2533 goto exit;
2534 }
2535 map = arg;
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002536 return_value = _codecs_charmap_build_impl(module, map);
2537
2538exit:
2539 return return_value;
2540}
2541
Steve Dowercc16be82016-09-08 10:35:16 -07002542#if defined(MS_WINDOWS)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002543
2544PyDoc_STRVAR(_codecs_mbcs_encode__doc__,
2545"mbcs_encode($module, str, errors=None, /)\n"
2546"--\n"
2547"\n");
2548
2549#define _CODECS_MBCS_ENCODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002550 {"mbcs_encode", (PyCFunction)(void(*)(void))_codecs_mbcs_encode, METH_FASTCALL, _codecs_mbcs_encode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002551
2552static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002553_codecs_mbcs_encode_impl(PyObject *module, PyObject *str, const char *errors);
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002554
2555static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002556_codecs_mbcs_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002557{
2558 PyObject *return_value = NULL;
2559 PyObject *str;
2560 const char *errors = NULL;
2561
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002562 if (!_PyArg_CheckPositional("mbcs_encode", nargs, 1, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002563 goto exit;
2564 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002565 if (!PyUnicode_Check(args[0])) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02002566 _PyArg_BadArgument("mbcs_encode", "argument 1", "str", args[0]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002567 goto exit;
2568 }
2569 if (PyUnicode_READY(args[0]) == -1) {
2570 goto exit;
2571 }
2572 str = args[0];
2573 if (nargs < 2) {
2574 goto skip_optional;
2575 }
2576 if (args[1] == Py_None) {
2577 errors = NULL;
2578 }
2579 else if (PyUnicode_Check(args[1])) {
2580 Py_ssize_t errors_length;
2581 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
2582 if (errors == NULL) {
2583 goto exit;
2584 }
2585 if (strlen(errors) != (size_t)errors_length) {
2586 PyErr_SetString(PyExc_ValueError, "embedded null character");
2587 goto exit;
2588 }
2589 }
2590 else {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02002591 _PyArg_BadArgument("mbcs_encode", "argument 2", "str or None", args[1]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002592 goto exit;
2593 }
2594skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002595 return_value = _codecs_mbcs_encode_impl(module, str, errors);
2596
2597exit:
2598 return return_value;
2599}
2600
Steve Dowercc16be82016-09-08 10:35:16 -07002601#endif /* defined(MS_WINDOWS) */
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002602
Steve Dowercc16be82016-09-08 10:35:16 -07002603#if defined(MS_WINDOWS)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002604
Steve Dowerf5aba582016-09-06 19:42:27 -07002605PyDoc_STRVAR(_codecs_oem_encode__doc__,
2606"oem_encode($module, str, errors=None, /)\n"
2607"--\n"
2608"\n");
2609
2610#define _CODECS_OEM_ENCODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002611 {"oem_encode", (PyCFunction)(void(*)(void))_codecs_oem_encode, METH_FASTCALL, _codecs_oem_encode__doc__},
Steve Dowerf5aba582016-09-06 19:42:27 -07002612
2613static PyObject *
2614_codecs_oem_encode_impl(PyObject *module, PyObject *str, const char *errors);
2615
2616static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002617_codecs_oem_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Steve Dowerf5aba582016-09-06 19:42:27 -07002618{
2619 PyObject *return_value = NULL;
2620 PyObject *str;
2621 const char *errors = NULL;
2622
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002623 if (!_PyArg_CheckPositional("oem_encode", nargs, 1, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002624 goto exit;
2625 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002626 if (!PyUnicode_Check(args[0])) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02002627 _PyArg_BadArgument("oem_encode", "argument 1", "str", args[0]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002628 goto exit;
2629 }
2630 if (PyUnicode_READY(args[0]) == -1) {
2631 goto exit;
2632 }
2633 str = args[0];
2634 if (nargs < 2) {
2635 goto skip_optional;
2636 }
2637 if (args[1] == Py_None) {
2638 errors = NULL;
2639 }
2640 else if (PyUnicode_Check(args[1])) {
2641 Py_ssize_t errors_length;
2642 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
2643 if (errors == NULL) {
2644 goto exit;
2645 }
2646 if (strlen(errors) != (size_t)errors_length) {
2647 PyErr_SetString(PyExc_ValueError, "embedded null character");
2648 goto exit;
2649 }
2650 }
2651 else {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02002652 _PyArg_BadArgument("oem_encode", "argument 2", "str or None", args[1]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002653 goto exit;
2654 }
2655skip_optional:
Steve Dowerf5aba582016-09-06 19:42:27 -07002656 return_value = _codecs_oem_encode_impl(module, str, errors);
2657
2658exit:
2659 return return_value;
2660}
2661
Steve Dowercc16be82016-09-08 10:35:16 -07002662#endif /* defined(MS_WINDOWS) */
Steve Dowerf5aba582016-09-06 19:42:27 -07002663
Steve Dowercc16be82016-09-08 10:35:16 -07002664#if defined(MS_WINDOWS)
Steve Dowerf5aba582016-09-06 19:42:27 -07002665
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002666PyDoc_STRVAR(_codecs_code_page_encode__doc__,
2667"code_page_encode($module, code_page, str, errors=None, /)\n"
2668"--\n"
2669"\n");
2670
2671#define _CODECS_CODE_PAGE_ENCODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002672 {"code_page_encode", (PyCFunction)(void(*)(void))_codecs_code_page_encode, METH_FASTCALL, _codecs_code_page_encode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002673
2674static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002675_codecs_code_page_encode_impl(PyObject *module, int code_page, PyObject *str,
2676 const char *errors);
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002677
2678static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002679_codecs_code_page_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002680{
2681 PyObject *return_value = NULL;
2682 int code_page;
2683 PyObject *str;
2684 const char *errors = NULL;
2685
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002686 if (!_PyArg_CheckPositional("code_page_encode", nargs, 2, 3)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002687 goto exit;
2688 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002689 code_page = _PyLong_AsInt(args[0]);
2690 if (code_page == -1 && PyErr_Occurred()) {
2691 goto exit;
2692 }
2693 if (!PyUnicode_Check(args[1])) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02002694 _PyArg_BadArgument("code_page_encode", "argument 2", "str", args[1]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002695 goto exit;
2696 }
2697 if (PyUnicode_READY(args[1]) == -1) {
2698 goto exit;
2699 }
2700 str = args[1];
2701 if (nargs < 3) {
2702 goto skip_optional;
2703 }
2704 if (args[2] == Py_None) {
2705 errors = NULL;
2706 }
2707 else if (PyUnicode_Check(args[2])) {
2708 Py_ssize_t errors_length;
2709 errors = PyUnicode_AsUTF8AndSize(args[2], &errors_length);
2710 if (errors == NULL) {
2711 goto exit;
2712 }
2713 if (strlen(errors) != (size_t)errors_length) {
2714 PyErr_SetString(PyExc_ValueError, "embedded null character");
2715 goto exit;
2716 }
2717 }
2718 else {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02002719 _PyArg_BadArgument("code_page_encode", "argument 3", "str or None", args[2]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002720 goto exit;
2721 }
2722skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002723 return_value = _codecs_code_page_encode_impl(module, code_page, str, errors);
2724
2725exit:
2726 return return_value;
2727}
2728
Steve Dowercc16be82016-09-08 10:35:16 -07002729#endif /* defined(MS_WINDOWS) */
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002730
2731PyDoc_STRVAR(_codecs_register_error__doc__,
2732"register_error($module, errors, handler, /)\n"
2733"--\n"
2734"\n"
2735"Register the specified error handler under the name errors.\n"
2736"\n"
2737"handler must be a callable object, that will be called with an exception\n"
2738"instance containing information about the location of the encoding/decoding\n"
2739"error and must return a (replacement, new position) tuple.");
2740
2741#define _CODECS_REGISTER_ERROR_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002742 {"register_error", (PyCFunction)(void(*)(void))_codecs_register_error, METH_FASTCALL, _codecs_register_error__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002743
2744static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002745_codecs_register_error_impl(PyObject *module, const char *errors,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002746 PyObject *handler);
2747
2748static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002749_codecs_register_error(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002750{
2751 PyObject *return_value = NULL;
2752 const char *errors;
2753 PyObject *handler;
2754
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002755 if (!_PyArg_CheckPositional("register_error", nargs, 2, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002756 goto exit;
2757 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002758 if (!PyUnicode_Check(args[0])) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02002759 _PyArg_BadArgument("register_error", "argument 1", "str", args[0]);
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002760 goto exit;
2761 }
2762 Py_ssize_t errors_length;
2763 errors = PyUnicode_AsUTF8AndSize(args[0], &errors_length);
2764 if (errors == NULL) {
2765 goto exit;
2766 }
2767 if (strlen(errors) != (size_t)errors_length) {
2768 PyErr_SetString(PyExc_ValueError, "embedded null character");
2769 goto exit;
2770 }
2771 handler = args[1];
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002772 return_value = _codecs_register_error_impl(module, errors, handler);
2773
2774exit:
2775 return return_value;
2776}
2777
2778PyDoc_STRVAR(_codecs_lookup_error__doc__,
2779"lookup_error($module, name, /)\n"
2780"--\n"
2781"\n"
2782"lookup_error(errors) -> handler\n"
2783"\n"
2784"Return the error handler for the specified error handling name or raise a\n"
2785"LookupError, if no handler exists under this name.");
2786
2787#define _CODECS_LOOKUP_ERROR_METHODDEF \
2788 {"lookup_error", (PyCFunction)_codecs_lookup_error, METH_O, _codecs_lookup_error__doc__},
2789
2790static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002791_codecs_lookup_error_impl(PyObject *module, const char *name);
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002792
2793static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002794_codecs_lookup_error(PyObject *module, PyObject *arg)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002795{
2796 PyObject *return_value = NULL;
2797 const char *name;
2798
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02002799 if (!PyUnicode_Check(arg)) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02002800 _PyArg_BadArgument("lookup_error", "argument", "str", arg);
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02002801 goto exit;
2802 }
2803 Py_ssize_t name_length;
2804 name = PyUnicode_AsUTF8AndSize(arg, &name_length);
2805 if (name == NULL) {
2806 goto exit;
2807 }
2808 if (strlen(name) != (size_t)name_length) {
2809 PyErr_SetString(PyExc_ValueError, "embedded null character");
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002810 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002811 }
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002812 return_value = _codecs_lookup_error_impl(module, name);
2813
2814exit:
2815 return return_value;
2816}
2817
2818#ifndef _CODECS_MBCS_DECODE_METHODDEF
2819 #define _CODECS_MBCS_DECODE_METHODDEF
2820#endif /* !defined(_CODECS_MBCS_DECODE_METHODDEF) */
2821
Steve Dowerf5aba582016-09-06 19:42:27 -07002822#ifndef _CODECS_OEM_DECODE_METHODDEF
2823 #define _CODECS_OEM_DECODE_METHODDEF
2824#endif /* !defined(_CODECS_OEM_DECODE_METHODDEF) */
2825
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002826#ifndef _CODECS_CODE_PAGE_DECODE_METHODDEF
2827 #define _CODECS_CODE_PAGE_DECODE_METHODDEF
2828#endif /* !defined(_CODECS_CODE_PAGE_DECODE_METHODDEF) */
2829
2830#ifndef _CODECS_MBCS_ENCODE_METHODDEF
2831 #define _CODECS_MBCS_ENCODE_METHODDEF
2832#endif /* !defined(_CODECS_MBCS_ENCODE_METHODDEF) */
2833
Steve Dowerf5aba582016-09-06 19:42:27 -07002834#ifndef _CODECS_OEM_ENCODE_METHODDEF
2835 #define _CODECS_OEM_ENCODE_METHODDEF
2836#endif /* !defined(_CODECS_OEM_ENCODE_METHODDEF) */
2837
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002838#ifndef _CODECS_CODE_PAGE_ENCODE_METHODDEF
2839 #define _CODECS_CODE_PAGE_ENCODE_METHODDEF
2840#endif /* !defined(_CODECS_CODE_PAGE_ENCODE_METHODDEF) */
Hai Shid332e7b2020-09-29 05:41:11 +08002841/*[clinic end generated code: output=9a97e2ddf3e69072 input=a9049054013a1b77]*/