blob: d1f4cf3fc681307d0cfe41003937c9cb28fb6cc1 [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
18PyDoc_STRVAR(_codecs_lookup__doc__,
19"lookup($module, encoding, /)\n"
20"--\n"
21"\n"
22"Looks up a codec tuple in the Python codec registry and returns a CodecInfo object.");
23
24#define _CODECS_LOOKUP_METHODDEF \
25 {"lookup", (PyCFunction)_codecs_lookup, METH_O, _codecs_lookup__doc__},
26
27static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +030028_codecs_lookup_impl(PyObject *module, const char *encoding);
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +030029
30static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +030031_codecs_lookup(PyObject *module, PyObject *arg)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +030032{
33 PyObject *return_value = NULL;
34 const char *encoding;
35
Serhiy Storchaka32d96a22018-12-25 13:23:47 +020036 if (!PyUnicode_Check(arg)) {
Serhiy Storchaka4fa95912019-01-11 16:01:14 +020037 _PyArg_BadArgument("lookup", 0, "str", arg);
Serhiy Storchaka32d96a22018-12-25 13:23:47 +020038 goto exit;
39 }
40 Py_ssize_t encoding_length;
41 encoding = PyUnicode_AsUTF8AndSize(arg, &encoding_length);
42 if (encoding == NULL) {
43 goto exit;
44 }
45 if (strlen(encoding) != (size_t)encoding_length) {
46 PyErr_SetString(PyExc_ValueError, "embedded null character");
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +030047 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030048 }
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +030049 return_value = _codecs_lookup_impl(module, encoding);
50
51exit:
52 return return_value;
53}
54
55PyDoc_STRVAR(_codecs_encode__doc__,
Serhiy Storchakac97a9622015-08-09 12:23:08 +030056"encode($module, /, obj, encoding=\'utf-8\', errors=\'strict\')\n"
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +030057"--\n"
58"\n"
59"Encodes obj using the codec registered for encoding.\n"
60"\n"
Serhiy Storchakac97a9622015-08-09 12:23:08 +030061"The default encoding is \'utf-8\'. errors may be given to set a\n"
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +030062"different error handling scheme. Default is \'strict\' meaning that encoding\n"
63"errors raise a ValueError. Other possible values are \'ignore\', \'replace\'\n"
64"and \'backslashreplace\' as well as any other name registered with\n"
65"codecs.register_error that can handle ValueErrors.");
66
67#define _CODECS_ENCODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +020068 {"encode", (PyCFunction)(void(*)(void))_codecs_encode, METH_FASTCALL|METH_KEYWORDS, _codecs_encode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +030069
70static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +030071_codecs_encode_impl(PyObject *module, PyObject *obj, const char *encoding,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +030072 const char *errors);
73
74static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +020075_codecs_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +030076{
77 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +030078 static const char * const _keywords[] = {"obj", "encoding", "errors", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +020079 static _PyArg_Parser _parser = {NULL, _keywords, "encode", 0};
80 PyObject *argsbuf[3];
81 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +030082 PyObject *obj;
83 const char *encoding = NULL;
84 const char *errors = NULL;
85
Serhiy Storchaka31913912019-03-14 10:32:22 +020086 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 3, 0, argsbuf);
87 if (!args) {
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +030088 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030089 }
Serhiy Storchaka31913912019-03-14 10:32:22 +020090 obj = args[0];
91 if (!noptargs) {
92 goto skip_optional_pos;
93 }
94 if (args[1]) {
95 if (!PyUnicode_Check(args[1])) {
96 _PyArg_BadArgument("encode", 2, "str", args[1]);
97 goto exit;
98 }
99 Py_ssize_t encoding_length;
100 encoding = PyUnicode_AsUTF8AndSize(args[1], &encoding_length);
101 if (encoding == NULL) {
102 goto exit;
103 }
104 if (strlen(encoding) != (size_t)encoding_length) {
105 PyErr_SetString(PyExc_ValueError, "embedded null character");
106 goto exit;
107 }
108 if (!--noptargs) {
109 goto skip_optional_pos;
110 }
111 }
112 if (!PyUnicode_Check(args[2])) {
113 _PyArg_BadArgument("encode", 3, "str", args[2]);
114 goto exit;
115 }
116 Py_ssize_t errors_length;
117 errors = PyUnicode_AsUTF8AndSize(args[2], &errors_length);
118 if (errors == NULL) {
119 goto exit;
120 }
121 if (strlen(errors) != (size_t)errors_length) {
122 PyErr_SetString(PyExc_ValueError, "embedded null character");
123 goto exit;
124 }
125skip_optional_pos:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300126 return_value = _codecs_encode_impl(module, obj, encoding, errors);
127
128exit:
129 return return_value;
130}
131
132PyDoc_STRVAR(_codecs_decode__doc__,
Serhiy Storchakac97a9622015-08-09 12:23:08 +0300133"decode($module, /, obj, encoding=\'utf-8\', errors=\'strict\')\n"
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300134"--\n"
135"\n"
136"Decodes obj using the codec registered for encoding.\n"
137"\n"
Serhiy Storchakac97a9622015-08-09 12:23:08 +0300138"Default encoding is \'utf-8\'. errors may be given to set a\n"
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300139"different error handling scheme. Default is \'strict\' meaning that encoding\n"
140"errors raise a ValueError. Other possible values are \'ignore\', \'replace\'\n"
141"and \'backslashreplace\' as well as any other name registered with\n"
142"codecs.register_error that can handle ValueErrors.");
143
144#define _CODECS_DECODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200145 {"decode", (PyCFunction)(void(*)(void))_codecs_decode, METH_FASTCALL|METH_KEYWORDS, _codecs_decode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300146
147static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300148_codecs_decode_impl(PyObject *module, PyObject *obj, const char *encoding,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300149 const char *errors);
150
151static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200152_codecs_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300153{
154 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300155 static const char * const _keywords[] = {"obj", "encoding", "errors", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +0200156 static _PyArg_Parser _parser = {NULL, _keywords, "decode", 0};
157 PyObject *argsbuf[3];
158 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300159 PyObject *obj;
160 const char *encoding = NULL;
161 const char *errors = NULL;
162
Serhiy Storchaka31913912019-03-14 10:32:22 +0200163 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 3, 0, argsbuf);
164 if (!args) {
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300165 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300166 }
Serhiy Storchaka31913912019-03-14 10:32:22 +0200167 obj = args[0];
168 if (!noptargs) {
169 goto skip_optional_pos;
170 }
171 if (args[1]) {
172 if (!PyUnicode_Check(args[1])) {
173 _PyArg_BadArgument("decode", 2, "str", args[1]);
174 goto exit;
175 }
176 Py_ssize_t encoding_length;
177 encoding = PyUnicode_AsUTF8AndSize(args[1], &encoding_length);
178 if (encoding == NULL) {
179 goto exit;
180 }
181 if (strlen(encoding) != (size_t)encoding_length) {
182 PyErr_SetString(PyExc_ValueError, "embedded null character");
183 goto exit;
184 }
185 if (!--noptargs) {
186 goto skip_optional_pos;
187 }
188 }
189 if (!PyUnicode_Check(args[2])) {
190 _PyArg_BadArgument("decode", 3, "str", args[2]);
191 goto exit;
192 }
193 Py_ssize_t errors_length;
194 errors = PyUnicode_AsUTF8AndSize(args[2], &errors_length);
195 if (errors == NULL) {
196 goto exit;
197 }
198 if (strlen(errors) != (size_t)errors_length) {
199 PyErr_SetString(PyExc_ValueError, "embedded null character");
200 goto exit;
201 }
202skip_optional_pos:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300203 return_value = _codecs_decode_impl(module, obj, encoding, errors);
204
205exit:
206 return return_value;
207}
208
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300209PyDoc_STRVAR(_codecs__forget_codec__doc__,
210"_forget_codec($module, encoding, /)\n"
211"--\n"
212"\n"
213"Purge the named codec from the internal codec lookup cache");
214
215#define _CODECS__FORGET_CODEC_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300216 {"_forget_codec", (PyCFunction)_codecs__forget_codec, METH_O, _codecs__forget_codec__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300217
218static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300219_codecs__forget_codec_impl(PyObject *module, const char *encoding);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300220
221static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300222_codecs__forget_codec(PyObject *module, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300223{
224 PyObject *return_value = NULL;
225 const char *encoding;
226
Serhiy Storchaka32d96a22018-12-25 13:23:47 +0200227 if (!PyUnicode_Check(arg)) {
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200228 _PyArg_BadArgument("_forget_codec", 0, "str", arg);
Serhiy Storchaka32d96a22018-12-25 13:23:47 +0200229 goto exit;
230 }
231 Py_ssize_t encoding_length;
232 encoding = PyUnicode_AsUTF8AndSize(arg, &encoding_length);
233 if (encoding == NULL) {
234 goto exit;
235 }
236 if (strlen(encoding) != (size_t)encoding_length) {
237 PyErr_SetString(PyExc_ValueError, "embedded null character");
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300238 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300239 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300240 return_value = _codecs__forget_codec_impl(module, encoding);
241
242exit:
243 return return_value;
244}
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300245
246PyDoc_STRVAR(_codecs_escape_decode__doc__,
247"escape_decode($module, data, errors=None, /)\n"
248"--\n"
249"\n");
250
251#define _CODECS_ESCAPE_DECODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200252 {"escape_decode", (PyCFunction)(void(*)(void))_codecs_escape_decode, METH_FASTCALL, _codecs_escape_decode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300253
254static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300255_codecs_escape_decode_impl(PyObject *module, Py_buffer *data,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300256 const char *errors);
257
258static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200259_codecs_escape_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300260{
261 PyObject *return_value = NULL;
262 Py_buffer data = {NULL, NULL};
263 const char *errors = NULL;
264
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200265 if (!_PyArg_CheckPositional("escape_decode", nargs, 1, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100266 goto exit;
267 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200268 if (PyUnicode_Check(args[0])) {
269 Py_ssize_t len;
270 const char *ptr = PyUnicode_AsUTF8AndSize(args[0], &len);
271 if (ptr == NULL) {
272 goto exit;
273 }
274 PyBuffer_FillInfo(&data, args[0], (void *)ptr, len, 1, 0);
275 }
276 else { /* any bytes-like object */
277 if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
278 goto exit;
279 }
280 if (!PyBuffer_IsContiguous(&data, 'C')) {
281 _PyArg_BadArgument("escape_decode", 1, "contiguous buffer", args[0]);
282 goto exit;
283 }
284 }
285 if (nargs < 2) {
286 goto skip_optional;
287 }
288 if (args[1] == Py_None) {
289 errors = NULL;
290 }
291 else if (PyUnicode_Check(args[1])) {
292 Py_ssize_t errors_length;
293 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
294 if (errors == NULL) {
295 goto exit;
296 }
297 if (strlen(errors) != (size_t)errors_length) {
298 PyErr_SetString(PyExc_ValueError, "embedded null character");
299 goto exit;
300 }
301 }
302 else {
303 _PyArg_BadArgument("escape_decode", 2, "str or None", args[1]);
304 goto exit;
305 }
306skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300307 return_value = _codecs_escape_decode_impl(module, &data, errors);
308
309exit:
310 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300311 if (data.obj) {
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300312 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300313 }
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300314
315 return return_value;
316}
317
318PyDoc_STRVAR(_codecs_escape_encode__doc__,
319"escape_encode($module, data, errors=None, /)\n"
320"--\n"
321"\n");
322
323#define _CODECS_ESCAPE_ENCODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200324 {"escape_encode", (PyCFunction)(void(*)(void))_codecs_escape_encode, METH_FASTCALL, _codecs_escape_encode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300325
326static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300327_codecs_escape_encode_impl(PyObject *module, PyObject *data,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300328 const char *errors);
329
330static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200331_codecs_escape_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300332{
333 PyObject *return_value = NULL;
334 PyObject *data;
335 const char *errors = NULL;
336
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200337 if (!_PyArg_CheckPositional("escape_encode", nargs, 1, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100338 goto exit;
339 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200340 if (!PyBytes_Check(args[0])) {
341 _PyArg_BadArgument("escape_encode", 1, "bytes", args[0]);
342 goto exit;
343 }
344 data = args[0];
345 if (nargs < 2) {
346 goto skip_optional;
347 }
348 if (args[1] == Py_None) {
349 errors = NULL;
350 }
351 else if (PyUnicode_Check(args[1])) {
352 Py_ssize_t errors_length;
353 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
354 if (errors == NULL) {
355 goto exit;
356 }
357 if (strlen(errors) != (size_t)errors_length) {
358 PyErr_SetString(PyExc_ValueError, "embedded null character");
359 goto exit;
360 }
361 }
362 else {
363 _PyArg_BadArgument("escape_encode", 2, "str or None", args[1]);
364 goto exit;
365 }
366skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300367 return_value = _codecs_escape_encode_impl(module, data, errors);
368
369exit:
370 return return_value;
371}
372
373PyDoc_STRVAR(_codecs_unicode_internal_decode__doc__,
374"unicode_internal_decode($module, obj, errors=None, /)\n"
375"--\n"
376"\n");
377
378#define _CODECS_UNICODE_INTERNAL_DECODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200379 {"unicode_internal_decode", (PyCFunction)(void(*)(void))_codecs_unicode_internal_decode, METH_FASTCALL, _codecs_unicode_internal_decode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300380
381static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300382_codecs_unicode_internal_decode_impl(PyObject *module, PyObject *obj,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300383 const char *errors);
384
385static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200386_codecs_unicode_internal_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300387{
388 PyObject *return_value = NULL;
389 PyObject *obj;
390 const char *errors = NULL;
391
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200392 if (!_PyArg_CheckPositional("unicode_internal_decode", nargs, 1, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100393 goto exit;
394 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200395 obj = args[0];
396 if (nargs < 2) {
397 goto skip_optional;
398 }
399 if (args[1] == Py_None) {
400 errors = NULL;
401 }
402 else if (PyUnicode_Check(args[1])) {
403 Py_ssize_t errors_length;
404 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
405 if (errors == NULL) {
406 goto exit;
407 }
408 if (strlen(errors) != (size_t)errors_length) {
409 PyErr_SetString(PyExc_ValueError, "embedded null character");
410 goto exit;
411 }
412 }
413 else {
414 _PyArg_BadArgument("unicode_internal_decode", 2, "str or None", args[1]);
415 goto exit;
416 }
417skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300418 return_value = _codecs_unicode_internal_decode_impl(module, obj, errors);
419
420exit:
421 return return_value;
422}
423
424PyDoc_STRVAR(_codecs_utf_7_decode__doc__,
425"utf_7_decode($module, data, errors=None, final=False, /)\n"
426"--\n"
427"\n");
428
429#define _CODECS_UTF_7_DECODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200430 {"utf_7_decode", (PyCFunction)(void(*)(void))_codecs_utf_7_decode, METH_FASTCALL, _codecs_utf_7_decode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300431
432static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300433_codecs_utf_7_decode_impl(PyObject *module, Py_buffer *data,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300434 const char *errors, int final);
435
436static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200437_codecs_utf_7_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300438{
439 PyObject *return_value = NULL;
440 Py_buffer data = {NULL, NULL};
441 const char *errors = NULL;
442 int final = 0;
443
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200444 if (!_PyArg_CheckPositional("utf_7_decode", nargs, 1, 3)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100445 goto exit;
446 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200447 if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
448 goto exit;
449 }
450 if (!PyBuffer_IsContiguous(&data, 'C')) {
451 _PyArg_BadArgument("utf_7_decode", 1, "contiguous buffer", args[0]);
452 goto exit;
453 }
454 if (nargs < 2) {
455 goto skip_optional;
456 }
457 if (args[1] == Py_None) {
458 errors = NULL;
459 }
460 else if (PyUnicode_Check(args[1])) {
461 Py_ssize_t errors_length;
462 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
463 if (errors == NULL) {
464 goto exit;
465 }
466 if (strlen(errors) != (size_t)errors_length) {
467 PyErr_SetString(PyExc_ValueError, "embedded null character");
468 goto exit;
469 }
470 }
471 else {
472 _PyArg_BadArgument("utf_7_decode", 2, "str or None", args[1]);
473 goto exit;
474 }
475 if (nargs < 3) {
476 goto skip_optional;
477 }
478 if (PyFloat_Check(args[2])) {
479 PyErr_SetString(PyExc_TypeError,
480 "integer argument expected, got float" );
481 goto exit;
482 }
483 final = _PyLong_AsInt(args[2]);
484 if (final == -1 && PyErr_Occurred()) {
485 goto exit;
486 }
487skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300488 return_value = _codecs_utf_7_decode_impl(module, &data, errors, final);
489
490exit:
491 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300492 if (data.obj) {
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300493 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300494 }
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300495
496 return return_value;
497}
498
499PyDoc_STRVAR(_codecs_utf_8_decode__doc__,
500"utf_8_decode($module, data, errors=None, final=False, /)\n"
501"--\n"
502"\n");
503
504#define _CODECS_UTF_8_DECODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200505 {"utf_8_decode", (PyCFunction)(void(*)(void))_codecs_utf_8_decode, METH_FASTCALL, _codecs_utf_8_decode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300506
507static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300508_codecs_utf_8_decode_impl(PyObject *module, Py_buffer *data,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300509 const char *errors, int final);
510
511static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200512_codecs_utf_8_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300513{
514 PyObject *return_value = NULL;
515 Py_buffer data = {NULL, NULL};
516 const char *errors = NULL;
517 int final = 0;
518
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200519 if (!_PyArg_CheckPositional("utf_8_decode", nargs, 1, 3)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100520 goto exit;
521 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200522 if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
523 goto exit;
524 }
525 if (!PyBuffer_IsContiguous(&data, 'C')) {
526 _PyArg_BadArgument("utf_8_decode", 1, "contiguous buffer", args[0]);
527 goto exit;
528 }
529 if (nargs < 2) {
530 goto skip_optional;
531 }
532 if (args[1] == Py_None) {
533 errors = NULL;
534 }
535 else if (PyUnicode_Check(args[1])) {
536 Py_ssize_t errors_length;
537 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
538 if (errors == NULL) {
539 goto exit;
540 }
541 if (strlen(errors) != (size_t)errors_length) {
542 PyErr_SetString(PyExc_ValueError, "embedded null character");
543 goto exit;
544 }
545 }
546 else {
547 _PyArg_BadArgument("utf_8_decode", 2, "str or None", args[1]);
548 goto exit;
549 }
550 if (nargs < 3) {
551 goto skip_optional;
552 }
553 if (PyFloat_Check(args[2])) {
554 PyErr_SetString(PyExc_TypeError,
555 "integer argument expected, got float" );
556 goto exit;
557 }
558 final = _PyLong_AsInt(args[2]);
559 if (final == -1 && PyErr_Occurred()) {
560 goto exit;
561 }
562skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300563 return_value = _codecs_utf_8_decode_impl(module, &data, errors, final);
564
565exit:
566 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300567 if (data.obj) {
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300568 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300569 }
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300570
571 return return_value;
572}
573
574PyDoc_STRVAR(_codecs_utf_16_decode__doc__,
575"utf_16_decode($module, data, errors=None, final=False, /)\n"
576"--\n"
577"\n");
578
579#define _CODECS_UTF_16_DECODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200580 {"utf_16_decode", (PyCFunction)(void(*)(void))_codecs_utf_16_decode, METH_FASTCALL, _codecs_utf_16_decode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300581
582static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300583_codecs_utf_16_decode_impl(PyObject *module, Py_buffer *data,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300584 const char *errors, int final);
585
586static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200587_codecs_utf_16_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300588{
589 PyObject *return_value = NULL;
590 Py_buffer data = {NULL, NULL};
591 const char *errors = NULL;
592 int final = 0;
593
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200594 if (!_PyArg_CheckPositional("utf_16_decode", nargs, 1, 3)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100595 goto exit;
596 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200597 if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
598 goto exit;
599 }
600 if (!PyBuffer_IsContiguous(&data, 'C')) {
601 _PyArg_BadArgument("utf_16_decode", 1, "contiguous buffer", args[0]);
602 goto exit;
603 }
604 if (nargs < 2) {
605 goto skip_optional;
606 }
607 if (args[1] == Py_None) {
608 errors = NULL;
609 }
610 else if (PyUnicode_Check(args[1])) {
611 Py_ssize_t errors_length;
612 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
613 if (errors == NULL) {
614 goto exit;
615 }
616 if (strlen(errors) != (size_t)errors_length) {
617 PyErr_SetString(PyExc_ValueError, "embedded null character");
618 goto exit;
619 }
620 }
621 else {
622 _PyArg_BadArgument("utf_16_decode", 2, "str or None", args[1]);
623 goto exit;
624 }
625 if (nargs < 3) {
626 goto skip_optional;
627 }
628 if (PyFloat_Check(args[2])) {
629 PyErr_SetString(PyExc_TypeError,
630 "integer argument expected, got float" );
631 goto exit;
632 }
633 final = _PyLong_AsInt(args[2]);
634 if (final == -1 && PyErr_Occurred()) {
635 goto exit;
636 }
637skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300638 return_value = _codecs_utf_16_decode_impl(module, &data, errors, final);
639
640exit:
641 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300642 if (data.obj) {
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300643 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300644 }
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300645
646 return return_value;
647}
648
649PyDoc_STRVAR(_codecs_utf_16_le_decode__doc__,
650"utf_16_le_decode($module, data, errors=None, final=False, /)\n"
651"--\n"
652"\n");
653
654#define _CODECS_UTF_16_LE_DECODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200655 {"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 +0300656
657static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300658_codecs_utf_16_le_decode_impl(PyObject *module, Py_buffer *data,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300659 const char *errors, int final);
660
661static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200662_codecs_utf_16_le_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300663{
664 PyObject *return_value = NULL;
665 Py_buffer data = {NULL, NULL};
666 const char *errors = NULL;
667 int final = 0;
668
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200669 if (!_PyArg_CheckPositional("utf_16_le_decode", nargs, 1, 3)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100670 goto exit;
671 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200672 if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
673 goto exit;
674 }
675 if (!PyBuffer_IsContiguous(&data, 'C')) {
676 _PyArg_BadArgument("utf_16_le_decode", 1, "contiguous buffer", args[0]);
677 goto exit;
678 }
679 if (nargs < 2) {
680 goto skip_optional;
681 }
682 if (args[1] == Py_None) {
683 errors = NULL;
684 }
685 else if (PyUnicode_Check(args[1])) {
686 Py_ssize_t errors_length;
687 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
688 if (errors == NULL) {
689 goto exit;
690 }
691 if (strlen(errors) != (size_t)errors_length) {
692 PyErr_SetString(PyExc_ValueError, "embedded null character");
693 goto exit;
694 }
695 }
696 else {
697 _PyArg_BadArgument("utf_16_le_decode", 2, "str or None", args[1]);
698 goto exit;
699 }
700 if (nargs < 3) {
701 goto skip_optional;
702 }
703 if (PyFloat_Check(args[2])) {
704 PyErr_SetString(PyExc_TypeError,
705 "integer argument expected, got float" );
706 goto exit;
707 }
708 final = _PyLong_AsInt(args[2]);
709 if (final == -1 && PyErr_Occurred()) {
710 goto exit;
711 }
712skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300713 return_value = _codecs_utf_16_le_decode_impl(module, &data, errors, final);
714
715exit:
716 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300717 if (data.obj) {
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300718 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300719 }
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300720
721 return return_value;
722}
723
724PyDoc_STRVAR(_codecs_utf_16_be_decode__doc__,
725"utf_16_be_decode($module, data, errors=None, final=False, /)\n"
726"--\n"
727"\n");
728
729#define _CODECS_UTF_16_BE_DECODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200730 {"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 +0300731
732static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300733_codecs_utf_16_be_decode_impl(PyObject *module, Py_buffer *data,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300734 const char *errors, int final);
735
736static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200737_codecs_utf_16_be_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300738{
739 PyObject *return_value = NULL;
740 Py_buffer data = {NULL, NULL};
741 const char *errors = NULL;
742 int final = 0;
743
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200744 if (!_PyArg_CheckPositional("utf_16_be_decode", nargs, 1, 3)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100745 goto exit;
746 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200747 if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
748 goto exit;
749 }
750 if (!PyBuffer_IsContiguous(&data, 'C')) {
751 _PyArg_BadArgument("utf_16_be_decode", 1, "contiguous buffer", args[0]);
752 goto exit;
753 }
754 if (nargs < 2) {
755 goto skip_optional;
756 }
757 if (args[1] == Py_None) {
758 errors = NULL;
759 }
760 else if (PyUnicode_Check(args[1])) {
761 Py_ssize_t errors_length;
762 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
763 if (errors == NULL) {
764 goto exit;
765 }
766 if (strlen(errors) != (size_t)errors_length) {
767 PyErr_SetString(PyExc_ValueError, "embedded null character");
768 goto exit;
769 }
770 }
771 else {
772 _PyArg_BadArgument("utf_16_be_decode", 2, "str or None", args[1]);
773 goto exit;
774 }
775 if (nargs < 3) {
776 goto skip_optional;
777 }
778 if (PyFloat_Check(args[2])) {
779 PyErr_SetString(PyExc_TypeError,
780 "integer argument expected, got float" );
781 goto exit;
782 }
783 final = _PyLong_AsInt(args[2]);
784 if (final == -1 && PyErr_Occurred()) {
785 goto exit;
786 }
787skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300788 return_value = _codecs_utf_16_be_decode_impl(module, &data, errors, final);
789
790exit:
791 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300792 if (data.obj) {
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300793 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300794 }
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300795
796 return return_value;
797}
798
799PyDoc_STRVAR(_codecs_utf_16_ex_decode__doc__,
800"utf_16_ex_decode($module, data, errors=None, byteorder=0, final=False,\n"
801" /)\n"
802"--\n"
803"\n");
804
805#define _CODECS_UTF_16_EX_DECODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200806 {"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 +0300807
808static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300809_codecs_utf_16_ex_decode_impl(PyObject *module, Py_buffer *data,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300810 const char *errors, int byteorder, int final);
811
812static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200813_codecs_utf_16_ex_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300814{
815 PyObject *return_value = NULL;
816 Py_buffer data = {NULL, NULL};
817 const char *errors = NULL;
818 int byteorder = 0;
819 int final = 0;
820
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200821 if (!_PyArg_CheckPositional("utf_16_ex_decode", nargs, 1, 4)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100822 goto exit;
823 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200824 if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
825 goto exit;
826 }
827 if (!PyBuffer_IsContiguous(&data, 'C')) {
828 _PyArg_BadArgument("utf_16_ex_decode", 1, "contiguous buffer", args[0]);
829 goto exit;
830 }
831 if (nargs < 2) {
832 goto skip_optional;
833 }
834 if (args[1] == Py_None) {
835 errors = NULL;
836 }
837 else if (PyUnicode_Check(args[1])) {
838 Py_ssize_t errors_length;
839 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
840 if (errors == NULL) {
841 goto exit;
842 }
843 if (strlen(errors) != (size_t)errors_length) {
844 PyErr_SetString(PyExc_ValueError, "embedded null character");
845 goto exit;
846 }
847 }
848 else {
849 _PyArg_BadArgument("utf_16_ex_decode", 2, "str or None", args[1]);
850 goto exit;
851 }
852 if (nargs < 3) {
853 goto skip_optional;
854 }
855 if (PyFloat_Check(args[2])) {
856 PyErr_SetString(PyExc_TypeError,
857 "integer argument expected, got float" );
858 goto exit;
859 }
860 byteorder = _PyLong_AsInt(args[2]);
861 if (byteorder == -1 && PyErr_Occurred()) {
862 goto exit;
863 }
864 if (nargs < 4) {
865 goto skip_optional;
866 }
867 if (PyFloat_Check(args[3])) {
868 PyErr_SetString(PyExc_TypeError,
869 "integer argument expected, got float" );
870 goto exit;
871 }
872 final = _PyLong_AsInt(args[3]);
873 if (final == -1 && PyErr_Occurred()) {
874 goto exit;
875 }
876skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300877 return_value = _codecs_utf_16_ex_decode_impl(module, &data, errors, byteorder, final);
878
879exit:
880 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300881 if (data.obj) {
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300882 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300883 }
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300884
885 return return_value;
886}
887
888PyDoc_STRVAR(_codecs_utf_32_decode__doc__,
889"utf_32_decode($module, data, errors=None, final=False, /)\n"
890"--\n"
891"\n");
892
893#define _CODECS_UTF_32_DECODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200894 {"utf_32_decode", (PyCFunction)(void(*)(void))_codecs_utf_32_decode, METH_FASTCALL, _codecs_utf_32_decode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300895
896static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300897_codecs_utf_32_decode_impl(PyObject *module, Py_buffer *data,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300898 const char *errors, int final);
899
900static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200901_codecs_utf_32_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300902{
903 PyObject *return_value = NULL;
904 Py_buffer data = {NULL, NULL};
905 const char *errors = NULL;
906 int final = 0;
907
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200908 if (!_PyArg_CheckPositional("utf_32_decode", nargs, 1, 3)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100909 goto exit;
910 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200911 if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
912 goto exit;
913 }
914 if (!PyBuffer_IsContiguous(&data, 'C')) {
915 _PyArg_BadArgument("utf_32_decode", 1, "contiguous buffer", args[0]);
916 goto exit;
917 }
918 if (nargs < 2) {
919 goto skip_optional;
920 }
921 if (args[1] == Py_None) {
922 errors = NULL;
923 }
924 else if (PyUnicode_Check(args[1])) {
925 Py_ssize_t errors_length;
926 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
927 if (errors == NULL) {
928 goto exit;
929 }
930 if (strlen(errors) != (size_t)errors_length) {
931 PyErr_SetString(PyExc_ValueError, "embedded null character");
932 goto exit;
933 }
934 }
935 else {
936 _PyArg_BadArgument("utf_32_decode", 2, "str or None", args[1]);
937 goto exit;
938 }
939 if (nargs < 3) {
940 goto skip_optional;
941 }
942 if (PyFloat_Check(args[2])) {
943 PyErr_SetString(PyExc_TypeError,
944 "integer argument expected, got float" );
945 goto exit;
946 }
947 final = _PyLong_AsInt(args[2]);
948 if (final == -1 && PyErr_Occurred()) {
949 goto exit;
950 }
951skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300952 return_value = _codecs_utf_32_decode_impl(module, &data, errors, final);
953
954exit:
955 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300956 if (data.obj) {
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300957 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300958 }
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300959
960 return return_value;
961}
962
963PyDoc_STRVAR(_codecs_utf_32_le_decode__doc__,
964"utf_32_le_decode($module, data, errors=None, final=False, /)\n"
965"--\n"
966"\n");
967
968#define _CODECS_UTF_32_LE_DECODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200969 {"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 +0300970
971static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300972_codecs_utf_32_le_decode_impl(PyObject *module, Py_buffer *data,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300973 const char *errors, int final);
974
975static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200976_codecs_utf_32_le_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +0300977{
978 PyObject *return_value = NULL;
979 Py_buffer data = {NULL, NULL};
980 const char *errors = NULL;
981 int final = 0;
982
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200983 if (!_PyArg_CheckPositional("utf_32_le_decode", nargs, 1, 3)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100984 goto exit;
985 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +0200986 if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
987 goto exit;
988 }
989 if (!PyBuffer_IsContiguous(&data, 'C')) {
990 _PyArg_BadArgument("utf_32_le_decode", 1, "contiguous buffer", args[0]);
991 goto exit;
992 }
993 if (nargs < 2) {
994 goto skip_optional;
995 }
996 if (args[1] == Py_None) {
997 errors = NULL;
998 }
999 else if (PyUnicode_Check(args[1])) {
1000 Py_ssize_t errors_length;
1001 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
1002 if (errors == NULL) {
1003 goto exit;
1004 }
1005 if (strlen(errors) != (size_t)errors_length) {
1006 PyErr_SetString(PyExc_ValueError, "embedded null character");
1007 goto exit;
1008 }
1009 }
1010 else {
1011 _PyArg_BadArgument("utf_32_le_decode", 2, "str or None", args[1]);
1012 goto exit;
1013 }
1014 if (nargs < 3) {
1015 goto skip_optional;
1016 }
1017 if (PyFloat_Check(args[2])) {
1018 PyErr_SetString(PyExc_TypeError,
1019 "integer argument expected, got float" );
1020 goto exit;
1021 }
1022 final = _PyLong_AsInt(args[2]);
1023 if (final == -1 && PyErr_Occurred()) {
1024 goto exit;
1025 }
1026skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001027 return_value = _codecs_utf_32_le_decode_impl(module, &data, errors, final);
1028
1029exit:
1030 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001031 if (data.obj) {
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001032 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001033 }
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001034
1035 return return_value;
1036}
1037
1038PyDoc_STRVAR(_codecs_utf_32_be_decode__doc__,
1039"utf_32_be_decode($module, data, errors=None, final=False, /)\n"
1040"--\n"
1041"\n");
1042
1043#define _CODECS_UTF_32_BE_DECODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001044 {"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 +03001045
1046static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001047_codecs_utf_32_be_decode_impl(PyObject *module, Py_buffer *data,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001048 const char *errors, int final);
1049
1050static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001051_codecs_utf_32_be_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001052{
1053 PyObject *return_value = NULL;
1054 Py_buffer data = {NULL, NULL};
1055 const char *errors = NULL;
1056 int final = 0;
1057
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001058 if (!_PyArg_CheckPositional("utf_32_be_decode", nargs, 1, 3)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01001059 goto exit;
1060 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001061 if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
1062 goto exit;
1063 }
1064 if (!PyBuffer_IsContiguous(&data, 'C')) {
1065 _PyArg_BadArgument("utf_32_be_decode", 1, "contiguous buffer", args[0]);
1066 goto exit;
1067 }
1068 if (nargs < 2) {
1069 goto skip_optional;
1070 }
1071 if (args[1] == Py_None) {
1072 errors = NULL;
1073 }
1074 else if (PyUnicode_Check(args[1])) {
1075 Py_ssize_t errors_length;
1076 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
1077 if (errors == NULL) {
1078 goto exit;
1079 }
1080 if (strlen(errors) != (size_t)errors_length) {
1081 PyErr_SetString(PyExc_ValueError, "embedded null character");
1082 goto exit;
1083 }
1084 }
1085 else {
1086 _PyArg_BadArgument("utf_32_be_decode", 2, "str or None", args[1]);
1087 goto exit;
1088 }
1089 if (nargs < 3) {
1090 goto skip_optional;
1091 }
1092 if (PyFloat_Check(args[2])) {
1093 PyErr_SetString(PyExc_TypeError,
1094 "integer argument expected, got float" );
1095 goto exit;
1096 }
1097 final = _PyLong_AsInt(args[2]);
1098 if (final == -1 && PyErr_Occurred()) {
1099 goto exit;
1100 }
1101skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001102 return_value = _codecs_utf_32_be_decode_impl(module, &data, errors, final);
1103
1104exit:
1105 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001106 if (data.obj) {
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001107 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001108 }
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001109
1110 return return_value;
1111}
1112
1113PyDoc_STRVAR(_codecs_utf_32_ex_decode__doc__,
1114"utf_32_ex_decode($module, data, errors=None, byteorder=0, final=False,\n"
1115" /)\n"
1116"--\n"
1117"\n");
1118
1119#define _CODECS_UTF_32_EX_DECODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001120 {"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 +03001121
1122static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001123_codecs_utf_32_ex_decode_impl(PyObject *module, Py_buffer *data,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001124 const char *errors, int byteorder, int final);
1125
1126static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001127_codecs_utf_32_ex_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001128{
1129 PyObject *return_value = NULL;
1130 Py_buffer data = {NULL, NULL};
1131 const char *errors = NULL;
1132 int byteorder = 0;
1133 int final = 0;
1134
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001135 if (!_PyArg_CheckPositional("utf_32_ex_decode", nargs, 1, 4)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01001136 goto exit;
1137 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001138 if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
1139 goto exit;
1140 }
1141 if (!PyBuffer_IsContiguous(&data, 'C')) {
1142 _PyArg_BadArgument("utf_32_ex_decode", 1, "contiguous buffer", args[0]);
1143 goto exit;
1144 }
1145 if (nargs < 2) {
1146 goto skip_optional;
1147 }
1148 if (args[1] == Py_None) {
1149 errors = NULL;
1150 }
1151 else if (PyUnicode_Check(args[1])) {
1152 Py_ssize_t errors_length;
1153 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
1154 if (errors == NULL) {
1155 goto exit;
1156 }
1157 if (strlen(errors) != (size_t)errors_length) {
1158 PyErr_SetString(PyExc_ValueError, "embedded null character");
1159 goto exit;
1160 }
1161 }
1162 else {
1163 _PyArg_BadArgument("utf_32_ex_decode", 2, "str or None", args[1]);
1164 goto exit;
1165 }
1166 if (nargs < 3) {
1167 goto skip_optional;
1168 }
1169 if (PyFloat_Check(args[2])) {
1170 PyErr_SetString(PyExc_TypeError,
1171 "integer argument expected, got float" );
1172 goto exit;
1173 }
1174 byteorder = _PyLong_AsInt(args[2]);
1175 if (byteorder == -1 && PyErr_Occurred()) {
1176 goto exit;
1177 }
1178 if (nargs < 4) {
1179 goto skip_optional;
1180 }
1181 if (PyFloat_Check(args[3])) {
1182 PyErr_SetString(PyExc_TypeError,
1183 "integer argument expected, got float" );
1184 goto exit;
1185 }
1186 final = _PyLong_AsInt(args[3]);
1187 if (final == -1 && PyErr_Occurred()) {
1188 goto exit;
1189 }
1190skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001191 return_value = _codecs_utf_32_ex_decode_impl(module, &data, errors, byteorder, final);
1192
1193exit:
1194 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001195 if (data.obj) {
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001196 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001197 }
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001198
1199 return return_value;
1200}
1201
1202PyDoc_STRVAR(_codecs_unicode_escape_decode__doc__,
1203"unicode_escape_decode($module, data, errors=None, /)\n"
1204"--\n"
1205"\n");
1206
1207#define _CODECS_UNICODE_ESCAPE_DECODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001208 {"unicode_escape_decode", (PyCFunction)(void(*)(void))_codecs_unicode_escape_decode, METH_FASTCALL, _codecs_unicode_escape_decode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001209
1210static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001211_codecs_unicode_escape_decode_impl(PyObject *module, Py_buffer *data,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001212 const char *errors);
1213
1214static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001215_codecs_unicode_escape_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001216{
1217 PyObject *return_value = NULL;
1218 Py_buffer data = {NULL, NULL};
1219 const char *errors = NULL;
1220
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001221 if (!_PyArg_CheckPositional("unicode_escape_decode", nargs, 1, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01001222 goto exit;
1223 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001224 if (PyUnicode_Check(args[0])) {
1225 Py_ssize_t len;
1226 const char *ptr = PyUnicode_AsUTF8AndSize(args[0], &len);
1227 if (ptr == NULL) {
1228 goto exit;
1229 }
1230 PyBuffer_FillInfo(&data, args[0], (void *)ptr, len, 1, 0);
1231 }
1232 else { /* any bytes-like object */
1233 if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
1234 goto exit;
1235 }
1236 if (!PyBuffer_IsContiguous(&data, 'C')) {
1237 _PyArg_BadArgument("unicode_escape_decode", 1, "contiguous buffer", args[0]);
1238 goto exit;
1239 }
1240 }
1241 if (nargs < 2) {
1242 goto skip_optional;
1243 }
1244 if (args[1] == Py_None) {
1245 errors = NULL;
1246 }
1247 else if (PyUnicode_Check(args[1])) {
1248 Py_ssize_t errors_length;
1249 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
1250 if (errors == NULL) {
1251 goto exit;
1252 }
1253 if (strlen(errors) != (size_t)errors_length) {
1254 PyErr_SetString(PyExc_ValueError, "embedded null character");
1255 goto exit;
1256 }
1257 }
1258 else {
1259 _PyArg_BadArgument("unicode_escape_decode", 2, "str or None", args[1]);
1260 goto exit;
1261 }
1262skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001263 return_value = _codecs_unicode_escape_decode_impl(module, &data, errors);
1264
1265exit:
1266 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001267 if (data.obj) {
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001268 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001269 }
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001270
1271 return return_value;
1272}
1273
1274PyDoc_STRVAR(_codecs_raw_unicode_escape_decode__doc__,
1275"raw_unicode_escape_decode($module, data, errors=None, /)\n"
1276"--\n"
1277"\n");
1278
1279#define _CODECS_RAW_UNICODE_ESCAPE_DECODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001280 {"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 +03001281
1282static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001283_codecs_raw_unicode_escape_decode_impl(PyObject *module, Py_buffer *data,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001284 const char *errors);
1285
1286static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001287_codecs_raw_unicode_escape_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001288{
1289 PyObject *return_value = NULL;
1290 Py_buffer data = {NULL, NULL};
1291 const char *errors = NULL;
1292
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001293 if (!_PyArg_CheckPositional("raw_unicode_escape_decode", nargs, 1, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01001294 goto exit;
1295 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001296 if (PyUnicode_Check(args[0])) {
1297 Py_ssize_t len;
1298 const char *ptr = PyUnicode_AsUTF8AndSize(args[0], &len);
1299 if (ptr == NULL) {
1300 goto exit;
1301 }
1302 PyBuffer_FillInfo(&data, args[0], (void *)ptr, len, 1, 0);
1303 }
1304 else { /* any bytes-like object */
1305 if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
1306 goto exit;
1307 }
1308 if (!PyBuffer_IsContiguous(&data, 'C')) {
1309 _PyArg_BadArgument("raw_unicode_escape_decode", 1, "contiguous buffer", args[0]);
1310 goto exit;
1311 }
1312 }
1313 if (nargs < 2) {
1314 goto skip_optional;
1315 }
1316 if (args[1] == Py_None) {
1317 errors = NULL;
1318 }
1319 else if (PyUnicode_Check(args[1])) {
1320 Py_ssize_t errors_length;
1321 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
1322 if (errors == NULL) {
1323 goto exit;
1324 }
1325 if (strlen(errors) != (size_t)errors_length) {
1326 PyErr_SetString(PyExc_ValueError, "embedded null character");
1327 goto exit;
1328 }
1329 }
1330 else {
1331 _PyArg_BadArgument("raw_unicode_escape_decode", 2, "str or None", args[1]);
1332 goto exit;
1333 }
1334skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001335 return_value = _codecs_raw_unicode_escape_decode_impl(module, &data, errors);
1336
1337exit:
1338 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001339 if (data.obj) {
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001340 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001341 }
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001342
1343 return return_value;
1344}
1345
1346PyDoc_STRVAR(_codecs_latin_1_decode__doc__,
1347"latin_1_decode($module, data, errors=None, /)\n"
1348"--\n"
1349"\n");
1350
1351#define _CODECS_LATIN_1_DECODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001352 {"latin_1_decode", (PyCFunction)(void(*)(void))_codecs_latin_1_decode, METH_FASTCALL, _codecs_latin_1_decode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001353
1354static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001355_codecs_latin_1_decode_impl(PyObject *module, Py_buffer *data,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001356 const char *errors);
1357
1358static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001359_codecs_latin_1_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001360{
1361 PyObject *return_value = NULL;
1362 Py_buffer data = {NULL, NULL};
1363 const char *errors = NULL;
1364
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001365 if (!_PyArg_CheckPositional("latin_1_decode", nargs, 1, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01001366 goto exit;
1367 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001368 if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
1369 goto exit;
1370 }
1371 if (!PyBuffer_IsContiguous(&data, 'C')) {
1372 _PyArg_BadArgument("latin_1_decode", 1, "contiguous buffer", args[0]);
1373 goto exit;
1374 }
1375 if (nargs < 2) {
1376 goto skip_optional;
1377 }
1378 if (args[1] == Py_None) {
1379 errors = NULL;
1380 }
1381 else if (PyUnicode_Check(args[1])) {
1382 Py_ssize_t errors_length;
1383 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
1384 if (errors == NULL) {
1385 goto exit;
1386 }
1387 if (strlen(errors) != (size_t)errors_length) {
1388 PyErr_SetString(PyExc_ValueError, "embedded null character");
1389 goto exit;
1390 }
1391 }
1392 else {
1393 _PyArg_BadArgument("latin_1_decode", 2, "str or None", args[1]);
1394 goto exit;
1395 }
1396skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001397 return_value = _codecs_latin_1_decode_impl(module, &data, errors);
1398
1399exit:
1400 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001401 if (data.obj) {
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001402 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001403 }
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001404
1405 return return_value;
1406}
1407
1408PyDoc_STRVAR(_codecs_ascii_decode__doc__,
1409"ascii_decode($module, data, errors=None, /)\n"
1410"--\n"
1411"\n");
1412
1413#define _CODECS_ASCII_DECODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001414 {"ascii_decode", (PyCFunction)(void(*)(void))_codecs_ascii_decode, METH_FASTCALL, _codecs_ascii_decode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001415
1416static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001417_codecs_ascii_decode_impl(PyObject *module, Py_buffer *data,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001418 const char *errors);
1419
1420static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001421_codecs_ascii_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001422{
1423 PyObject *return_value = NULL;
1424 Py_buffer data = {NULL, NULL};
1425 const char *errors = NULL;
1426
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001427 if (!_PyArg_CheckPositional("ascii_decode", nargs, 1, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01001428 goto exit;
1429 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001430 if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
1431 goto exit;
1432 }
1433 if (!PyBuffer_IsContiguous(&data, 'C')) {
1434 _PyArg_BadArgument("ascii_decode", 1, "contiguous buffer", args[0]);
1435 goto exit;
1436 }
1437 if (nargs < 2) {
1438 goto skip_optional;
1439 }
1440 if (args[1] == Py_None) {
1441 errors = NULL;
1442 }
1443 else if (PyUnicode_Check(args[1])) {
1444 Py_ssize_t errors_length;
1445 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
1446 if (errors == NULL) {
1447 goto exit;
1448 }
1449 if (strlen(errors) != (size_t)errors_length) {
1450 PyErr_SetString(PyExc_ValueError, "embedded null character");
1451 goto exit;
1452 }
1453 }
1454 else {
1455 _PyArg_BadArgument("ascii_decode", 2, "str or None", args[1]);
1456 goto exit;
1457 }
1458skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001459 return_value = _codecs_ascii_decode_impl(module, &data, errors);
1460
1461exit:
1462 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001463 if (data.obj) {
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001464 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001465 }
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001466
1467 return return_value;
1468}
1469
1470PyDoc_STRVAR(_codecs_charmap_decode__doc__,
1471"charmap_decode($module, data, errors=None, mapping=None, /)\n"
1472"--\n"
1473"\n");
1474
1475#define _CODECS_CHARMAP_DECODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001476 {"charmap_decode", (PyCFunction)(void(*)(void))_codecs_charmap_decode, METH_FASTCALL, _codecs_charmap_decode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001477
1478static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001479_codecs_charmap_decode_impl(PyObject *module, Py_buffer *data,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001480 const char *errors, PyObject *mapping);
1481
1482static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001483_codecs_charmap_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001484{
1485 PyObject *return_value = NULL;
1486 Py_buffer data = {NULL, NULL};
1487 const char *errors = NULL;
1488 PyObject *mapping = NULL;
1489
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001490 if (!_PyArg_CheckPositional("charmap_decode", nargs, 1, 3)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01001491 goto exit;
1492 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001493 if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
1494 goto exit;
1495 }
1496 if (!PyBuffer_IsContiguous(&data, 'C')) {
1497 _PyArg_BadArgument("charmap_decode", 1, "contiguous buffer", args[0]);
1498 goto exit;
1499 }
1500 if (nargs < 2) {
1501 goto skip_optional;
1502 }
1503 if (args[1] == Py_None) {
1504 errors = NULL;
1505 }
1506 else if (PyUnicode_Check(args[1])) {
1507 Py_ssize_t errors_length;
1508 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
1509 if (errors == NULL) {
1510 goto exit;
1511 }
1512 if (strlen(errors) != (size_t)errors_length) {
1513 PyErr_SetString(PyExc_ValueError, "embedded null character");
1514 goto exit;
1515 }
1516 }
1517 else {
1518 _PyArg_BadArgument("charmap_decode", 2, "str or None", args[1]);
1519 goto exit;
1520 }
1521 if (nargs < 3) {
1522 goto skip_optional;
1523 }
1524 mapping = args[2];
1525skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001526 return_value = _codecs_charmap_decode_impl(module, &data, errors, mapping);
1527
1528exit:
1529 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001530 if (data.obj) {
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001531 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001532 }
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001533
1534 return return_value;
1535}
1536
Steve Dowercc16be82016-09-08 10:35:16 -07001537#if defined(MS_WINDOWS)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001538
1539PyDoc_STRVAR(_codecs_mbcs_decode__doc__,
1540"mbcs_decode($module, data, errors=None, final=False, /)\n"
1541"--\n"
1542"\n");
1543
1544#define _CODECS_MBCS_DECODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001545 {"mbcs_decode", (PyCFunction)(void(*)(void))_codecs_mbcs_decode, METH_FASTCALL, _codecs_mbcs_decode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001546
1547static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001548_codecs_mbcs_decode_impl(PyObject *module, Py_buffer *data,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001549 const char *errors, int final);
1550
1551static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001552_codecs_mbcs_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001553{
1554 PyObject *return_value = NULL;
1555 Py_buffer data = {NULL, NULL};
1556 const char *errors = NULL;
1557 int final = 0;
1558
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001559 if (!_PyArg_CheckPositional("mbcs_decode", nargs, 1, 3)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01001560 goto exit;
1561 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001562 if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
1563 goto exit;
1564 }
1565 if (!PyBuffer_IsContiguous(&data, 'C')) {
1566 _PyArg_BadArgument("mbcs_decode", 1, "contiguous buffer", args[0]);
1567 goto exit;
1568 }
1569 if (nargs < 2) {
1570 goto skip_optional;
1571 }
1572 if (args[1] == Py_None) {
1573 errors = NULL;
1574 }
1575 else if (PyUnicode_Check(args[1])) {
1576 Py_ssize_t errors_length;
1577 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
1578 if (errors == NULL) {
1579 goto exit;
1580 }
1581 if (strlen(errors) != (size_t)errors_length) {
1582 PyErr_SetString(PyExc_ValueError, "embedded null character");
1583 goto exit;
1584 }
1585 }
1586 else {
1587 _PyArg_BadArgument("mbcs_decode", 2, "str or None", args[1]);
1588 goto exit;
1589 }
1590 if (nargs < 3) {
1591 goto skip_optional;
1592 }
1593 if (PyFloat_Check(args[2])) {
1594 PyErr_SetString(PyExc_TypeError,
1595 "integer argument expected, got float" );
1596 goto exit;
1597 }
1598 final = _PyLong_AsInt(args[2]);
1599 if (final == -1 && PyErr_Occurred()) {
1600 goto exit;
1601 }
1602skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001603 return_value = _codecs_mbcs_decode_impl(module, &data, errors, final);
1604
1605exit:
1606 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001607 if (data.obj) {
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001608 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001609 }
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001610
1611 return return_value;
1612}
1613
Steve Dowercc16be82016-09-08 10:35:16 -07001614#endif /* defined(MS_WINDOWS) */
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001615
Steve Dowercc16be82016-09-08 10:35:16 -07001616#if defined(MS_WINDOWS)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001617
Steve Dowerf5aba582016-09-06 19:42:27 -07001618PyDoc_STRVAR(_codecs_oem_decode__doc__,
1619"oem_decode($module, data, errors=None, final=False, /)\n"
1620"--\n"
1621"\n");
1622
1623#define _CODECS_OEM_DECODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001624 {"oem_decode", (PyCFunction)(void(*)(void))_codecs_oem_decode, METH_FASTCALL, _codecs_oem_decode__doc__},
Steve Dowerf5aba582016-09-06 19:42:27 -07001625
1626static PyObject *
1627_codecs_oem_decode_impl(PyObject *module, Py_buffer *data,
1628 const char *errors, int final);
1629
1630static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001631_codecs_oem_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Steve Dowerf5aba582016-09-06 19:42:27 -07001632{
1633 PyObject *return_value = NULL;
1634 Py_buffer data = {NULL, NULL};
1635 const char *errors = NULL;
1636 int final = 0;
1637
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001638 if (!_PyArg_CheckPositional("oem_decode", nargs, 1, 3)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01001639 goto exit;
1640 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001641 if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
1642 goto exit;
1643 }
1644 if (!PyBuffer_IsContiguous(&data, 'C')) {
1645 _PyArg_BadArgument("oem_decode", 1, "contiguous buffer", args[0]);
1646 goto exit;
1647 }
1648 if (nargs < 2) {
1649 goto skip_optional;
1650 }
1651 if (args[1] == Py_None) {
1652 errors = NULL;
1653 }
1654 else if (PyUnicode_Check(args[1])) {
1655 Py_ssize_t errors_length;
1656 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
1657 if (errors == NULL) {
1658 goto exit;
1659 }
1660 if (strlen(errors) != (size_t)errors_length) {
1661 PyErr_SetString(PyExc_ValueError, "embedded null character");
1662 goto exit;
1663 }
1664 }
1665 else {
1666 _PyArg_BadArgument("oem_decode", 2, "str or None", args[1]);
1667 goto exit;
1668 }
1669 if (nargs < 3) {
1670 goto skip_optional;
1671 }
1672 if (PyFloat_Check(args[2])) {
1673 PyErr_SetString(PyExc_TypeError,
1674 "integer argument expected, got float" );
1675 goto exit;
1676 }
1677 final = _PyLong_AsInt(args[2]);
1678 if (final == -1 && PyErr_Occurred()) {
1679 goto exit;
1680 }
1681skip_optional:
Steve Dowerf5aba582016-09-06 19:42:27 -07001682 return_value = _codecs_oem_decode_impl(module, &data, errors, final);
1683
1684exit:
1685 /* Cleanup for data */
1686 if (data.obj) {
1687 PyBuffer_Release(&data);
1688 }
1689
1690 return return_value;
1691}
1692
Steve Dowercc16be82016-09-08 10:35:16 -07001693#endif /* defined(MS_WINDOWS) */
Steve Dowerf5aba582016-09-06 19:42:27 -07001694
Steve Dowercc16be82016-09-08 10:35:16 -07001695#if defined(MS_WINDOWS)
Steve Dowerf5aba582016-09-06 19:42:27 -07001696
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001697PyDoc_STRVAR(_codecs_code_page_decode__doc__,
1698"code_page_decode($module, codepage, data, errors=None, final=False, /)\n"
1699"--\n"
1700"\n");
1701
1702#define _CODECS_CODE_PAGE_DECODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001703 {"code_page_decode", (PyCFunction)(void(*)(void))_codecs_code_page_decode, METH_FASTCALL, _codecs_code_page_decode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001704
1705static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001706_codecs_code_page_decode_impl(PyObject *module, int codepage,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001707 Py_buffer *data, const char *errors, int final);
1708
1709static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001710_codecs_code_page_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001711{
1712 PyObject *return_value = NULL;
1713 int codepage;
1714 Py_buffer data = {NULL, NULL};
1715 const char *errors = NULL;
1716 int final = 0;
1717
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001718 if (!_PyArg_CheckPositional("code_page_decode", nargs, 2, 4)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01001719 goto exit;
1720 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001721 if (PyFloat_Check(args[0])) {
1722 PyErr_SetString(PyExc_TypeError,
1723 "integer argument expected, got float" );
1724 goto exit;
1725 }
1726 codepage = _PyLong_AsInt(args[0]);
1727 if (codepage == -1 && PyErr_Occurred()) {
1728 goto exit;
1729 }
1730 if (PyObject_GetBuffer(args[1], &data, PyBUF_SIMPLE) != 0) {
1731 goto exit;
1732 }
1733 if (!PyBuffer_IsContiguous(&data, 'C')) {
1734 _PyArg_BadArgument("code_page_decode", 2, "contiguous buffer", args[1]);
1735 goto exit;
1736 }
1737 if (nargs < 3) {
1738 goto skip_optional;
1739 }
1740 if (args[2] == Py_None) {
1741 errors = NULL;
1742 }
1743 else if (PyUnicode_Check(args[2])) {
1744 Py_ssize_t errors_length;
1745 errors = PyUnicode_AsUTF8AndSize(args[2], &errors_length);
1746 if (errors == NULL) {
1747 goto exit;
1748 }
1749 if (strlen(errors) != (size_t)errors_length) {
1750 PyErr_SetString(PyExc_ValueError, "embedded null character");
1751 goto exit;
1752 }
1753 }
1754 else {
1755 _PyArg_BadArgument("code_page_decode", 3, "str or None", args[2]);
1756 goto exit;
1757 }
1758 if (nargs < 4) {
1759 goto skip_optional;
1760 }
1761 if (PyFloat_Check(args[3])) {
1762 PyErr_SetString(PyExc_TypeError,
1763 "integer argument expected, got float" );
1764 goto exit;
1765 }
1766 final = _PyLong_AsInt(args[3]);
1767 if (final == -1 && PyErr_Occurred()) {
1768 goto exit;
1769 }
1770skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001771 return_value = _codecs_code_page_decode_impl(module, codepage, &data, errors, final);
1772
1773exit:
1774 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001775 if (data.obj) {
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001776 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001777 }
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001778
1779 return return_value;
1780}
1781
Steve Dowercc16be82016-09-08 10:35:16 -07001782#endif /* defined(MS_WINDOWS) */
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001783
1784PyDoc_STRVAR(_codecs_readbuffer_encode__doc__,
1785"readbuffer_encode($module, data, errors=None, /)\n"
1786"--\n"
1787"\n");
1788
1789#define _CODECS_READBUFFER_ENCODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001790 {"readbuffer_encode", (PyCFunction)(void(*)(void))_codecs_readbuffer_encode, METH_FASTCALL, _codecs_readbuffer_encode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001791
1792static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001793_codecs_readbuffer_encode_impl(PyObject *module, Py_buffer *data,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001794 const char *errors);
1795
1796static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001797_codecs_readbuffer_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001798{
1799 PyObject *return_value = NULL;
1800 Py_buffer data = {NULL, NULL};
1801 const char *errors = NULL;
1802
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001803 if (!_PyArg_CheckPositional("readbuffer_encode", nargs, 1, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01001804 goto exit;
1805 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001806 if (PyUnicode_Check(args[0])) {
1807 Py_ssize_t len;
1808 const char *ptr = PyUnicode_AsUTF8AndSize(args[0], &len);
1809 if (ptr == NULL) {
1810 goto exit;
1811 }
1812 PyBuffer_FillInfo(&data, args[0], (void *)ptr, len, 1, 0);
1813 }
1814 else { /* any bytes-like object */
1815 if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
1816 goto exit;
1817 }
1818 if (!PyBuffer_IsContiguous(&data, 'C')) {
1819 _PyArg_BadArgument("readbuffer_encode", 1, "contiguous buffer", args[0]);
1820 goto exit;
1821 }
1822 }
1823 if (nargs < 2) {
1824 goto skip_optional;
1825 }
1826 if (args[1] == Py_None) {
1827 errors = NULL;
1828 }
1829 else if (PyUnicode_Check(args[1])) {
1830 Py_ssize_t errors_length;
1831 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
1832 if (errors == NULL) {
1833 goto exit;
1834 }
1835 if (strlen(errors) != (size_t)errors_length) {
1836 PyErr_SetString(PyExc_ValueError, "embedded null character");
1837 goto exit;
1838 }
1839 }
1840 else {
1841 _PyArg_BadArgument("readbuffer_encode", 2, "str or None", args[1]);
1842 goto exit;
1843 }
1844skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001845 return_value = _codecs_readbuffer_encode_impl(module, &data, errors);
1846
1847exit:
1848 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001849 if (data.obj) {
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001850 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001851 }
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001852
1853 return return_value;
1854}
1855
1856PyDoc_STRVAR(_codecs_unicode_internal_encode__doc__,
1857"unicode_internal_encode($module, obj, errors=None, /)\n"
1858"--\n"
1859"\n");
1860
1861#define _CODECS_UNICODE_INTERNAL_ENCODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001862 {"unicode_internal_encode", (PyCFunction)(void(*)(void))_codecs_unicode_internal_encode, METH_FASTCALL, _codecs_unicode_internal_encode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001863
1864static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001865_codecs_unicode_internal_encode_impl(PyObject *module, PyObject *obj,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001866 const char *errors);
1867
1868static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001869_codecs_unicode_internal_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001870{
1871 PyObject *return_value = NULL;
1872 PyObject *obj;
1873 const char *errors = NULL;
1874
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001875 if (!_PyArg_CheckPositional("unicode_internal_encode", nargs, 1, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01001876 goto exit;
1877 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001878 obj = args[0];
1879 if (nargs < 2) {
1880 goto skip_optional;
1881 }
1882 if (args[1] == Py_None) {
1883 errors = NULL;
1884 }
1885 else if (PyUnicode_Check(args[1])) {
1886 Py_ssize_t errors_length;
1887 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
1888 if (errors == NULL) {
1889 goto exit;
1890 }
1891 if (strlen(errors) != (size_t)errors_length) {
1892 PyErr_SetString(PyExc_ValueError, "embedded null character");
1893 goto exit;
1894 }
1895 }
1896 else {
1897 _PyArg_BadArgument("unicode_internal_encode", 2, "str or None", args[1]);
1898 goto exit;
1899 }
1900skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001901 return_value = _codecs_unicode_internal_encode_impl(module, obj, errors);
1902
1903exit:
1904 return return_value;
1905}
1906
1907PyDoc_STRVAR(_codecs_utf_7_encode__doc__,
1908"utf_7_encode($module, str, errors=None, /)\n"
1909"--\n"
1910"\n");
1911
1912#define _CODECS_UTF_7_ENCODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001913 {"utf_7_encode", (PyCFunction)(void(*)(void))_codecs_utf_7_encode, METH_FASTCALL, _codecs_utf_7_encode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001914
1915static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001916_codecs_utf_7_encode_impl(PyObject *module, PyObject *str,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001917 const char *errors);
1918
1919static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001920_codecs_utf_7_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001921{
1922 PyObject *return_value = NULL;
1923 PyObject *str;
1924 const char *errors = NULL;
1925
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001926 if (!_PyArg_CheckPositional("utf_7_encode", nargs, 1, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01001927 goto exit;
1928 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001929 if (!PyUnicode_Check(args[0])) {
1930 _PyArg_BadArgument("utf_7_encode", 1, "str", args[0]);
1931 goto exit;
1932 }
1933 if (PyUnicode_READY(args[0]) == -1) {
1934 goto exit;
1935 }
1936 str = args[0];
1937 if (nargs < 2) {
1938 goto skip_optional;
1939 }
1940 if (args[1] == Py_None) {
1941 errors = NULL;
1942 }
1943 else if (PyUnicode_Check(args[1])) {
1944 Py_ssize_t errors_length;
1945 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
1946 if (errors == NULL) {
1947 goto exit;
1948 }
1949 if (strlen(errors) != (size_t)errors_length) {
1950 PyErr_SetString(PyExc_ValueError, "embedded null character");
1951 goto exit;
1952 }
1953 }
1954 else {
1955 _PyArg_BadArgument("utf_7_encode", 2, "str or None", args[1]);
1956 goto exit;
1957 }
1958skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001959 return_value = _codecs_utf_7_encode_impl(module, str, errors);
1960
1961exit:
1962 return return_value;
1963}
1964
1965PyDoc_STRVAR(_codecs_utf_8_encode__doc__,
1966"utf_8_encode($module, str, errors=None, /)\n"
1967"--\n"
1968"\n");
1969
1970#define _CODECS_UTF_8_ENCODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001971 {"utf_8_encode", (PyCFunction)(void(*)(void))_codecs_utf_8_encode, METH_FASTCALL, _codecs_utf_8_encode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001972
1973static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03001974_codecs_utf_8_encode_impl(PyObject *module, PyObject *str,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001975 const char *errors);
1976
1977static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001978_codecs_utf_8_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03001979{
1980 PyObject *return_value = NULL;
1981 PyObject *str;
1982 const char *errors = NULL;
1983
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001984 if (!_PyArg_CheckPositional("utf_8_encode", nargs, 1, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01001985 goto exit;
1986 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02001987 if (!PyUnicode_Check(args[0])) {
1988 _PyArg_BadArgument("utf_8_encode", 1, "str", args[0]);
1989 goto exit;
1990 }
1991 if (PyUnicode_READY(args[0]) == -1) {
1992 goto exit;
1993 }
1994 str = args[0];
1995 if (nargs < 2) {
1996 goto skip_optional;
1997 }
1998 if (args[1] == Py_None) {
1999 errors = NULL;
2000 }
2001 else if (PyUnicode_Check(args[1])) {
2002 Py_ssize_t errors_length;
2003 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
2004 if (errors == NULL) {
2005 goto exit;
2006 }
2007 if (strlen(errors) != (size_t)errors_length) {
2008 PyErr_SetString(PyExc_ValueError, "embedded null character");
2009 goto exit;
2010 }
2011 }
2012 else {
2013 _PyArg_BadArgument("utf_8_encode", 2, "str or None", args[1]);
2014 goto exit;
2015 }
2016skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002017 return_value = _codecs_utf_8_encode_impl(module, str, errors);
2018
2019exit:
2020 return return_value;
2021}
2022
2023PyDoc_STRVAR(_codecs_utf_16_encode__doc__,
2024"utf_16_encode($module, str, errors=None, byteorder=0, /)\n"
2025"--\n"
2026"\n");
2027
2028#define _CODECS_UTF_16_ENCODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002029 {"utf_16_encode", (PyCFunction)(void(*)(void))_codecs_utf_16_encode, METH_FASTCALL, _codecs_utf_16_encode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002030
2031static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002032_codecs_utf_16_encode_impl(PyObject *module, PyObject *str,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002033 const char *errors, int byteorder);
2034
2035static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002036_codecs_utf_16_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002037{
2038 PyObject *return_value = NULL;
2039 PyObject *str;
2040 const char *errors = NULL;
2041 int byteorder = 0;
2042
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002043 if (!_PyArg_CheckPositional("utf_16_encode", nargs, 1, 3)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002044 goto exit;
2045 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002046 if (!PyUnicode_Check(args[0])) {
2047 _PyArg_BadArgument("utf_16_encode", 1, "str", args[0]);
2048 goto exit;
2049 }
2050 if (PyUnicode_READY(args[0]) == -1) {
2051 goto exit;
2052 }
2053 str = args[0];
2054 if (nargs < 2) {
2055 goto skip_optional;
2056 }
2057 if (args[1] == Py_None) {
2058 errors = NULL;
2059 }
2060 else if (PyUnicode_Check(args[1])) {
2061 Py_ssize_t errors_length;
2062 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
2063 if (errors == NULL) {
2064 goto exit;
2065 }
2066 if (strlen(errors) != (size_t)errors_length) {
2067 PyErr_SetString(PyExc_ValueError, "embedded null character");
2068 goto exit;
2069 }
2070 }
2071 else {
2072 _PyArg_BadArgument("utf_16_encode", 2, "str or None", args[1]);
2073 goto exit;
2074 }
2075 if (nargs < 3) {
2076 goto skip_optional;
2077 }
2078 if (PyFloat_Check(args[2])) {
2079 PyErr_SetString(PyExc_TypeError,
2080 "integer argument expected, got float" );
2081 goto exit;
2082 }
2083 byteorder = _PyLong_AsInt(args[2]);
2084 if (byteorder == -1 && PyErr_Occurred()) {
2085 goto exit;
2086 }
2087skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002088 return_value = _codecs_utf_16_encode_impl(module, str, errors, byteorder);
2089
2090exit:
2091 return return_value;
2092}
2093
2094PyDoc_STRVAR(_codecs_utf_16_le_encode__doc__,
2095"utf_16_le_encode($module, str, errors=None, /)\n"
2096"--\n"
2097"\n");
2098
2099#define _CODECS_UTF_16_LE_ENCODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002100 {"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 +03002101
2102static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002103_codecs_utf_16_le_encode_impl(PyObject *module, PyObject *str,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002104 const char *errors);
2105
2106static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002107_codecs_utf_16_le_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002108{
2109 PyObject *return_value = NULL;
2110 PyObject *str;
2111 const char *errors = NULL;
2112
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002113 if (!_PyArg_CheckPositional("utf_16_le_encode", nargs, 1, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002114 goto exit;
2115 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002116 if (!PyUnicode_Check(args[0])) {
2117 _PyArg_BadArgument("utf_16_le_encode", 1, "str", args[0]);
2118 goto exit;
2119 }
2120 if (PyUnicode_READY(args[0]) == -1) {
2121 goto exit;
2122 }
2123 str = args[0];
2124 if (nargs < 2) {
2125 goto skip_optional;
2126 }
2127 if (args[1] == Py_None) {
2128 errors = NULL;
2129 }
2130 else if (PyUnicode_Check(args[1])) {
2131 Py_ssize_t errors_length;
2132 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
2133 if (errors == NULL) {
2134 goto exit;
2135 }
2136 if (strlen(errors) != (size_t)errors_length) {
2137 PyErr_SetString(PyExc_ValueError, "embedded null character");
2138 goto exit;
2139 }
2140 }
2141 else {
2142 _PyArg_BadArgument("utf_16_le_encode", 2, "str or None", args[1]);
2143 goto exit;
2144 }
2145skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002146 return_value = _codecs_utf_16_le_encode_impl(module, str, errors);
2147
2148exit:
2149 return return_value;
2150}
2151
2152PyDoc_STRVAR(_codecs_utf_16_be_encode__doc__,
2153"utf_16_be_encode($module, str, errors=None, /)\n"
2154"--\n"
2155"\n");
2156
2157#define _CODECS_UTF_16_BE_ENCODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002158 {"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 +03002159
2160static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002161_codecs_utf_16_be_encode_impl(PyObject *module, PyObject *str,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002162 const char *errors);
2163
2164static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002165_codecs_utf_16_be_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002166{
2167 PyObject *return_value = NULL;
2168 PyObject *str;
2169 const char *errors = NULL;
2170
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002171 if (!_PyArg_CheckPositional("utf_16_be_encode", nargs, 1, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002172 goto exit;
2173 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002174 if (!PyUnicode_Check(args[0])) {
2175 _PyArg_BadArgument("utf_16_be_encode", 1, "str", args[0]);
2176 goto exit;
2177 }
2178 if (PyUnicode_READY(args[0]) == -1) {
2179 goto exit;
2180 }
2181 str = args[0];
2182 if (nargs < 2) {
2183 goto skip_optional;
2184 }
2185 if (args[1] == Py_None) {
2186 errors = NULL;
2187 }
2188 else if (PyUnicode_Check(args[1])) {
2189 Py_ssize_t errors_length;
2190 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
2191 if (errors == NULL) {
2192 goto exit;
2193 }
2194 if (strlen(errors) != (size_t)errors_length) {
2195 PyErr_SetString(PyExc_ValueError, "embedded null character");
2196 goto exit;
2197 }
2198 }
2199 else {
2200 _PyArg_BadArgument("utf_16_be_encode", 2, "str or None", args[1]);
2201 goto exit;
2202 }
2203skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002204 return_value = _codecs_utf_16_be_encode_impl(module, str, errors);
2205
2206exit:
2207 return return_value;
2208}
2209
2210PyDoc_STRVAR(_codecs_utf_32_encode__doc__,
2211"utf_32_encode($module, str, errors=None, byteorder=0, /)\n"
2212"--\n"
2213"\n");
2214
2215#define _CODECS_UTF_32_ENCODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002216 {"utf_32_encode", (PyCFunction)(void(*)(void))_codecs_utf_32_encode, METH_FASTCALL, _codecs_utf_32_encode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002217
2218static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002219_codecs_utf_32_encode_impl(PyObject *module, PyObject *str,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002220 const char *errors, int byteorder);
2221
2222static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002223_codecs_utf_32_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002224{
2225 PyObject *return_value = NULL;
2226 PyObject *str;
2227 const char *errors = NULL;
2228 int byteorder = 0;
2229
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002230 if (!_PyArg_CheckPositional("utf_32_encode", nargs, 1, 3)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002231 goto exit;
2232 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002233 if (!PyUnicode_Check(args[0])) {
2234 _PyArg_BadArgument("utf_32_encode", 1, "str", args[0]);
2235 goto exit;
2236 }
2237 if (PyUnicode_READY(args[0]) == -1) {
2238 goto exit;
2239 }
2240 str = args[0];
2241 if (nargs < 2) {
2242 goto skip_optional;
2243 }
2244 if (args[1] == Py_None) {
2245 errors = NULL;
2246 }
2247 else if (PyUnicode_Check(args[1])) {
2248 Py_ssize_t errors_length;
2249 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
2250 if (errors == NULL) {
2251 goto exit;
2252 }
2253 if (strlen(errors) != (size_t)errors_length) {
2254 PyErr_SetString(PyExc_ValueError, "embedded null character");
2255 goto exit;
2256 }
2257 }
2258 else {
2259 _PyArg_BadArgument("utf_32_encode", 2, "str or None", args[1]);
2260 goto exit;
2261 }
2262 if (nargs < 3) {
2263 goto skip_optional;
2264 }
2265 if (PyFloat_Check(args[2])) {
2266 PyErr_SetString(PyExc_TypeError,
2267 "integer argument expected, got float" );
2268 goto exit;
2269 }
2270 byteorder = _PyLong_AsInt(args[2]);
2271 if (byteorder == -1 && PyErr_Occurred()) {
2272 goto exit;
2273 }
2274skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002275 return_value = _codecs_utf_32_encode_impl(module, str, errors, byteorder);
2276
2277exit:
2278 return return_value;
2279}
2280
2281PyDoc_STRVAR(_codecs_utf_32_le_encode__doc__,
2282"utf_32_le_encode($module, str, errors=None, /)\n"
2283"--\n"
2284"\n");
2285
2286#define _CODECS_UTF_32_LE_ENCODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002287 {"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 +03002288
2289static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002290_codecs_utf_32_le_encode_impl(PyObject *module, PyObject *str,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002291 const char *errors);
2292
2293static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002294_codecs_utf_32_le_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002295{
2296 PyObject *return_value = NULL;
2297 PyObject *str;
2298 const char *errors = NULL;
2299
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002300 if (!_PyArg_CheckPositional("utf_32_le_encode", nargs, 1, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002301 goto exit;
2302 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002303 if (!PyUnicode_Check(args[0])) {
2304 _PyArg_BadArgument("utf_32_le_encode", 1, "str", args[0]);
2305 goto exit;
2306 }
2307 if (PyUnicode_READY(args[0]) == -1) {
2308 goto exit;
2309 }
2310 str = args[0];
2311 if (nargs < 2) {
2312 goto skip_optional;
2313 }
2314 if (args[1] == Py_None) {
2315 errors = NULL;
2316 }
2317 else if (PyUnicode_Check(args[1])) {
2318 Py_ssize_t errors_length;
2319 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
2320 if (errors == NULL) {
2321 goto exit;
2322 }
2323 if (strlen(errors) != (size_t)errors_length) {
2324 PyErr_SetString(PyExc_ValueError, "embedded null character");
2325 goto exit;
2326 }
2327 }
2328 else {
2329 _PyArg_BadArgument("utf_32_le_encode", 2, "str or None", args[1]);
2330 goto exit;
2331 }
2332skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002333 return_value = _codecs_utf_32_le_encode_impl(module, str, errors);
2334
2335exit:
2336 return return_value;
2337}
2338
2339PyDoc_STRVAR(_codecs_utf_32_be_encode__doc__,
2340"utf_32_be_encode($module, str, errors=None, /)\n"
2341"--\n"
2342"\n");
2343
2344#define _CODECS_UTF_32_BE_ENCODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002345 {"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 +03002346
2347static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002348_codecs_utf_32_be_encode_impl(PyObject *module, PyObject *str,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002349 const char *errors);
2350
2351static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002352_codecs_utf_32_be_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002353{
2354 PyObject *return_value = NULL;
2355 PyObject *str;
2356 const char *errors = NULL;
2357
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002358 if (!_PyArg_CheckPositional("utf_32_be_encode", nargs, 1, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002359 goto exit;
2360 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002361 if (!PyUnicode_Check(args[0])) {
2362 _PyArg_BadArgument("utf_32_be_encode", 1, "str", args[0]);
2363 goto exit;
2364 }
2365 if (PyUnicode_READY(args[0]) == -1) {
2366 goto exit;
2367 }
2368 str = args[0];
2369 if (nargs < 2) {
2370 goto skip_optional;
2371 }
2372 if (args[1] == Py_None) {
2373 errors = NULL;
2374 }
2375 else if (PyUnicode_Check(args[1])) {
2376 Py_ssize_t errors_length;
2377 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
2378 if (errors == NULL) {
2379 goto exit;
2380 }
2381 if (strlen(errors) != (size_t)errors_length) {
2382 PyErr_SetString(PyExc_ValueError, "embedded null character");
2383 goto exit;
2384 }
2385 }
2386 else {
2387 _PyArg_BadArgument("utf_32_be_encode", 2, "str or None", args[1]);
2388 goto exit;
2389 }
2390skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002391 return_value = _codecs_utf_32_be_encode_impl(module, str, errors);
2392
2393exit:
2394 return return_value;
2395}
2396
2397PyDoc_STRVAR(_codecs_unicode_escape_encode__doc__,
2398"unicode_escape_encode($module, str, errors=None, /)\n"
2399"--\n"
2400"\n");
2401
2402#define _CODECS_UNICODE_ESCAPE_ENCODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002403 {"unicode_escape_encode", (PyCFunction)(void(*)(void))_codecs_unicode_escape_encode, METH_FASTCALL, _codecs_unicode_escape_encode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002404
2405static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002406_codecs_unicode_escape_encode_impl(PyObject *module, PyObject *str,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002407 const char *errors);
2408
2409static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002410_codecs_unicode_escape_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002411{
2412 PyObject *return_value = NULL;
2413 PyObject *str;
2414 const char *errors = NULL;
2415
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002416 if (!_PyArg_CheckPositional("unicode_escape_encode", nargs, 1, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002417 goto exit;
2418 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002419 if (!PyUnicode_Check(args[0])) {
2420 _PyArg_BadArgument("unicode_escape_encode", 1, "str", args[0]);
2421 goto exit;
2422 }
2423 if (PyUnicode_READY(args[0]) == -1) {
2424 goto exit;
2425 }
2426 str = args[0];
2427 if (nargs < 2) {
2428 goto skip_optional;
2429 }
2430 if (args[1] == Py_None) {
2431 errors = NULL;
2432 }
2433 else if (PyUnicode_Check(args[1])) {
2434 Py_ssize_t errors_length;
2435 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
2436 if (errors == NULL) {
2437 goto exit;
2438 }
2439 if (strlen(errors) != (size_t)errors_length) {
2440 PyErr_SetString(PyExc_ValueError, "embedded null character");
2441 goto exit;
2442 }
2443 }
2444 else {
2445 _PyArg_BadArgument("unicode_escape_encode", 2, "str or None", args[1]);
2446 goto exit;
2447 }
2448skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002449 return_value = _codecs_unicode_escape_encode_impl(module, str, errors);
2450
2451exit:
2452 return return_value;
2453}
2454
2455PyDoc_STRVAR(_codecs_raw_unicode_escape_encode__doc__,
2456"raw_unicode_escape_encode($module, str, errors=None, /)\n"
2457"--\n"
2458"\n");
2459
2460#define _CODECS_RAW_UNICODE_ESCAPE_ENCODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002461 {"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 +03002462
2463static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002464_codecs_raw_unicode_escape_encode_impl(PyObject *module, PyObject *str,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002465 const char *errors);
2466
2467static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002468_codecs_raw_unicode_escape_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002469{
2470 PyObject *return_value = NULL;
2471 PyObject *str;
2472 const char *errors = NULL;
2473
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002474 if (!_PyArg_CheckPositional("raw_unicode_escape_encode", nargs, 1, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002475 goto exit;
2476 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002477 if (!PyUnicode_Check(args[0])) {
2478 _PyArg_BadArgument("raw_unicode_escape_encode", 1, "str", args[0]);
2479 goto exit;
2480 }
2481 if (PyUnicode_READY(args[0]) == -1) {
2482 goto exit;
2483 }
2484 str = args[0];
2485 if (nargs < 2) {
2486 goto skip_optional;
2487 }
2488 if (args[1] == Py_None) {
2489 errors = NULL;
2490 }
2491 else if (PyUnicode_Check(args[1])) {
2492 Py_ssize_t errors_length;
2493 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
2494 if (errors == NULL) {
2495 goto exit;
2496 }
2497 if (strlen(errors) != (size_t)errors_length) {
2498 PyErr_SetString(PyExc_ValueError, "embedded null character");
2499 goto exit;
2500 }
2501 }
2502 else {
2503 _PyArg_BadArgument("raw_unicode_escape_encode", 2, "str or None", args[1]);
2504 goto exit;
2505 }
2506skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002507 return_value = _codecs_raw_unicode_escape_encode_impl(module, str, errors);
2508
2509exit:
2510 return return_value;
2511}
2512
2513PyDoc_STRVAR(_codecs_latin_1_encode__doc__,
2514"latin_1_encode($module, str, errors=None, /)\n"
2515"--\n"
2516"\n");
2517
2518#define _CODECS_LATIN_1_ENCODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002519 {"latin_1_encode", (PyCFunction)(void(*)(void))_codecs_latin_1_encode, METH_FASTCALL, _codecs_latin_1_encode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002520
2521static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002522_codecs_latin_1_encode_impl(PyObject *module, PyObject *str,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002523 const char *errors);
2524
2525static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002526_codecs_latin_1_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002527{
2528 PyObject *return_value = NULL;
2529 PyObject *str;
2530 const char *errors = NULL;
2531
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002532 if (!_PyArg_CheckPositional("latin_1_encode", nargs, 1, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002533 goto exit;
2534 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002535 if (!PyUnicode_Check(args[0])) {
2536 _PyArg_BadArgument("latin_1_encode", 1, "str", args[0]);
2537 goto exit;
2538 }
2539 if (PyUnicode_READY(args[0]) == -1) {
2540 goto exit;
2541 }
2542 str = args[0];
2543 if (nargs < 2) {
2544 goto skip_optional;
2545 }
2546 if (args[1] == Py_None) {
2547 errors = NULL;
2548 }
2549 else if (PyUnicode_Check(args[1])) {
2550 Py_ssize_t errors_length;
2551 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
2552 if (errors == NULL) {
2553 goto exit;
2554 }
2555 if (strlen(errors) != (size_t)errors_length) {
2556 PyErr_SetString(PyExc_ValueError, "embedded null character");
2557 goto exit;
2558 }
2559 }
2560 else {
2561 _PyArg_BadArgument("latin_1_encode", 2, "str or None", args[1]);
2562 goto exit;
2563 }
2564skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002565 return_value = _codecs_latin_1_encode_impl(module, str, errors);
2566
2567exit:
2568 return return_value;
2569}
2570
2571PyDoc_STRVAR(_codecs_ascii_encode__doc__,
2572"ascii_encode($module, str, errors=None, /)\n"
2573"--\n"
2574"\n");
2575
2576#define _CODECS_ASCII_ENCODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002577 {"ascii_encode", (PyCFunction)(void(*)(void))_codecs_ascii_encode, METH_FASTCALL, _codecs_ascii_encode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002578
2579static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002580_codecs_ascii_encode_impl(PyObject *module, PyObject *str,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002581 const char *errors);
2582
2583static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002584_codecs_ascii_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002585{
2586 PyObject *return_value = NULL;
2587 PyObject *str;
2588 const char *errors = NULL;
2589
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002590 if (!_PyArg_CheckPositional("ascii_encode", nargs, 1, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002591 goto exit;
2592 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002593 if (!PyUnicode_Check(args[0])) {
2594 _PyArg_BadArgument("ascii_encode", 1, "str", args[0]);
2595 goto exit;
2596 }
2597 if (PyUnicode_READY(args[0]) == -1) {
2598 goto exit;
2599 }
2600 str = args[0];
2601 if (nargs < 2) {
2602 goto skip_optional;
2603 }
2604 if (args[1] == Py_None) {
2605 errors = NULL;
2606 }
2607 else if (PyUnicode_Check(args[1])) {
2608 Py_ssize_t errors_length;
2609 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
2610 if (errors == NULL) {
2611 goto exit;
2612 }
2613 if (strlen(errors) != (size_t)errors_length) {
2614 PyErr_SetString(PyExc_ValueError, "embedded null character");
2615 goto exit;
2616 }
2617 }
2618 else {
2619 _PyArg_BadArgument("ascii_encode", 2, "str or None", args[1]);
2620 goto exit;
2621 }
2622skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002623 return_value = _codecs_ascii_encode_impl(module, str, errors);
2624
2625exit:
2626 return return_value;
2627}
2628
2629PyDoc_STRVAR(_codecs_charmap_encode__doc__,
2630"charmap_encode($module, str, errors=None, mapping=None, /)\n"
2631"--\n"
2632"\n");
2633
2634#define _CODECS_CHARMAP_ENCODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002635 {"charmap_encode", (PyCFunction)(void(*)(void))_codecs_charmap_encode, METH_FASTCALL, _codecs_charmap_encode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002636
2637static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002638_codecs_charmap_encode_impl(PyObject *module, PyObject *str,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002639 const char *errors, PyObject *mapping);
2640
2641static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002642_codecs_charmap_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002643{
2644 PyObject *return_value = NULL;
2645 PyObject *str;
2646 const char *errors = NULL;
2647 PyObject *mapping = NULL;
2648
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002649 if (!_PyArg_CheckPositional("charmap_encode", nargs, 1, 3)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002650 goto exit;
2651 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002652 if (!PyUnicode_Check(args[0])) {
2653 _PyArg_BadArgument("charmap_encode", 1, "str", args[0]);
2654 goto exit;
2655 }
2656 if (PyUnicode_READY(args[0]) == -1) {
2657 goto exit;
2658 }
2659 str = args[0];
2660 if (nargs < 2) {
2661 goto skip_optional;
2662 }
2663 if (args[1] == Py_None) {
2664 errors = NULL;
2665 }
2666 else if (PyUnicode_Check(args[1])) {
2667 Py_ssize_t errors_length;
2668 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
2669 if (errors == NULL) {
2670 goto exit;
2671 }
2672 if (strlen(errors) != (size_t)errors_length) {
2673 PyErr_SetString(PyExc_ValueError, "embedded null character");
2674 goto exit;
2675 }
2676 }
2677 else {
2678 _PyArg_BadArgument("charmap_encode", 2, "str or None", args[1]);
2679 goto exit;
2680 }
2681 if (nargs < 3) {
2682 goto skip_optional;
2683 }
2684 mapping = args[2];
2685skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002686 return_value = _codecs_charmap_encode_impl(module, str, errors, mapping);
2687
2688exit:
2689 return return_value;
2690}
2691
2692PyDoc_STRVAR(_codecs_charmap_build__doc__,
2693"charmap_build($module, map, /)\n"
2694"--\n"
2695"\n");
2696
2697#define _CODECS_CHARMAP_BUILD_METHODDEF \
2698 {"charmap_build", (PyCFunction)_codecs_charmap_build, METH_O, _codecs_charmap_build__doc__},
2699
2700static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002701_codecs_charmap_build_impl(PyObject *module, PyObject *map);
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002702
2703static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002704_codecs_charmap_build(PyObject *module, PyObject *arg)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002705{
2706 PyObject *return_value = NULL;
2707 PyObject *map;
2708
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02002709 if (!PyUnicode_Check(arg)) {
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002710 _PyArg_BadArgument("charmap_build", 0, "str", arg);
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002711 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002712 }
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02002713 if (PyUnicode_READY(arg) == -1) {
2714 goto exit;
2715 }
2716 map = arg;
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002717 return_value = _codecs_charmap_build_impl(module, map);
2718
2719exit:
2720 return return_value;
2721}
2722
Steve Dowercc16be82016-09-08 10:35:16 -07002723#if defined(MS_WINDOWS)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002724
2725PyDoc_STRVAR(_codecs_mbcs_encode__doc__,
2726"mbcs_encode($module, str, errors=None, /)\n"
2727"--\n"
2728"\n");
2729
2730#define _CODECS_MBCS_ENCODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002731 {"mbcs_encode", (PyCFunction)(void(*)(void))_codecs_mbcs_encode, METH_FASTCALL, _codecs_mbcs_encode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002732
2733static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002734_codecs_mbcs_encode_impl(PyObject *module, PyObject *str, const char *errors);
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002735
2736static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002737_codecs_mbcs_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002738{
2739 PyObject *return_value = NULL;
2740 PyObject *str;
2741 const char *errors = NULL;
2742
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002743 if (!_PyArg_CheckPositional("mbcs_encode", nargs, 1, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002744 goto exit;
2745 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002746 if (!PyUnicode_Check(args[0])) {
2747 _PyArg_BadArgument("mbcs_encode", 1, "str", args[0]);
2748 goto exit;
2749 }
2750 if (PyUnicode_READY(args[0]) == -1) {
2751 goto exit;
2752 }
2753 str = args[0];
2754 if (nargs < 2) {
2755 goto skip_optional;
2756 }
2757 if (args[1] == Py_None) {
2758 errors = NULL;
2759 }
2760 else if (PyUnicode_Check(args[1])) {
2761 Py_ssize_t errors_length;
2762 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
2763 if (errors == NULL) {
2764 goto exit;
2765 }
2766 if (strlen(errors) != (size_t)errors_length) {
2767 PyErr_SetString(PyExc_ValueError, "embedded null character");
2768 goto exit;
2769 }
2770 }
2771 else {
2772 _PyArg_BadArgument("mbcs_encode", 2, "str or None", args[1]);
2773 goto exit;
2774 }
2775skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002776 return_value = _codecs_mbcs_encode_impl(module, str, errors);
2777
2778exit:
2779 return return_value;
2780}
2781
Steve Dowercc16be82016-09-08 10:35:16 -07002782#endif /* defined(MS_WINDOWS) */
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002783
Steve Dowercc16be82016-09-08 10:35:16 -07002784#if defined(MS_WINDOWS)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002785
Steve Dowerf5aba582016-09-06 19:42:27 -07002786PyDoc_STRVAR(_codecs_oem_encode__doc__,
2787"oem_encode($module, str, errors=None, /)\n"
2788"--\n"
2789"\n");
2790
2791#define _CODECS_OEM_ENCODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002792 {"oem_encode", (PyCFunction)(void(*)(void))_codecs_oem_encode, METH_FASTCALL, _codecs_oem_encode__doc__},
Steve Dowerf5aba582016-09-06 19:42:27 -07002793
2794static PyObject *
2795_codecs_oem_encode_impl(PyObject *module, PyObject *str, const char *errors);
2796
2797static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002798_codecs_oem_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Steve Dowerf5aba582016-09-06 19:42:27 -07002799{
2800 PyObject *return_value = NULL;
2801 PyObject *str;
2802 const char *errors = NULL;
2803
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002804 if (!_PyArg_CheckPositional("oem_encode", nargs, 1, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002805 goto exit;
2806 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002807 if (!PyUnicode_Check(args[0])) {
2808 _PyArg_BadArgument("oem_encode", 1, "str", args[0]);
2809 goto exit;
2810 }
2811 if (PyUnicode_READY(args[0]) == -1) {
2812 goto exit;
2813 }
2814 str = args[0];
2815 if (nargs < 2) {
2816 goto skip_optional;
2817 }
2818 if (args[1] == Py_None) {
2819 errors = NULL;
2820 }
2821 else if (PyUnicode_Check(args[1])) {
2822 Py_ssize_t errors_length;
2823 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
2824 if (errors == NULL) {
2825 goto exit;
2826 }
2827 if (strlen(errors) != (size_t)errors_length) {
2828 PyErr_SetString(PyExc_ValueError, "embedded null character");
2829 goto exit;
2830 }
2831 }
2832 else {
2833 _PyArg_BadArgument("oem_encode", 2, "str or None", args[1]);
2834 goto exit;
2835 }
2836skip_optional:
Steve Dowerf5aba582016-09-06 19:42:27 -07002837 return_value = _codecs_oem_encode_impl(module, str, errors);
2838
2839exit:
2840 return return_value;
2841}
2842
Steve Dowercc16be82016-09-08 10:35:16 -07002843#endif /* defined(MS_WINDOWS) */
Steve Dowerf5aba582016-09-06 19:42:27 -07002844
Steve Dowercc16be82016-09-08 10:35:16 -07002845#if defined(MS_WINDOWS)
Steve Dowerf5aba582016-09-06 19:42:27 -07002846
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002847PyDoc_STRVAR(_codecs_code_page_encode__doc__,
2848"code_page_encode($module, code_page, str, errors=None, /)\n"
2849"--\n"
2850"\n");
2851
2852#define _CODECS_CODE_PAGE_ENCODE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002853 {"code_page_encode", (PyCFunction)(void(*)(void))_codecs_code_page_encode, METH_FASTCALL, _codecs_code_page_encode__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002854
2855static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002856_codecs_code_page_encode_impl(PyObject *module, int code_page, PyObject *str,
2857 const char *errors);
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002858
2859static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002860_codecs_code_page_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002861{
2862 PyObject *return_value = NULL;
2863 int code_page;
2864 PyObject *str;
2865 const char *errors = NULL;
2866
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002867 if (!_PyArg_CheckPositional("code_page_encode", nargs, 2, 3)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002868 goto exit;
2869 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002870 if (PyFloat_Check(args[0])) {
2871 PyErr_SetString(PyExc_TypeError,
2872 "integer argument expected, got float" );
2873 goto exit;
2874 }
2875 code_page = _PyLong_AsInt(args[0]);
2876 if (code_page == -1 && PyErr_Occurred()) {
2877 goto exit;
2878 }
2879 if (!PyUnicode_Check(args[1])) {
2880 _PyArg_BadArgument("code_page_encode", 2, "str", args[1]);
2881 goto exit;
2882 }
2883 if (PyUnicode_READY(args[1]) == -1) {
2884 goto exit;
2885 }
2886 str = args[1];
2887 if (nargs < 3) {
2888 goto skip_optional;
2889 }
2890 if (args[2] == Py_None) {
2891 errors = NULL;
2892 }
2893 else if (PyUnicode_Check(args[2])) {
2894 Py_ssize_t errors_length;
2895 errors = PyUnicode_AsUTF8AndSize(args[2], &errors_length);
2896 if (errors == NULL) {
2897 goto exit;
2898 }
2899 if (strlen(errors) != (size_t)errors_length) {
2900 PyErr_SetString(PyExc_ValueError, "embedded null character");
2901 goto exit;
2902 }
2903 }
2904 else {
2905 _PyArg_BadArgument("code_page_encode", 3, "str or None", args[2]);
2906 goto exit;
2907 }
2908skip_optional:
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002909 return_value = _codecs_code_page_encode_impl(module, code_page, str, errors);
2910
2911exit:
2912 return return_value;
2913}
2914
Steve Dowercc16be82016-09-08 10:35:16 -07002915#endif /* defined(MS_WINDOWS) */
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002916
2917PyDoc_STRVAR(_codecs_register_error__doc__,
2918"register_error($module, errors, handler, /)\n"
2919"--\n"
2920"\n"
2921"Register the specified error handler under the name errors.\n"
2922"\n"
2923"handler must be a callable object, that will be called with an exception\n"
2924"instance containing information about the location of the encoding/decoding\n"
2925"error and must return a (replacement, new position) tuple.");
2926
2927#define _CODECS_REGISTER_ERROR_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02002928 {"register_error", (PyCFunction)(void(*)(void))_codecs_register_error, METH_FASTCALL, _codecs_register_error__doc__},
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002929
2930static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002931_codecs_register_error_impl(PyObject *module, const char *errors,
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002932 PyObject *handler);
2933
2934static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02002935_codecs_register_error(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002936{
2937 PyObject *return_value = NULL;
2938 const char *errors;
2939 PyObject *handler;
2940
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002941 if (!_PyArg_CheckPositional("register_error", nargs, 2, 2)) {
Victor Stinner259f0e42017-01-17 01:35:17 +01002942 goto exit;
2943 }
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002944 if (!PyUnicode_Check(args[0])) {
2945 _PyArg_BadArgument("register_error", 1, "str", args[0]);
2946 goto exit;
2947 }
2948 Py_ssize_t errors_length;
2949 errors = PyUnicode_AsUTF8AndSize(args[0], &errors_length);
2950 if (errors == NULL) {
2951 goto exit;
2952 }
2953 if (strlen(errors) != (size_t)errors_length) {
2954 PyErr_SetString(PyExc_ValueError, "embedded null character");
2955 goto exit;
2956 }
2957 handler = args[1];
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002958 return_value = _codecs_register_error_impl(module, errors, handler);
2959
2960exit:
2961 return return_value;
2962}
2963
2964PyDoc_STRVAR(_codecs_lookup_error__doc__,
2965"lookup_error($module, name, /)\n"
2966"--\n"
2967"\n"
2968"lookup_error(errors) -> handler\n"
2969"\n"
2970"Return the error handler for the specified error handling name or raise a\n"
2971"LookupError, if no handler exists under this name.");
2972
2973#define _CODECS_LOOKUP_ERROR_METHODDEF \
2974 {"lookup_error", (PyCFunction)_codecs_lookup_error, METH_O, _codecs_lookup_error__doc__},
2975
2976static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002977_codecs_lookup_error_impl(PyObject *module, const char *name);
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002978
2979static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +03002980_codecs_lookup_error(PyObject *module, PyObject *arg)
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002981{
2982 PyObject *return_value = NULL;
2983 const char *name;
2984
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02002985 if (!PyUnicode_Check(arg)) {
Serhiy Storchaka4fa95912019-01-11 16:01:14 +02002986 _PyArg_BadArgument("lookup_error", 0, "str", arg);
Serhiy Storchaka32d96a22018-12-25 13:23:47 +02002987 goto exit;
2988 }
2989 Py_ssize_t name_length;
2990 name = PyUnicode_AsUTF8AndSize(arg, &name_length);
2991 if (name == NULL) {
2992 goto exit;
2993 }
2994 if (strlen(name) != (size_t)name_length) {
2995 PyErr_SetString(PyExc_ValueError, "embedded null character");
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002996 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03002997 }
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03002998 return_value = _codecs_lookup_error_impl(module, name);
2999
3000exit:
3001 return return_value;
3002}
3003
3004#ifndef _CODECS_MBCS_DECODE_METHODDEF
3005 #define _CODECS_MBCS_DECODE_METHODDEF
3006#endif /* !defined(_CODECS_MBCS_DECODE_METHODDEF) */
3007
Steve Dowerf5aba582016-09-06 19:42:27 -07003008#ifndef _CODECS_OEM_DECODE_METHODDEF
3009 #define _CODECS_OEM_DECODE_METHODDEF
3010#endif /* !defined(_CODECS_OEM_DECODE_METHODDEF) */
3011
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03003012#ifndef _CODECS_CODE_PAGE_DECODE_METHODDEF
3013 #define _CODECS_CODE_PAGE_DECODE_METHODDEF
3014#endif /* !defined(_CODECS_CODE_PAGE_DECODE_METHODDEF) */
3015
3016#ifndef _CODECS_MBCS_ENCODE_METHODDEF
3017 #define _CODECS_MBCS_ENCODE_METHODDEF
3018#endif /* !defined(_CODECS_MBCS_ENCODE_METHODDEF) */
3019
Steve Dowerf5aba582016-09-06 19:42:27 -07003020#ifndef _CODECS_OEM_ENCODE_METHODDEF
3021 #define _CODECS_OEM_ENCODE_METHODDEF
3022#endif /* !defined(_CODECS_OEM_ENCODE_METHODDEF) */
3023
Serhiy Storchaka0c59ff62015-05-12 13:15:57 +03003024#ifndef _CODECS_CODE_PAGE_ENCODE_METHODDEF
3025 #define _CODECS_CODE_PAGE_ENCODE_METHODDEF
3026#endif /* !defined(_CODECS_CODE_PAGE_ENCODE_METHODDEF) */
Serhiy Storchaka31913912019-03-14 10:32:22 +02003027/*[clinic end generated code: output=02bd0f0cf9a28150 input=a9049054013a1b77]*/