• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*[clinic input]
2 preserve
3 [clinic start generated code]*/
4 
5 PyDoc_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 
18 PyDoc_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 
27 static PyObject *
28 _codecs_lookup_impl(PyObject *module, const char *encoding);
29 
30 static PyObject *
_codecs_lookup(PyObject * module,PyObject * arg)31 _codecs_lookup(PyObject *module, PyObject *arg)
32 {
33     PyObject *return_value = NULL;
34     const char *encoding;
35 
36     if (!PyUnicode_Check(arg)) {
37         _PyArg_BadArgument("lookup", "argument", "str", arg);
38         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");
47         goto exit;
48     }
49     return_value = _codecs_lookup_impl(module, encoding);
50 
51 exit:
52     return return_value;
53 }
54 
55 PyDoc_STRVAR(_codecs_encode__doc__,
56 "encode($module, /, obj, encoding=\'utf-8\', errors=\'strict\')\n"
57 "--\n"
58 "\n"
59 "Encodes obj using the codec registered for encoding.\n"
60 "\n"
61 "The default encoding is \'utf-8\'.  errors may be given to set a\n"
62 "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    \
68     {"encode", (PyCFunction)(void(*)(void))_codecs_encode, METH_FASTCALL|METH_KEYWORDS, _codecs_encode__doc__},
69 
70 static PyObject *
71 _codecs_encode_impl(PyObject *module, PyObject *obj, const char *encoding,
72                     const char *errors);
73 
74 static PyObject *
_codecs_encode(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)75 _codecs_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
76 {
77     PyObject *return_value = NULL;
78     static const char * const _keywords[] = {"obj", "encoding", "errors", NULL};
79     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;
82     PyObject *obj;
83     const char *encoding = NULL;
84     const char *errors = NULL;
85 
86     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 3, 0, argsbuf);
87     if (!args) {
88         goto exit;
89     }
90     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", "argument 'encoding'", "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", "argument 'errors'", "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     }
125 skip_optional_pos:
126     return_value = _codecs_encode_impl(module, obj, encoding, errors);
127 
128 exit:
129     return return_value;
130 }
131 
132 PyDoc_STRVAR(_codecs_decode__doc__,
133 "decode($module, /, obj, encoding=\'utf-8\', errors=\'strict\')\n"
134 "--\n"
135 "\n"
136 "Decodes obj using the codec registered for encoding.\n"
137 "\n"
138 "Default encoding is \'utf-8\'.  errors may be given to set a\n"
139 "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    \
145     {"decode", (PyCFunction)(void(*)(void))_codecs_decode, METH_FASTCALL|METH_KEYWORDS, _codecs_decode__doc__},
146 
147 static PyObject *
148 _codecs_decode_impl(PyObject *module, PyObject *obj, const char *encoding,
149                     const char *errors);
150 
151 static PyObject *
_codecs_decode(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)152 _codecs_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
153 {
154     PyObject *return_value = NULL;
155     static const char * const _keywords[] = {"obj", "encoding", "errors", NULL};
156     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;
159     PyObject *obj;
160     const char *encoding = NULL;
161     const char *errors = NULL;
162 
163     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 3, 0, argsbuf);
164     if (!args) {
165         goto exit;
166     }
167     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", "argument 'encoding'", "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", "argument 'errors'", "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     }
202 skip_optional_pos:
203     return_value = _codecs_decode_impl(module, obj, encoding, errors);
204 
205 exit:
206     return return_value;
207 }
208 
209 PyDoc_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    \
216     {"_forget_codec", (PyCFunction)_codecs__forget_codec, METH_O, _codecs__forget_codec__doc__},
217 
218 static PyObject *
219 _codecs__forget_codec_impl(PyObject *module, const char *encoding);
220 
221 static PyObject *
_codecs__forget_codec(PyObject * module,PyObject * arg)222 _codecs__forget_codec(PyObject *module, PyObject *arg)
223 {
224     PyObject *return_value = NULL;
225     const char *encoding;
226 
227     if (!PyUnicode_Check(arg)) {
228         _PyArg_BadArgument("_forget_codec", "argument", "str", arg);
229         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");
238         goto exit;
239     }
240     return_value = _codecs__forget_codec_impl(module, encoding);
241 
242 exit:
243     return return_value;
244 }
245 
246 PyDoc_STRVAR(_codecs_escape_decode__doc__,
247 "escape_decode($module, data, errors=None, /)\n"
248 "--\n"
249 "\n");
250 
251 #define _CODECS_ESCAPE_DECODE_METHODDEF    \
252     {"escape_decode", (PyCFunction)(void(*)(void))_codecs_escape_decode, METH_FASTCALL, _codecs_escape_decode__doc__},
253 
254 static PyObject *
255 _codecs_escape_decode_impl(PyObject *module, Py_buffer *data,
256                            const char *errors);
257 
258 static PyObject *
_codecs_escape_decode(PyObject * module,PyObject * const * args,Py_ssize_t nargs)259 _codecs_escape_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
260 {
261     PyObject *return_value = NULL;
262     Py_buffer data = {NULL, NULL};
263     const char *errors = NULL;
264 
265     if (!_PyArg_CheckPositional("escape_decode", nargs, 1, 2)) {
266         goto exit;
267     }
268     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", "argument 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", "argument 2", "str or None", args[1]);
304         goto exit;
305     }
306 skip_optional:
307     return_value = _codecs_escape_decode_impl(module, &data, errors);
308 
309 exit:
310     /* Cleanup for data */
311     if (data.obj) {
312        PyBuffer_Release(&data);
313     }
314 
315     return return_value;
316 }
317 
318 PyDoc_STRVAR(_codecs_escape_encode__doc__,
319 "escape_encode($module, data, errors=None, /)\n"
320 "--\n"
321 "\n");
322 
323 #define _CODECS_ESCAPE_ENCODE_METHODDEF    \
324     {"escape_encode", (PyCFunction)(void(*)(void))_codecs_escape_encode, METH_FASTCALL, _codecs_escape_encode__doc__},
325 
326 static PyObject *
327 _codecs_escape_encode_impl(PyObject *module, PyObject *data,
328                            const char *errors);
329 
330 static PyObject *
_codecs_escape_encode(PyObject * module,PyObject * const * args,Py_ssize_t nargs)331 _codecs_escape_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
332 {
333     PyObject *return_value = NULL;
334     PyObject *data;
335     const char *errors = NULL;
336 
337     if (!_PyArg_CheckPositional("escape_encode", nargs, 1, 2)) {
338         goto exit;
339     }
340     if (!PyBytes_Check(args[0])) {
341         _PyArg_BadArgument("escape_encode", "argument 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", "argument 2", "str or None", args[1]);
364         goto exit;
365     }
366 skip_optional:
367     return_value = _codecs_escape_encode_impl(module, data, errors);
368 
369 exit:
370     return return_value;
371 }
372 
373 PyDoc_STRVAR(_codecs_utf_7_decode__doc__,
374 "utf_7_decode($module, data, errors=None, final=False, /)\n"
375 "--\n"
376 "\n");
377 
378 #define _CODECS_UTF_7_DECODE_METHODDEF    \
379     {"utf_7_decode", (PyCFunction)(void(*)(void))_codecs_utf_7_decode, METH_FASTCALL, _codecs_utf_7_decode__doc__},
380 
381 static PyObject *
382 _codecs_utf_7_decode_impl(PyObject *module, Py_buffer *data,
383                           const char *errors, int final);
384 
385 static PyObject *
_codecs_utf_7_decode(PyObject * module,PyObject * const * args,Py_ssize_t nargs)386 _codecs_utf_7_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
387 {
388     PyObject *return_value = NULL;
389     Py_buffer data = {NULL, NULL};
390     const char *errors = NULL;
391     int final = 0;
392 
393     if (!_PyArg_CheckPositional("utf_7_decode", nargs, 1, 3)) {
394         goto exit;
395     }
396     if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
397         goto exit;
398     }
399     if (!PyBuffer_IsContiguous(&data, 'C')) {
400         _PyArg_BadArgument("utf_7_decode", "argument 1", "contiguous buffer", args[0]);
401         goto exit;
402     }
403     if (nargs < 2) {
404         goto skip_optional;
405     }
406     if (args[1] == Py_None) {
407         errors = NULL;
408     }
409     else if (PyUnicode_Check(args[1])) {
410         Py_ssize_t errors_length;
411         errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
412         if (errors == NULL) {
413             goto exit;
414         }
415         if (strlen(errors) != (size_t)errors_length) {
416             PyErr_SetString(PyExc_ValueError, "embedded null character");
417             goto exit;
418         }
419     }
420     else {
421         _PyArg_BadArgument("utf_7_decode", "argument 2", "str or None", args[1]);
422         goto exit;
423     }
424     if (nargs < 3) {
425         goto skip_optional;
426     }
427     if (PyFloat_Check(args[2])) {
428         PyErr_SetString(PyExc_TypeError,
429                         "integer argument expected, got float" );
430         goto exit;
431     }
432     final = _PyLong_AsInt(args[2]);
433     if (final == -1 && PyErr_Occurred()) {
434         goto exit;
435     }
436 skip_optional:
437     return_value = _codecs_utf_7_decode_impl(module, &data, errors, final);
438 
439 exit:
440     /* Cleanup for data */
441     if (data.obj) {
442        PyBuffer_Release(&data);
443     }
444 
445     return return_value;
446 }
447 
448 PyDoc_STRVAR(_codecs_utf_8_decode__doc__,
449 "utf_8_decode($module, data, errors=None, final=False, /)\n"
450 "--\n"
451 "\n");
452 
453 #define _CODECS_UTF_8_DECODE_METHODDEF    \
454     {"utf_8_decode", (PyCFunction)(void(*)(void))_codecs_utf_8_decode, METH_FASTCALL, _codecs_utf_8_decode__doc__},
455 
456 static PyObject *
457 _codecs_utf_8_decode_impl(PyObject *module, Py_buffer *data,
458                           const char *errors, int final);
459 
460 static PyObject *
_codecs_utf_8_decode(PyObject * module,PyObject * const * args,Py_ssize_t nargs)461 _codecs_utf_8_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
462 {
463     PyObject *return_value = NULL;
464     Py_buffer data = {NULL, NULL};
465     const char *errors = NULL;
466     int final = 0;
467 
468     if (!_PyArg_CheckPositional("utf_8_decode", nargs, 1, 3)) {
469         goto exit;
470     }
471     if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
472         goto exit;
473     }
474     if (!PyBuffer_IsContiguous(&data, 'C')) {
475         _PyArg_BadArgument("utf_8_decode", "argument 1", "contiguous buffer", args[0]);
476         goto exit;
477     }
478     if (nargs < 2) {
479         goto skip_optional;
480     }
481     if (args[1] == Py_None) {
482         errors = NULL;
483     }
484     else if (PyUnicode_Check(args[1])) {
485         Py_ssize_t errors_length;
486         errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
487         if (errors == NULL) {
488             goto exit;
489         }
490         if (strlen(errors) != (size_t)errors_length) {
491             PyErr_SetString(PyExc_ValueError, "embedded null character");
492             goto exit;
493         }
494     }
495     else {
496         _PyArg_BadArgument("utf_8_decode", "argument 2", "str or None", args[1]);
497         goto exit;
498     }
499     if (nargs < 3) {
500         goto skip_optional;
501     }
502     if (PyFloat_Check(args[2])) {
503         PyErr_SetString(PyExc_TypeError,
504                         "integer argument expected, got float" );
505         goto exit;
506     }
507     final = _PyLong_AsInt(args[2]);
508     if (final == -1 && PyErr_Occurred()) {
509         goto exit;
510     }
511 skip_optional:
512     return_value = _codecs_utf_8_decode_impl(module, &data, errors, final);
513 
514 exit:
515     /* Cleanup for data */
516     if (data.obj) {
517        PyBuffer_Release(&data);
518     }
519 
520     return return_value;
521 }
522 
523 PyDoc_STRVAR(_codecs_utf_16_decode__doc__,
524 "utf_16_decode($module, data, errors=None, final=False, /)\n"
525 "--\n"
526 "\n");
527 
528 #define _CODECS_UTF_16_DECODE_METHODDEF    \
529     {"utf_16_decode", (PyCFunction)(void(*)(void))_codecs_utf_16_decode, METH_FASTCALL, _codecs_utf_16_decode__doc__},
530 
531 static PyObject *
532 _codecs_utf_16_decode_impl(PyObject *module, Py_buffer *data,
533                            const char *errors, int final);
534 
535 static PyObject *
_codecs_utf_16_decode(PyObject * module,PyObject * const * args,Py_ssize_t nargs)536 _codecs_utf_16_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
537 {
538     PyObject *return_value = NULL;
539     Py_buffer data = {NULL, NULL};
540     const char *errors = NULL;
541     int final = 0;
542 
543     if (!_PyArg_CheckPositional("utf_16_decode", nargs, 1, 3)) {
544         goto exit;
545     }
546     if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
547         goto exit;
548     }
549     if (!PyBuffer_IsContiguous(&data, 'C')) {
550         _PyArg_BadArgument("utf_16_decode", "argument 1", "contiguous buffer", args[0]);
551         goto exit;
552     }
553     if (nargs < 2) {
554         goto skip_optional;
555     }
556     if (args[1] == Py_None) {
557         errors = NULL;
558     }
559     else if (PyUnicode_Check(args[1])) {
560         Py_ssize_t errors_length;
561         errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
562         if (errors == NULL) {
563             goto exit;
564         }
565         if (strlen(errors) != (size_t)errors_length) {
566             PyErr_SetString(PyExc_ValueError, "embedded null character");
567             goto exit;
568         }
569     }
570     else {
571         _PyArg_BadArgument("utf_16_decode", "argument 2", "str or None", args[1]);
572         goto exit;
573     }
574     if (nargs < 3) {
575         goto skip_optional;
576     }
577     if (PyFloat_Check(args[2])) {
578         PyErr_SetString(PyExc_TypeError,
579                         "integer argument expected, got float" );
580         goto exit;
581     }
582     final = _PyLong_AsInt(args[2]);
583     if (final == -1 && PyErr_Occurred()) {
584         goto exit;
585     }
586 skip_optional:
587     return_value = _codecs_utf_16_decode_impl(module, &data, errors, final);
588 
589 exit:
590     /* Cleanup for data */
591     if (data.obj) {
592        PyBuffer_Release(&data);
593     }
594 
595     return return_value;
596 }
597 
598 PyDoc_STRVAR(_codecs_utf_16_le_decode__doc__,
599 "utf_16_le_decode($module, data, errors=None, final=False, /)\n"
600 "--\n"
601 "\n");
602 
603 #define _CODECS_UTF_16_LE_DECODE_METHODDEF    \
604     {"utf_16_le_decode", (PyCFunction)(void(*)(void))_codecs_utf_16_le_decode, METH_FASTCALL, _codecs_utf_16_le_decode__doc__},
605 
606 static PyObject *
607 _codecs_utf_16_le_decode_impl(PyObject *module, Py_buffer *data,
608                               const char *errors, int final);
609 
610 static PyObject *
_codecs_utf_16_le_decode(PyObject * module,PyObject * const * args,Py_ssize_t nargs)611 _codecs_utf_16_le_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
612 {
613     PyObject *return_value = NULL;
614     Py_buffer data = {NULL, NULL};
615     const char *errors = NULL;
616     int final = 0;
617 
618     if (!_PyArg_CheckPositional("utf_16_le_decode", nargs, 1, 3)) {
619         goto exit;
620     }
621     if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
622         goto exit;
623     }
624     if (!PyBuffer_IsContiguous(&data, 'C')) {
625         _PyArg_BadArgument("utf_16_le_decode", "argument 1", "contiguous buffer", args[0]);
626         goto exit;
627     }
628     if (nargs < 2) {
629         goto skip_optional;
630     }
631     if (args[1] == Py_None) {
632         errors = NULL;
633     }
634     else if (PyUnicode_Check(args[1])) {
635         Py_ssize_t errors_length;
636         errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
637         if (errors == NULL) {
638             goto exit;
639         }
640         if (strlen(errors) != (size_t)errors_length) {
641             PyErr_SetString(PyExc_ValueError, "embedded null character");
642             goto exit;
643         }
644     }
645     else {
646         _PyArg_BadArgument("utf_16_le_decode", "argument 2", "str or None", args[1]);
647         goto exit;
648     }
649     if (nargs < 3) {
650         goto skip_optional;
651     }
652     if (PyFloat_Check(args[2])) {
653         PyErr_SetString(PyExc_TypeError,
654                         "integer argument expected, got float" );
655         goto exit;
656     }
657     final = _PyLong_AsInt(args[2]);
658     if (final == -1 && PyErr_Occurred()) {
659         goto exit;
660     }
661 skip_optional:
662     return_value = _codecs_utf_16_le_decode_impl(module, &data, errors, final);
663 
664 exit:
665     /* Cleanup for data */
666     if (data.obj) {
667        PyBuffer_Release(&data);
668     }
669 
670     return return_value;
671 }
672 
673 PyDoc_STRVAR(_codecs_utf_16_be_decode__doc__,
674 "utf_16_be_decode($module, data, errors=None, final=False, /)\n"
675 "--\n"
676 "\n");
677 
678 #define _CODECS_UTF_16_BE_DECODE_METHODDEF    \
679     {"utf_16_be_decode", (PyCFunction)(void(*)(void))_codecs_utf_16_be_decode, METH_FASTCALL, _codecs_utf_16_be_decode__doc__},
680 
681 static PyObject *
682 _codecs_utf_16_be_decode_impl(PyObject *module, Py_buffer *data,
683                               const char *errors, int final);
684 
685 static PyObject *
_codecs_utf_16_be_decode(PyObject * module,PyObject * const * args,Py_ssize_t nargs)686 _codecs_utf_16_be_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
687 {
688     PyObject *return_value = NULL;
689     Py_buffer data = {NULL, NULL};
690     const char *errors = NULL;
691     int final = 0;
692 
693     if (!_PyArg_CheckPositional("utf_16_be_decode", nargs, 1, 3)) {
694         goto exit;
695     }
696     if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
697         goto exit;
698     }
699     if (!PyBuffer_IsContiguous(&data, 'C')) {
700         _PyArg_BadArgument("utf_16_be_decode", "argument 1", "contiguous buffer", args[0]);
701         goto exit;
702     }
703     if (nargs < 2) {
704         goto skip_optional;
705     }
706     if (args[1] == Py_None) {
707         errors = NULL;
708     }
709     else if (PyUnicode_Check(args[1])) {
710         Py_ssize_t errors_length;
711         errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
712         if (errors == NULL) {
713             goto exit;
714         }
715         if (strlen(errors) != (size_t)errors_length) {
716             PyErr_SetString(PyExc_ValueError, "embedded null character");
717             goto exit;
718         }
719     }
720     else {
721         _PyArg_BadArgument("utf_16_be_decode", "argument 2", "str or None", args[1]);
722         goto exit;
723     }
724     if (nargs < 3) {
725         goto skip_optional;
726     }
727     if (PyFloat_Check(args[2])) {
728         PyErr_SetString(PyExc_TypeError,
729                         "integer argument expected, got float" );
730         goto exit;
731     }
732     final = _PyLong_AsInt(args[2]);
733     if (final == -1 && PyErr_Occurred()) {
734         goto exit;
735     }
736 skip_optional:
737     return_value = _codecs_utf_16_be_decode_impl(module, &data, errors, final);
738 
739 exit:
740     /* Cleanup for data */
741     if (data.obj) {
742        PyBuffer_Release(&data);
743     }
744 
745     return return_value;
746 }
747 
748 PyDoc_STRVAR(_codecs_utf_16_ex_decode__doc__,
749 "utf_16_ex_decode($module, data, errors=None, byteorder=0, final=False,\n"
750 "                 /)\n"
751 "--\n"
752 "\n");
753 
754 #define _CODECS_UTF_16_EX_DECODE_METHODDEF    \
755     {"utf_16_ex_decode", (PyCFunction)(void(*)(void))_codecs_utf_16_ex_decode, METH_FASTCALL, _codecs_utf_16_ex_decode__doc__},
756 
757 static PyObject *
758 _codecs_utf_16_ex_decode_impl(PyObject *module, Py_buffer *data,
759                               const char *errors, int byteorder, int final);
760 
761 static PyObject *
_codecs_utf_16_ex_decode(PyObject * module,PyObject * const * args,Py_ssize_t nargs)762 _codecs_utf_16_ex_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
763 {
764     PyObject *return_value = NULL;
765     Py_buffer data = {NULL, NULL};
766     const char *errors = NULL;
767     int byteorder = 0;
768     int final = 0;
769 
770     if (!_PyArg_CheckPositional("utf_16_ex_decode", nargs, 1, 4)) {
771         goto exit;
772     }
773     if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
774         goto exit;
775     }
776     if (!PyBuffer_IsContiguous(&data, 'C')) {
777         _PyArg_BadArgument("utf_16_ex_decode", "argument 1", "contiguous buffer", args[0]);
778         goto exit;
779     }
780     if (nargs < 2) {
781         goto skip_optional;
782     }
783     if (args[1] == Py_None) {
784         errors = NULL;
785     }
786     else if (PyUnicode_Check(args[1])) {
787         Py_ssize_t errors_length;
788         errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
789         if (errors == NULL) {
790             goto exit;
791         }
792         if (strlen(errors) != (size_t)errors_length) {
793             PyErr_SetString(PyExc_ValueError, "embedded null character");
794             goto exit;
795         }
796     }
797     else {
798         _PyArg_BadArgument("utf_16_ex_decode", "argument 2", "str or None", args[1]);
799         goto exit;
800     }
801     if (nargs < 3) {
802         goto skip_optional;
803     }
804     if (PyFloat_Check(args[2])) {
805         PyErr_SetString(PyExc_TypeError,
806                         "integer argument expected, got float" );
807         goto exit;
808     }
809     byteorder = _PyLong_AsInt(args[2]);
810     if (byteorder == -1 && PyErr_Occurred()) {
811         goto exit;
812     }
813     if (nargs < 4) {
814         goto skip_optional;
815     }
816     if (PyFloat_Check(args[3])) {
817         PyErr_SetString(PyExc_TypeError,
818                         "integer argument expected, got float" );
819         goto exit;
820     }
821     final = _PyLong_AsInt(args[3]);
822     if (final == -1 && PyErr_Occurred()) {
823         goto exit;
824     }
825 skip_optional:
826     return_value = _codecs_utf_16_ex_decode_impl(module, &data, errors, byteorder, final);
827 
828 exit:
829     /* Cleanup for data */
830     if (data.obj) {
831        PyBuffer_Release(&data);
832     }
833 
834     return return_value;
835 }
836 
837 PyDoc_STRVAR(_codecs_utf_32_decode__doc__,
838 "utf_32_decode($module, data, errors=None, final=False, /)\n"
839 "--\n"
840 "\n");
841 
842 #define _CODECS_UTF_32_DECODE_METHODDEF    \
843     {"utf_32_decode", (PyCFunction)(void(*)(void))_codecs_utf_32_decode, METH_FASTCALL, _codecs_utf_32_decode__doc__},
844 
845 static PyObject *
846 _codecs_utf_32_decode_impl(PyObject *module, Py_buffer *data,
847                            const char *errors, int final);
848 
849 static PyObject *
_codecs_utf_32_decode(PyObject * module,PyObject * const * args,Py_ssize_t nargs)850 _codecs_utf_32_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
851 {
852     PyObject *return_value = NULL;
853     Py_buffer data = {NULL, NULL};
854     const char *errors = NULL;
855     int final = 0;
856 
857     if (!_PyArg_CheckPositional("utf_32_decode", nargs, 1, 3)) {
858         goto exit;
859     }
860     if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
861         goto exit;
862     }
863     if (!PyBuffer_IsContiguous(&data, 'C')) {
864         _PyArg_BadArgument("utf_32_decode", "argument 1", "contiguous buffer", args[0]);
865         goto exit;
866     }
867     if (nargs < 2) {
868         goto skip_optional;
869     }
870     if (args[1] == Py_None) {
871         errors = NULL;
872     }
873     else if (PyUnicode_Check(args[1])) {
874         Py_ssize_t errors_length;
875         errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
876         if (errors == NULL) {
877             goto exit;
878         }
879         if (strlen(errors) != (size_t)errors_length) {
880             PyErr_SetString(PyExc_ValueError, "embedded null character");
881             goto exit;
882         }
883     }
884     else {
885         _PyArg_BadArgument("utf_32_decode", "argument 2", "str or None", args[1]);
886         goto exit;
887     }
888     if (nargs < 3) {
889         goto skip_optional;
890     }
891     if (PyFloat_Check(args[2])) {
892         PyErr_SetString(PyExc_TypeError,
893                         "integer argument expected, got float" );
894         goto exit;
895     }
896     final = _PyLong_AsInt(args[2]);
897     if (final == -1 && PyErr_Occurred()) {
898         goto exit;
899     }
900 skip_optional:
901     return_value = _codecs_utf_32_decode_impl(module, &data, errors, final);
902 
903 exit:
904     /* Cleanup for data */
905     if (data.obj) {
906        PyBuffer_Release(&data);
907     }
908 
909     return return_value;
910 }
911 
912 PyDoc_STRVAR(_codecs_utf_32_le_decode__doc__,
913 "utf_32_le_decode($module, data, errors=None, final=False, /)\n"
914 "--\n"
915 "\n");
916 
917 #define _CODECS_UTF_32_LE_DECODE_METHODDEF    \
918     {"utf_32_le_decode", (PyCFunction)(void(*)(void))_codecs_utf_32_le_decode, METH_FASTCALL, _codecs_utf_32_le_decode__doc__},
919 
920 static PyObject *
921 _codecs_utf_32_le_decode_impl(PyObject *module, Py_buffer *data,
922                               const char *errors, int final);
923 
924 static PyObject *
_codecs_utf_32_le_decode(PyObject * module,PyObject * const * args,Py_ssize_t nargs)925 _codecs_utf_32_le_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
926 {
927     PyObject *return_value = NULL;
928     Py_buffer data = {NULL, NULL};
929     const char *errors = NULL;
930     int final = 0;
931 
932     if (!_PyArg_CheckPositional("utf_32_le_decode", nargs, 1, 3)) {
933         goto exit;
934     }
935     if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
936         goto exit;
937     }
938     if (!PyBuffer_IsContiguous(&data, 'C')) {
939         _PyArg_BadArgument("utf_32_le_decode", "argument 1", "contiguous buffer", args[0]);
940         goto exit;
941     }
942     if (nargs < 2) {
943         goto skip_optional;
944     }
945     if (args[1] == Py_None) {
946         errors = NULL;
947     }
948     else if (PyUnicode_Check(args[1])) {
949         Py_ssize_t errors_length;
950         errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
951         if (errors == NULL) {
952             goto exit;
953         }
954         if (strlen(errors) != (size_t)errors_length) {
955             PyErr_SetString(PyExc_ValueError, "embedded null character");
956             goto exit;
957         }
958     }
959     else {
960         _PyArg_BadArgument("utf_32_le_decode", "argument 2", "str or None", args[1]);
961         goto exit;
962     }
963     if (nargs < 3) {
964         goto skip_optional;
965     }
966     if (PyFloat_Check(args[2])) {
967         PyErr_SetString(PyExc_TypeError,
968                         "integer argument expected, got float" );
969         goto exit;
970     }
971     final = _PyLong_AsInt(args[2]);
972     if (final == -1 && PyErr_Occurred()) {
973         goto exit;
974     }
975 skip_optional:
976     return_value = _codecs_utf_32_le_decode_impl(module, &data, errors, final);
977 
978 exit:
979     /* Cleanup for data */
980     if (data.obj) {
981        PyBuffer_Release(&data);
982     }
983 
984     return return_value;
985 }
986 
987 PyDoc_STRVAR(_codecs_utf_32_be_decode__doc__,
988 "utf_32_be_decode($module, data, errors=None, final=False, /)\n"
989 "--\n"
990 "\n");
991 
992 #define _CODECS_UTF_32_BE_DECODE_METHODDEF    \
993     {"utf_32_be_decode", (PyCFunction)(void(*)(void))_codecs_utf_32_be_decode, METH_FASTCALL, _codecs_utf_32_be_decode__doc__},
994 
995 static PyObject *
996 _codecs_utf_32_be_decode_impl(PyObject *module, Py_buffer *data,
997                               const char *errors, int final);
998 
999 static PyObject *
_codecs_utf_32_be_decode(PyObject * module,PyObject * const * args,Py_ssize_t nargs)1000 _codecs_utf_32_be_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
1001 {
1002     PyObject *return_value = NULL;
1003     Py_buffer data = {NULL, NULL};
1004     const char *errors = NULL;
1005     int final = 0;
1006 
1007     if (!_PyArg_CheckPositional("utf_32_be_decode", nargs, 1, 3)) {
1008         goto exit;
1009     }
1010     if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
1011         goto exit;
1012     }
1013     if (!PyBuffer_IsContiguous(&data, 'C')) {
1014         _PyArg_BadArgument("utf_32_be_decode", "argument 1", "contiguous buffer", args[0]);
1015         goto exit;
1016     }
1017     if (nargs < 2) {
1018         goto skip_optional;
1019     }
1020     if (args[1] == Py_None) {
1021         errors = NULL;
1022     }
1023     else if (PyUnicode_Check(args[1])) {
1024         Py_ssize_t errors_length;
1025         errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
1026         if (errors == NULL) {
1027             goto exit;
1028         }
1029         if (strlen(errors) != (size_t)errors_length) {
1030             PyErr_SetString(PyExc_ValueError, "embedded null character");
1031             goto exit;
1032         }
1033     }
1034     else {
1035         _PyArg_BadArgument("utf_32_be_decode", "argument 2", "str or None", args[1]);
1036         goto exit;
1037     }
1038     if (nargs < 3) {
1039         goto skip_optional;
1040     }
1041     if (PyFloat_Check(args[2])) {
1042         PyErr_SetString(PyExc_TypeError,
1043                         "integer argument expected, got float" );
1044         goto exit;
1045     }
1046     final = _PyLong_AsInt(args[2]);
1047     if (final == -1 && PyErr_Occurred()) {
1048         goto exit;
1049     }
1050 skip_optional:
1051     return_value = _codecs_utf_32_be_decode_impl(module, &data, errors, final);
1052 
1053 exit:
1054     /* Cleanup for data */
1055     if (data.obj) {
1056        PyBuffer_Release(&data);
1057     }
1058 
1059     return return_value;
1060 }
1061 
1062 PyDoc_STRVAR(_codecs_utf_32_ex_decode__doc__,
1063 "utf_32_ex_decode($module, data, errors=None, byteorder=0, final=False,\n"
1064 "                 /)\n"
1065 "--\n"
1066 "\n");
1067 
1068 #define _CODECS_UTF_32_EX_DECODE_METHODDEF    \
1069     {"utf_32_ex_decode", (PyCFunction)(void(*)(void))_codecs_utf_32_ex_decode, METH_FASTCALL, _codecs_utf_32_ex_decode__doc__},
1070 
1071 static PyObject *
1072 _codecs_utf_32_ex_decode_impl(PyObject *module, Py_buffer *data,
1073                               const char *errors, int byteorder, int final);
1074 
1075 static PyObject *
_codecs_utf_32_ex_decode(PyObject * module,PyObject * const * args,Py_ssize_t nargs)1076 _codecs_utf_32_ex_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
1077 {
1078     PyObject *return_value = NULL;
1079     Py_buffer data = {NULL, NULL};
1080     const char *errors = NULL;
1081     int byteorder = 0;
1082     int final = 0;
1083 
1084     if (!_PyArg_CheckPositional("utf_32_ex_decode", nargs, 1, 4)) {
1085         goto exit;
1086     }
1087     if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
1088         goto exit;
1089     }
1090     if (!PyBuffer_IsContiguous(&data, 'C')) {
1091         _PyArg_BadArgument("utf_32_ex_decode", "argument 1", "contiguous buffer", args[0]);
1092         goto exit;
1093     }
1094     if (nargs < 2) {
1095         goto skip_optional;
1096     }
1097     if (args[1] == Py_None) {
1098         errors = NULL;
1099     }
1100     else if (PyUnicode_Check(args[1])) {
1101         Py_ssize_t errors_length;
1102         errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
1103         if (errors == NULL) {
1104             goto exit;
1105         }
1106         if (strlen(errors) != (size_t)errors_length) {
1107             PyErr_SetString(PyExc_ValueError, "embedded null character");
1108             goto exit;
1109         }
1110     }
1111     else {
1112         _PyArg_BadArgument("utf_32_ex_decode", "argument 2", "str or None", args[1]);
1113         goto exit;
1114     }
1115     if (nargs < 3) {
1116         goto skip_optional;
1117     }
1118     if (PyFloat_Check(args[2])) {
1119         PyErr_SetString(PyExc_TypeError,
1120                         "integer argument expected, got float" );
1121         goto exit;
1122     }
1123     byteorder = _PyLong_AsInt(args[2]);
1124     if (byteorder == -1 && PyErr_Occurred()) {
1125         goto exit;
1126     }
1127     if (nargs < 4) {
1128         goto skip_optional;
1129     }
1130     if (PyFloat_Check(args[3])) {
1131         PyErr_SetString(PyExc_TypeError,
1132                         "integer argument expected, got float" );
1133         goto exit;
1134     }
1135     final = _PyLong_AsInt(args[3]);
1136     if (final == -1 && PyErr_Occurred()) {
1137         goto exit;
1138     }
1139 skip_optional:
1140     return_value = _codecs_utf_32_ex_decode_impl(module, &data, errors, byteorder, final);
1141 
1142 exit:
1143     /* Cleanup for data */
1144     if (data.obj) {
1145        PyBuffer_Release(&data);
1146     }
1147 
1148     return return_value;
1149 }
1150 
1151 PyDoc_STRVAR(_codecs_unicode_escape_decode__doc__,
1152 "unicode_escape_decode($module, data, errors=None, /)\n"
1153 "--\n"
1154 "\n");
1155 
1156 #define _CODECS_UNICODE_ESCAPE_DECODE_METHODDEF    \
1157     {"unicode_escape_decode", (PyCFunction)(void(*)(void))_codecs_unicode_escape_decode, METH_FASTCALL, _codecs_unicode_escape_decode__doc__},
1158 
1159 static PyObject *
1160 _codecs_unicode_escape_decode_impl(PyObject *module, Py_buffer *data,
1161                                    const char *errors);
1162 
1163 static PyObject *
_codecs_unicode_escape_decode(PyObject * module,PyObject * const * args,Py_ssize_t nargs)1164 _codecs_unicode_escape_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
1165 {
1166     PyObject *return_value = NULL;
1167     Py_buffer data = {NULL, NULL};
1168     const char *errors = NULL;
1169 
1170     if (!_PyArg_CheckPositional("unicode_escape_decode", nargs, 1, 2)) {
1171         goto exit;
1172     }
1173     if (PyUnicode_Check(args[0])) {
1174         Py_ssize_t len;
1175         const char *ptr = PyUnicode_AsUTF8AndSize(args[0], &len);
1176         if (ptr == NULL) {
1177             goto exit;
1178         }
1179         PyBuffer_FillInfo(&data, args[0], (void *)ptr, len, 1, 0);
1180     }
1181     else { /* any bytes-like object */
1182         if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
1183             goto exit;
1184         }
1185         if (!PyBuffer_IsContiguous(&data, 'C')) {
1186             _PyArg_BadArgument("unicode_escape_decode", "argument 1", "contiguous buffer", args[0]);
1187             goto exit;
1188         }
1189     }
1190     if (nargs < 2) {
1191         goto skip_optional;
1192     }
1193     if (args[1] == Py_None) {
1194         errors = NULL;
1195     }
1196     else if (PyUnicode_Check(args[1])) {
1197         Py_ssize_t errors_length;
1198         errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
1199         if (errors == NULL) {
1200             goto exit;
1201         }
1202         if (strlen(errors) != (size_t)errors_length) {
1203             PyErr_SetString(PyExc_ValueError, "embedded null character");
1204             goto exit;
1205         }
1206     }
1207     else {
1208         _PyArg_BadArgument("unicode_escape_decode", "argument 2", "str or None", args[1]);
1209         goto exit;
1210     }
1211 skip_optional:
1212     return_value = _codecs_unicode_escape_decode_impl(module, &data, errors);
1213 
1214 exit:
1215     /* Cleanup for data */
1216     if (data.obj) {
1217        PyBuffer_Release(&data);
1218     }
1219 
1220     return return_value;
1221 }
1222 
1223 PyDoc_STRVAR(_codecs_raw_unicode_escape_decode__doc__,
1224 "raw_unicode_escape_decode($module, data, errors=None, /)\n"
1225 "--\n"
1226 "\n");
1227 
1228 #define _CODECS_RAW_UNICODE_ESCAPE_DECODE_METHODDEF    \
1229     {"raw_unicode_escape_decode", (PyCFunction)(void(*)(void))_codecs_raw_unicode_escape_decode, METH_FASTCALL, _codecs_raw_unicode_escape_decode__doc__},
1230 
1231 static PyObject *
1232 _codecs_raw_unicode_escape_decode_impl(PyObject *module, Py_buffer *data,
1233                                        const char *errors);
1234 
1235 static PyObject *
_codecs_raw_unicode_escape_decode(PyObject * module,PyObject * const * args,Py_ssize_t nargs)1236 _codecs_raw_unicode_escape_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
1237 {
1238     PyObject *return_value = NULL;
1239     Py_buffer data = {NULL, NULL};
1240     const char *errors = NULL;
1241 
1242     if (!_PyArg_CheckPositional("raw_unicode_escape_decode", nargs, 1, 2)) {
1243         goto exit;
1244     }
1245     if (PyUnicode_Check(args[0])) {
1246         Py_ssize_t len;
1247         const char *ptr = PyUnicode_AsUTF8AndSize(args[0], &len);
1248         if (ptr == NULL) {
1249             goto exit;
1250         }
1251         PyBuffer_FillInfo(&data, args[0], (void *)ptr, len, 1, 0);
1252     }
1253     else { /* any bytes-like object */
1254         if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
1255             goto exit;
1256         }
1257         if (!PyBuffer_IsContiguous(&data, 'C')) {
1258             _PyArg_BadArgument("raw_unicode_escape_decode", "argument 1", "contiguous buffer", args[0]);
1259             goto exit;
1260         }
1261     }
1262     if (nargs < 2) {
1263         goto skip_optional;
1264     }
1265     if (args[1] == Py_None) {
1266         errors = NULL;
1267     }
1268     else if (PyUnicode_Check(args[1])) {
1269         Py_ssize_t errors_length;
1270         errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
1271         if (errors == NULL) {
1272             goto exit;
1273         }
1274         if (strlen(errors) != (size_t)errors_length) {
1275             PyErr_SetString(PyExc_ValueError, "embedded null character");
1276             goto exit;
1277         }
1278     }
1279     else {
1280         _PyArg_BadArgument("raw_unicode_escape_decode", "argument 2", "str or None", args[1]);
1281         goto exit;
1282     }
1283 skip_optional:
1284     return_value = _codecs_raw_unicode_escape_decode_impl(module, &data, errors);
1285 
1286 exit:
1287     /* Cleanup for data */
1288     if (data.obj) {
1289        PyBuffer_Release(&data);
1290     }
1291 
1292     return return_value;
1293 }
1294 
1295 PyDoc_STRVAR(_codecs_latin_1_decode__doc__,
1296 "latin_1_decode($module, data, errors=None, /)\n"
1297 "--\n"
1298 "\n");
1299 
1300 #define _CODECS_LATIN_1_DECODE_METHODDEF    \
1301     {"latin_1_decode", (PyCFunction)(void(*)(void))_codecs_latin_1_decode, METH_FASTCALL, _codecs_latin_1_decode__doc__},
1302 
1303 static PyObject *
1304 _codecs_latin_1_decode_impl(PyObject *module, Py_buffer *data,
1305                             const char *errors);
1306 
1307 static PyObject *
_codecs_latin_1_decode(PyObject * module,PyObject * const * args,Py_ssize_t nargs)1308 _codecs_latin_1_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
1309 {
1310     PyObject *return_value = NULL;
1311     Py_buffer data = {NULL, NULL};
1312     const char *errors = NULL;
1313 
1314     if (!_PyArg_CheckPositional("latin_1_decode", nargs, 1, 2)) {
1315         goto exit;
1316     }
1317     if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
1318         goto exit;
1319     }
1320     if (!PyBuffer_IsContiguous(&data, 'C')) {
1321         _PyArg_BadArgument("latin_1_decode", "argument 1", "contiguous buffer", args[0]);
1322         goto exit;
1323     }
1324     if (nargs < 2) {
1325         goto skip_optional;
1326     }
1327     if (args[1] == Py_None) {
1328         errors = NULL;
1329     }
1330     else if (PyUnicode_Check(args[1])) {
1331         Py_ssize_t errors_length;
1332         errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
1333         if (errors == NULL) {
1334             goto exit;
1335         }
1336         if (strlen(errors) != (size_t)errors_length) {
1337             PyErr_SetString(PyExc_ValueError, "embedded null character");
1338             goto exit;
1339         }
1340     }
1341     else {
1342         _PyArg_BadArgument("latin_1_decode", "argument 2", "str or None", args[1]);
1343         goto exit;
1344     }
1345 skip_optional:
1346     return_value = _codecs_latin_1_decode_impl(module, &data, errors);
1347 
1348 exit:
1349     /* Cleanup for data */
1350     if (data.obj) {
1351        PyBuffer_Release(&data);
1352     }
1353 
1354     return return_value;
1355 }
1356 
1357 PyDoc_STRVAR(_codecs_ascii_decode__doc__,
1358 "ascii_decode($module, data, errors=None, /)\n"
1359 "--\n"
1360 "\n");
1361 
1362 #define _CODECS_ASCII_DECODE_METHODDEF    \
1363     {"ascii_decode", (PyCFunction)(void(*)(void))_codecs_ascii_decode, METH_FASTCALL, _codecs_ascii_decode__doc__},
1364 
1365 static PyObject *
1366 _codecs_ascii_decode_impl(PyObject *module, Py_buffer *data,
1367                           const char *errors);
1368 
1369 static PyObject *
_codecs_ascii_decode(PyObject * module,PyObject * const * args,Py_ssize_t nargs)1370 _codecs_ascii_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
1371 {
1372     PyObject *return_value = NULL;
1373     Py_buffer data = {NULL, NULL};
1374     const char *errors = NULL;
1375 
1376     if (!_PyArg_CheckPositional("ascii_decode", nargs, 1, 2)) {
1377         goto exit;
1378     }
1379     if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
1380         goto exit;
1381     }
1382     if (!PyBuffer_IsContiguous(&data, 'C')) {
1383         _PyArg_BadArgument("ascii_decode", "argument 1", "contiguous buffer", args[0]);
1384         goto exit;
1385     }
1386     if (nargs < 2) {
1387         goto skip_optional;
1388     }
1389     if (args[1] == Py_None) {
1390         errors = NULL;
1391     }
1392     else if (PyUnicode_Check(args[1])) {
1393         Py_ssize_t errors_length;
1394         errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
1395         if (errors == NULL) {
1396             goto exit;
1397         }
1398         if (strlen(errors) != (size_t)errors_length) {
1399             PyErr_SetString(PyExc_ValueError, "embedded null character");
1400             goto exit;
1401         }
1402     }
1403     else {
1404         _PyArg_BadArgument("ascii_decode", "argument 2", "str or None", args[1]);
1405         goto exit;
1406     }
1407 skip_optional:
1408     return_value = _codecs_ascii_decode_impl(module, &data, errors);
1409 
1410 exit:
1411     /* Cleanup for data */
1412     if (data.obj) {
1413        PyBuffer_Release(&data);
1414     }
1415 
1416     return return_value;
1417 }
1418 
1419 PyDoc_STRVAR(_codecs_charmap_decode__doc__,
1420 "charmap_decode($module, data, errors=None, mapping=None, /)\n"
1421 "--\n"
1422 "\n");
1423 
1424 #define _CODECS_CHARMAP_DECODE_METHODDEF    \
1425     {"charmap_decode", (PyCFunction)(void(*)(void))_codecs_charmap_decode, METH_FASTCALL, _codecs_charmap_decode__doc__},
1426 
1427 static PyObject *
1428 _codecs_charmap_decode_impl(PyObject *module, Py_buffer *data,
1429                             const char *errors, PyObject *mapping);
1430 
1431 static PyObject *
_codecs_charmap_decode(PyObject * module,PyObject * const * args,Py_ssize_t nargs)1432 _codecs_charmap_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
1433 {
1434     PyObject *return_value = NULL;
1435     Py_buffer data = {NULL, NULL};
1436     const char *errors = NULL;
1437     PyObject *mapping = Py_None;
1438 
1439     if (!_PyArg_CheckPositional("charmap_decode", nargs, 1, 3)) {
1440         goto exit;
1441     }
1442     if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
1443         goto exit;
1444     }
1445     if (!PyBuffer_IsContiguous(&data, 'C')) {
1446         _PyArg_BadArgument("charmap_decode", "argument 1", "contiguous buffer", args[0]);
1447         goto exit;
1448     }
1449     if (nargs < 2) {
1450         goto skip_optional;
1451     }
1452     if (args[1] == Py_None) {
1453         errors = NULL;
1454     }
1455     else if (PyUnicode_Check(args[1])) {
1456         Py_ssize_t errors_length;
1457         errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
1458         if (errors == NULL) {
1459             goto exit;
1460         }
1461         if (strlen(errors) != (size_t)errors_length) {
1462             PyErr_SetString(PyExc_ValueError, "embedded null character");
1463             goto exit;
1464         }
1465     }
1466     else {
1467         _PyArg_BadArgument("charmap_decode", "argument 2", "str or None", args[1]);
1468         goto exit;
1469     }
1470     if (nargs < 3) {
1471         goto skip_optional;
1472     }
1473     mapping = args[2];
1474 skip_optional:
1475     return_value = _codecs_charmap_decode_impl(module, &data, errors, mapping);
1476 
1477 exit:
1478     /* Cleanup for data */
1479     if (data.obj) {
1480        PyBuffer_Release(&data);
1481     }
1482 
1483     return return_value;
1484 }
1485 
1486 #if defined(MS_WINDOWS)
1487 
1488 PyDoc_STRVAR(_codecs_mbcs_decode__doc__,
1489 "mbcs_decode($module, data, errors=None, final=False, /)\n"
1490 "--\n"
1491 "\n");
1492 
1493 #define _CODECS_MBCS_DECODE_METHODDEF    \
1494     {"mbcs_decode", (PyCFunction)(void(*)(void))_codecs_mbcs_decode, METH_FASTCALL, _codecs_mbcs_decode__doc__},
1495 
1496 static PyObject *
1497 _codecs_mbcs_decode_impl(PyObject *module, Py_buffer *data,
1498                          const char *errors, int final);
1499 
1500 static PyObject *
_codecs_mbcs_decode(PyObject * module,PyObject * const * args,Py_ssize_t nargs)1501 _codecs_mbcs_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
1502 {
1503     PyObject *return_value = NULL;
1504     Py_buffer data = {NULL, NULL};
1505     const char *errors = NULL;
1506     int final = 0;
1507 
1508     if (!_PyArg_CheckPositional("mbcs_decode", nargs, 1, 3)) {
1509         goto exit;
1510     }
1511     if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
1512         goto exit;
1513     }
1514     if (!PyBuffer_IsContiguous(&data, 'C')) {
1515         _PyArg_BadArgument("mbcs_decode", "argument 1", "contiguous buffer", args[0]);
1516         goto exit;
1517     }
1518     if (nargs < 2) {
1519         goto skip_optional;
1520     }
1521     if (args[1] == Py_None) {
1522         errors = NULL;
1523     }
1524     else if (PyUnicode_Check(args[1])) {
1525         Py_ssize_t errors_length;
1526         errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
1527         if (errors == NULL) {
1528             goto exit;
1529         }
1530         if (strlen(errors) != (size_t)errors_length) {
1531             PyErr_SetString(PyExc_ValueError, "embedded null character");
1532             goto exit;
1533         }
1534     }
1535     else {
1536         _PyArg_BadArgument("mbcs_decode", "argument 2", "str or None", args[1]);
1537         goto exit;
1538     }
1539     if (nargs < 3) {
1540         goto skip_optional;
1541     }
1542     if (PyFloat_Check(args[2])) {
1543         PyErr_SetString(PyExc_TypeError,
1544                         "integer argument expected, got float" );
1545         goto exit;
1546     }
1547     final = _PyLong_AsInt(args[2]);
1548     if (final == -1 && PyErr_Occurred()) {
1549         goto exit;
1550     }
1551 skip_optional:
1552     return_value = _codecs_mbcs_decode_impl(module, &data, errors, final);
1553 
1554 exit:
1555     /* Cleanup for data */
1556     if (data.obj) {
1557        PyBuffer_Release(&data);
1558     }
1559 
1560     return return_value;
1561 }
1562 
1563 #endif /* defined(MS_WINDOWS) */
1564 
1565 #if defined(MS_WINDOWS)
1566 
1567 PyDoc_STRVAR(_codecs_oem_decode__doc__,
1568 "oem_decode($module, data, errors=None, final=False, /)\n"
1569 "--\n"
1570 "\n");
1571 
1572 #define _CODECS_OEM_DECODE_METHODDEF    \
1573     {"oem_decode", (PyCFunction)(void(*)(void))_codecs_oem_decode, METH_FASTCALL, _codecs_oem_decode__doc__},
1574 
1575 static PyObject *
1576 _codecs_oem_decode_impl(PyObject *module, Py_buffer *data,
1577                         const char *errors, int final);
1578 
1579 static PyObject *
_codecs_oem_decode(PyObject * module,PyObject * const * args,Py_ssize_t nargs)1580 _codecs_oem_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
1581 {
1582     PyObject *return_value = NULL;
1583     Py_buffer data = {NULL, NULL};
1584     const char *errors = NULL;
1585     int final = 0;
1586 
1587     if (!_PyArg_CheckPositional("oem_decode", nargs, 1, 3)) {
1588         goto exit;
1589     }
1590     if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
1591         goto exit;
1592     }
1593     if (!PyBuffer_IsContiguous(&data, 'C')) {
1594         _PyArg_BadArgument("oem_decode", "argument 1", "contiguous buffer", args[0]);
1595         goto exit;
1596     }
1597     if (nargs < 2) {
1598         goto skip_optional;
1599     }
1600     if (args[1] == Py_None) {
1601         errors = NULL;
1602     }
1603     else if (PyUnicode_Check(args[1])) {
1604         Py_ssize_t errors_length;
1605         errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
1606         if (errors == NULL) {
1607             goto exit;
1608         }
1609         if (strlen(errors) != (size_t)errors_length) {
1610             PyErr_SetString(PyExc_ValueError, "embedded null character");
1611             goto exit;
1612         }
1613     }
1614     else {
1615         _PyArg_BadArgument("oem_decode", "argument 2", "str or None", args[1]);
1616         goto exit;
1617     }
1618     if (nargs < 3) {
1619         goto skip_optional;
1620     }
1621     if (PyFloat_Check(args[2])) {
1622         PyErr_SetString(PyExc_TypeError,
1623                         "integer argument expected, got float" );
1624         goto exit;
1625     }
1626     final = _PyLong_AsInt(args[2]);
1627     if (final == -1 && PyErr_Occurred()) {
1628         goto exit;
1629     }
1630 skip_optional:
1631     return_value = _codecs_oem_decode_impl(module, &data, errors, final);
1632 
1633 exit:
1634     /* Cleanup for data */
1635     if (data.obj) {
1636        PyBuffer_Release(&data);
1637     }
1638 
1639     return return_value;
1640 }
1641 
1642 #endif /* defined(MS_WINDOWS) */
1643 
1644 #if defined(MS_WINDOWS)
1645 
1646 PyDoc_STRVAR(_codecs_code_page_decode__doc__,
1647 "code_page_decode($module, codepage, data, errors=None, final=False, /)\n"
1648 "--\n"
1649 "\n");
1650 
1651 #define _CODECS_CODE_PAGE_DECODE_METHODDEF    \
1652     {"code_page_decode", (PyCFunction)(void(*)(void))_codecs_code_page_decode, METH_FASTCALL, _codecs_code_page_decode__doc__},
1653 
1654 static PyObject *
1655 _codecs_code_page_decode_impl(PyObject *module, int codepage,
1656                               Py_buffer *data, const char *errors, int final);
1657 
1658 static PyObject *
_codecs_code_page_decode(PyObject * module,PyObject * const * args,Py_ssize_t nargs)1659 _codecs_code_page_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
1660 {
1661     PyObject *return_value = NULL;
1662     int codepage;
1663     Py_buffer data = {NULL, NULL};
1664     const char *errors = NULL;
1665     int final = 0;
1666 
1667     if (!_PyArg_CheckPositional("code_page_decode", nargs, 2, 4)) {
1668         goto exit;
1669     }
1670     if (PyFloat_Check(args[0])) {
1671         PyErr_SetString(PyExc_TypeError,
1672                         "integer argument expected, got float" );
1673         goto exit;
1674     }
1675     codepage = _PyLong_AsInt(args[0]);
1676     if (codepage == -1 && PyErr_Occurred()) {
1677         goto exit;
1678     }
1679     if (PyObject_GetBuffer(args[1], &data, PyBUF_SIMPLE) != 0) {
1680         goto exit;
1681     }
1682     if (!PyBuffer_IsContiguous(&data, 'C')) {
1683         _PyArg_BadArgument("code_page_decode", "argument 2", "contiguous buffer", args[1]);
1684         goto exit;
1685     }
1686     if (nargs < 3) {
1687         goto skip_optional;
1688     }
1689     if (args[2] == Py_None) {
1690         errors = NULL;
1691     }
1692     else if (PyUnicode_Check(args[2])) {
1693         Py_ssize_t errors_length;
1694         errors = PyUnicode_AsUTF8AndSize(args[2], &errors_length);
1695         if (errors == NULL) {
1696             goto exit;
1697         }
1698         if (strlen(errors) != (size_t)errors_length) {
1699             PyErr_SetString(PyExc_ValueError, "embedded null character");
1700             goto exit;
1701         }
1702     }
1703     else {
1704         _PyArg_BadArgument("code_page_decode", "argument 3", "str or None", args[2]);
1705         goto exit;
1706     }
1707     if (nargs < 4) {
1708         goto skip_optional;
1709     }
1710     if (PyFloat_Check(args[3])) {
1711         PyErr_SetString(PyExc_TypeError,
1712                         "integer argument expected, got float" );
1713         goto exit;
1714     }
1715     final = _PyLong_AsInt(args[3]);
1716     if (final == -1 && PyErr_Occurred()) {
1717         goto exit;
1718     }
1719 skip_optional:
1720     return_value = _codecs_code_page_decode_impl(module, codepage, &data, errors, final);
1721 
1722 exit:
1723     /* Cleanup for data */
1724     if (data.obj) {
1725        PyBuffer_Release(&data);
1726     }
1727 
1728     return return_value;
1729 }
1730 
1731 #endif /* defined(MS_WINDOWS) */
1732 
1733 PyDoc_STRVAR(_codecs_readbuffer_encode__doc__,
1734 "readbuffer_encode($module, data, errors=None, /)\n"
1735 "--\n"
1736 "\n");
1737 
1738 #define _CODECS_READBUFFER_ENCODE_METHODDEF    \
1739     {"readbuffer_encode", (PyCFunction)(void(*)(void))_codecs_readbuffer_encode, METH_FASTCALL, _codecs_readbuffer_encode__doc__},
1740 
1741 static PyObject *
1742 _codecs_readbuffer_encode_impl(PyObject *module, Py_buffer *data,
1743                                const char *errors);
1744 
1745 static PyObject *
_codecs_readbuffer_encode(PyObject * module,PyObject * const * args,Py_ssize_t nargs)1746 _codecs_readbuffer_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
1747 {
1748     PyObject *return_value = NULL;
1749     Py_buffer data = {NULL, NULL};
1750     const char *errors = NULL;
1751 
1752     if (!_PyArg_CheckPositional("readbuffer_encode", nargs, 1, 2)) {
1753         goto exit;
1754     }
1755     if (PyUnicode_Check(args[0])) {
1756         Py_ssize_t len;
1757         const char *ptr = PyUnicode_AsUTF8AndSize(args[0], &len);
1758         if (ptr == NULL) {
1759             goto exit;
1760         }
1761         PyBuffer_FillInfo(&data, args[0], (void *)ptr, len, 1, 0);
1762     }
1763     else { /* any bytes-like object */
1764         if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
1765             goto exit;
1766         }
1767         if (!PyBuffer_IsContiguous(&data, 'C')) {
1768             _PyArg_BadArgument("readbuffer_encode", "argument 1", "contiguous buffer", args[0]);
1769             goto exit;
1770         }
1771     }
1772     if (nargs < 2) {
1773         goto skip_optional;
1774     }
1775     if (args[1] == Py_None) {
1776         errors = NULL;
1777     }
1778     else if (PyUnicode_Check(args[1])) {
1779         Py_ssize_t errors_length;
1780         errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
1781         if (errors == NULL) {
1782             goto exit;
1783         }
1784         if (strlen(errors) != (size_t)errors_length) {
1785             PyErr_SetString(PyExc_ValueError, "embedded null character");
1786             goto exit;
1787         }
1788     }
1789     else {
1790         _PyArg_BadArgument("readbuffer_encode", "argument 2", "str or None", args[1]);
1791         goto exit;
1792     }
1793 skip_optional:
1794     return_value = _codecs_readbuffer_encode_impl(module, &data, errors);
1795 
1796 exit:
1797     /* Cleanup for data */
1798     if (data.obj) {
1799        PyBuffer_Release(&data);
1800     }
1801 
1802     return return_value;
1803 }
1804 
1805 PyDoc_STRVAR(_codecs_utf_7_encode__doc__,
1806 "utf_7_encode($module, str, errors=None, /)\n"
1807 "--\n"
1808 "\n");
1809 
1810 #define _CODECS_UTF_7_ENCODE_METHODDEF    \
1811     {"utf_7_encode", (PyCFunction)(void(*)(void))_codecs_utf_7_encode, METH_FASTCALL, _codecs_utf_7_encode__doc__},
1812 
1813 static PyObject *
1814 _codecs_utf_7_encode_impl(PyObject *module, PyObject *str,
1815                           const char *errors);
1816 
1817 static PyObject *
_codecs_utf_7_encode(PyObject * module,PyObject * const * args,Py_ssize_t nargs)1818 _codecs_utf_7_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
1819 {
1820     PyObject *return_value = NULL;
1821     PyObject *str;
1822     const char *errors = NULL;
1823 
1824     if (!_PyArg_CheckPositional("utf_7_encode", nargs, 1, 2)) {
1825         goto exit;
1826     }
1827     if (!PyUnicode_Check(args[0])) {
1828         _PyArg_BadArgument("utf_7_encode", "argument 1", "str", args[0]);
1829         goto exit;
1830     }
1831     if (PyUnicode_READY(args[0]) == -1) {
1832         goto exit;
1833     }
1834     str = args[0];
1835     if (nargs < 2) {
1836         goto skip_optional;
1837     }
1838     if (args[1] == Py_None) {
1839         errors = NULL;
1840     }
1841     else if (PyUnicode_Check(args[1])) {
1842         Py_ssize_t errors_length;
1843         errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
1844         if (errors == NULL) {
1845             goto exit;
1846         }
1847         if (strlen(errors) != (size_t)errors_length) {
1848             PyErr_SetString(PyExc_ValueError, "embedded null character");
1849             goto exit;
1850         }
1851     }
1852     else {
1853         _PyArg_BadArgument("utf_7_encode", "argument 2", "str or None", args[1]);
1854         goto exit;
1855     }
1856 skip_optional:
1857     return_value = _codecs_utf_7_encode_impl(module, str, errors);
1858 
1859 exit:
1860     return return_value;
1861 }
1862 
1863 PyDoc_STRVAR(_codecs_utf_8_encode__doc__,
1864 "utf_8_encode($module, str, errors=None, /)\n"
1865 "--\n"
1866 "\n");
1867 
1868 #define _CODECS_UTF_8_ENCODE_METHODDEF    \
1869     {"utf_8_encode", (PyCFunction)(void(*)(void))_codecs_utf_8_encode, METH_FASTCALL, _codecs_utf_8_encode__doc__},
1870 
1871 static PyObject *
1872 _codecs_utf_8_encode_impl(PyObject *module, PyObject *str,
1873                           const char *errors);
1874 
1875 static PyObject *
_codecs_utf_8_encode(PyObject * module,PyObject * const * args,Py_ssize_t nargs)1876 _codecs_utf_8_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
1877 {
1878     PyObject *return_value = NULL;
1879     PyObject *str;
1880     const char *errors = NULL;
1881 
1882     if (!_PyArg_CheckPositional("utf_8_encode", nargs, 1, 2)) {
1883         goto exit;
1884     }
1885     if (!PyUnicode_Check(args[0])) {
1886         _PyArg_BadArgument("utf_8_encode", "argument 1", "str", args[0]);
1887         goto exit;
1888     }
1889     if (PyUnicode_READY(args[0]) == -1) {
1890         goto exit;
1891     }
1892     str = args[0];
1893     if (nargs < 2) {
1894         goto skip_optional;
1895     }
1896     if (args[1] == Py_None) {
1897         errors = NULL;
1898     }
1899     else if (PyUnicode_Check(args[1])) {
1900         Py_ssize_t errors_length;
1901         errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
1902         if (errors == NULL) {
1903             goto exit;
1904         }
1905         if (strlen(errors) != (size_t)errors_length) {
1906             PyErr_SetString(PyExc_ValueError, "embedded null character");
1907             goto exit;
1908         }
1909     }
1910     else {
1911         _PyArg_BadArgument("utf_8_encode", "argument 2", "str or None", args[1]);
1912         goto exit;
1913     }
1914 skip_optional:
1915     return_value = _codecs_utf_8_encode_impl(module, str, errors);
1916 
1917 exit:
1918     return return_value;
1919 }
1920 
1921 PyDoc_STRVAR(_codecs_utf_16_encode__doc__,
1922 "utf_16_encode($module, str, errors=None, byteorder=0, /)\n"
1923 "--\n"
1924 "\n");
1925 
1926 #define _CODECS_UTF_16_ENCODE_METHODDEF    \
1927     {"utf_16_encode", (PyCFunction)(void(*)(void))_codecs_utf_16_encode, METH_FASTCALL, _codecs_utf_16_encode__doc__},
1928 
1929 static PyObject *
1930 _codecs_utf_16_encode_impl(PyObject *module, PyObject *str,
1931                            const char *errors, int byteorder);
1932 
1933 static PyObject *
_codecs_utf_16_encode(PyObject * module,PyObject * const * args,Py_ssize_t nargs)1934 _codecs_utf_16_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
1935 {
1936     PyObject *return_value = NULL;
1937     PyObject *str;
1938     const char *errors = NULL;
1939     int byteorder = 0;
1940 
1941     if (!_PyArg_CheckPositional("utf_16_encode", nargs, 1, 3)) {
1942         goto exit;
1943     }
1944     if (!PyUnicode_Check(args[0])) {
1945         _PyArg_BadArgument("utf_16_encode", "argument 1", "str", args[0]);
1946         goto exit;
1947     }
1948     if (PyUnicode_READY(args[0]) == -1) {
1949         goto exit;
1950     }
1951     str = args[0];
1952     if (nargs < 2) {
1953         goto skip_optional;
1954     }
1955     if (args[1] == Py_None) {
1956         errors = NULL;
1957     }
1958     else if (PyUnicode_Check(args[1])) {
1959         Py_ssize_t errors_length;
1960         errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
1961         if (errors == NULL) {
1962             goto exit;
1963         }
1964         if (strlen(errors) != (size_t)errors_length) {
1965             PyErr_SetString(PyExc_ValueError, "embedded null character");
1966             goto exit;
1967         }
1968     }
1969     else {
1970         _PyArg_BadArgument("utf_16_encode", "argument 2", "str or None", args[1]);
1971         goto exit;
1972     }
1973     if (nargs < 3) {
1974         goto skip_optional;
1975     }
1976     if (PyFloat_Check(args[2])) {
1977         PyErr_SetString(PyExc_TypeError,
1978                         "integer argument expected, got float" );
1979         goto exit;
1980     }
1981     byteorder = _PyLong_AsInt(args[2]);
1982     if (byteorder == -1 && PyErr_Occurred()) {
1983         goto exit;
1984     }
1985 skip_optional:
1986     return_value = _codecs_utf_16_encode_impl(module, str, errors, byteorder);
1987 
1988 exit:
1989     return return_value;
1990 }
1991 
1992 PyDoc_STRVAR(_codecs_utf_16_le_encode__doc__,
1993 "utf_16_le_encode($module, str, errors=None, /)\n"
1994 "--\n"
1995 "\n");
1996 
1997 #define _CODECS_UTF_16_LE_ENCODE_METHODDEF    \
1998     {"utf_16_le_encode", (PyCFunction)(void(*)(void))_codecs_utf_16_le_encode, METH_FASTCALL, _codecs_utf_16_le_encode__doc__},
1999 
2000 static PyObject *
2001 _codecs_utf_16_le_encode_impl(PyObject *module, PyObject *str,
2002                               const char *errors);
2003 
2004 static PyObject *
_codecs_utf_16_le_encode(PyObject * module,PyObject * const * args,Py_ssize_t nargs)2005 _codecs_utf_16_le_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
2006 {
2007     PyObject *return_value = NULL;
2008     PyObject *str;
2009     const char *errors = NULL;
2010 
2011     if (!_PyArg_CheckPositional("utf_16_le_encode", nargs, 1, 2)) {
2012         goto exit;
2013     }
2014     if (!PyUnicode_Check(args[0])) {
2015         _PyArg_BadArgument("utf_16_le_encode", "argument 1", "str", args[0]);
2016         goto exit;
2017     }
2018     if (PyUnicode_READY(args[0]) == -1) {
2019         goto exit;
2020     }
2021     str = args[0];
2022     if (nargs < 2) {
2023         goto skip_optional;
2024     }
2025     if (args[1] == Py_None) {
2026         errors = NULL;
2027     }
2028     else if (PyUnicode_Check(args[1])) {
2029         Py_ssize_t errors_length;
2030         errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
2031         if (errors == NULL) {
2032             goto exit;
2033         }
2034         if (strlen(errors) != (size_t)errors_length) {
2035             PyErr_SetString(PyExc_ValueError, "embedded null character");
2036             goto exit;
2037         }
2038     }
2039     else {
2040         _PyArg_BadArgument("utf_16_le_encode", "argument 2", "str or None", args[1]);
2041         goto exit;
2042     }
2043 skip_optional:
2044     return_value = _codecs_utf_16_le_encode_impl(module, str, errors);
2045 
2046 exit:
2047     return return_value;
2048 }
2049 
2050 PyDoc_STRVAR(_codecs_utf_16_be_encode__doc__,
2051 "utf_16_be_encode($module, str, errors=None, /)\n"
2052 "--\n"
2053 "\n");
2054 
2055 #define _CODECS_UTF_16_BE_ENCODE_METHODDEF    \
2056     {"utf_16_be_encode", (PyCFunction)(void(*)(void))_codecs_utf_16_be_encode, METH_FASTCALL, _codecs_utf_16_be_encode__doc__},
2057 
2058 static PyObject *
2059 _codecs_utf_16_be_encode_impl(PyObject *module, PyObject *str,
2060                               const char *errors);
2061 
2062 static PyObject *
_codecs_utf_16_be_encode(PyObject * module,PyObject * const * args,Py_ssize_t nargs)2063 _codecs_utf_16_be_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
2064 {
2065     PyObject *return_value = NULL;
2066     PyObject *str;
2067     const char *errors = NULL;
2068 
2069     if (!_PyArg_CheckPositional("utf_16_be_encode", nargs, 1, 2)) {
2070         goto exit;
2071     }
2072     if (!PyUnicode_Check(args[0])) {
2073         _PyArg_BadArgument("utf_16_be_encode", "argument 1", "str", args[0]);
2074         goto exit;
2075     }
2076     if (PyUnicode_READY(args[0]) == -1) {
2077         goto exit;
2078     }
2079     str = args[0];
2080     if (nargs < 2) {
2081         goto skip_optional;
2082     }
2083     if (args[1] == Py_None) {
2084         errors = NULL;
2085     }
2086     else if (PyUnicode_Check(args[1])) {
2087         Py_ssize_t errors_length;
2088         errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
2089         if (errors == NULL) {
2090             goto exit;
2091         }
2092         if (strlen(errors) != (size_t)errors_length) {
2093             PyErr_SetString(PyExc_ValueError, "embedded null character");
2094             goto exit;
2095         }
2096     }
2097     else {
2098         _PyArg_BadArgument("utf_16_be_encode", "argument 2", "str or None", args[1]);
2099         goto exit;
2100     }
2101 skip_optional:
2102     return_value = _codecs_utf_16_be_encode_impl(module, str, errors);
2103 
2104 exit:
2105     return return_value;
2106 }
2107 
2108 PyDoc_STRVAR(_codecs_utf_32_encode__doc__,
2109 "utf_32_encode($module, str, errors=None, byteorder=0, /)\n"
2110 "--\n"
2111 "\n");
2112 
2113 #define _CODECS_UTF_32_ENCODE_METHODDEF    \
2114     {"utf_32_encode", (PyCFunction)(void(*)(void))_codecs_utf_32_encode, METH_FASTCALL, _codecs_utf_32_encode__doc__},
2115 
2116 static PyObject *
2117 _codecs_utf_32_encode_impl(PyObject *module, PyObject *str,
2118                            const char *errors, int byteorder);
2119 
2120 static PyObject *
_codecs_utf_32_encode(PyObject * module,PyObject * const * args,Py_ssize_t nargs)2121 _codecs_utf_32_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
2122 {
2123     PyObject *return_value = NULL;
2124     PyObject *str;
2125     const char *errors = NULL;
2126     int byteorder = 0;
2127 
2128     if (!_PyArg_CheckPositional("utf_32_encode", nargs, 1, 3)) {
2129         goto exit;
2130     }
2131     if (!PyUnicode_Check(args[0])) {
2132         _PyArg_BadArgument("utf_32_encode", "argument 1", "str", args[0]);
2133         goto exit;
2134     }
2135     if (PyUnicode_READY(args[0]) == -1) {
2136         goto exit;
2137     }
2138     str = args[0];
2139     if (nargs < 2) {
2140         goto skip_optional;
2141     }
2142     if (args[1] == Py_None) {
2143         errors = NULL;
2144     }
2145     else if (PyUnicode_Check(args[1])) {
2146         Py_ssize_t errors_length;
2147         errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
2148         if (errors == NULL) {
2149             goto exit;
2150         }
2151         if (strlen(errors) != (size_t)errors_length) {
2152             PyErr_SetString(PyExc_ValueError, "embedded null character");
2153             goto exit;
2154         }
2155     }
2156     else {
2157         _PyArg_BadArgument("utf_32_encode", "argument 2", "str or None", args[1]);
2158         goto exit;
2159     }
2160     if (nargs < 3) {
2161         goto skip_optional;
2162     }
2163     if (PyFloat_Check(args[2])) {
2164         PyErr_SetString(PyExc_TypeError,
2165                         "integer argument expected, got float" );
2166         goto exit;
2167     }
2168     byteorder = _PyLong_AsInt(args[2]);
2169     if (byteorder == -1 && PyErr_Occurred()) {
2170         goto exit;
2171     }
2172 skip_optional:
2173     return_value = _codecs_utf_32_encode_impl(module, str, errors, byteorder);
2174 
2175 exit:
2176     return return_value;
2177 }
2178 
2179 PyDoc_STRVAR(_codecs_utf_32_le_encode__doc__,
2180 "utf_32_le_encode($module, str, errors=None, /)\n"
2181 "--\n"
2182 "\n");
2183 
2184 #define _CODECS_UTF_32_LE_ENCODE_METHODDEF    \
2185     {"utf_32_le_encode", (PyCFunction)(void(*)(void))_codecs_utf_32_le_encode, METH_FASTCALL, _codecs_utf_32_le_encode__doc__},
2186 
2187 static PyObject *
2188 _codecs_utf_32_le_encode_impl(PyObject *module, PyObject *str,
2189                               const char *errors);
2190 
2191 static PyObject *
_codecs_utf_32_le_encode(PyObject * module,PyObject * const * args,Py_ssize_t nargs)2192 _codecs_utf_32_le_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
2193 {
2194     PyObject *return_value = NULL;
2195     PyObject *str;
2196     const char *errors = NULL;
2197 
2198     if (!_PyArg_CheckPositional("utf_32_le_encode", nargs, 1, 2)) {
2199         goto exit;
2200     }
2201     if (!PyUnicode_Check(args[0])) {
2202         _PyArg_BadArgument("utf_32_le_encode", "argument 1", "str", args[0]);
2203         goto exit;
2204     }
2205     if (PyUnicode_READY(args[0]) == -1) {
2206         goto exit;
2207     }
2208     str = args[0];
2209     if (nargs < 2) {
2210         goto skip_optional;
2211     }
2212     if (args[1] == Py_None) {
2213         errors = NULL;
2214     }
2215     else if (PyUnicode_Check(args[1])) {
2216         Py_ssize_t errors_length;
2217         errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
2218         if (errors == NULL) {
2219             goto exit;
2220         }
2221         if (strlen(errors) != (size_t)errors_length) {
2222             PyErr_SetString(PyExc_ValueError, "embedded null character");
2223             goto exit;
2224         }
2225     }
2226     else {
2227         _PyArg_BadArgument("utf_32_le_encode", "argument 2", "str or None", args[1]);
2228         goto exit;
2229     }
2230 skip_optional:
2231     return_value = _codecs_utf_32_le_encode_impl(module, str, errors);
2232 
2233 exit:
2234     return return_value;
2235 }
2236 
2237 PyDoc_STRVAR(_codecs_utf_32_be_encode__doc__,
2238 "utf_32_be_encode($module, str, errors=None, /)\n"
2239 "--\n"
2240 "\n");
2241 
2242 #define _CODECS_UTF_32_BE_ENCODE_METHODDEF    \
2243     {"utf_32_be_encode", (PyCFunction)(void(*)(void))_codecs_utf_32_be_encode, METH_FASTCALL, _codecs_utf_32_be_encode__doc__},
2244 
2245 static PyObject *
2246 _codecs_utf_32_be_encode_impl(PyObject *module, PyObject *str,
2247                               const char *errors);
2248 
2249 static PyObject *
_codecs_utf_32_be_encode(PyObject * module,PyObject * const * args,Py_ssize_t nargs)2250 _codecs_utf_32_be_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
2251 {
2252     PyObject *return_value = NULL;
2253     PyObject *str;
2254     const char *errors = NULL;
2255 
2256     if (!_PyArg_CheckPositional("utf_32_be_encode", nargs, 1, 2)) {
2257         goto exit;
2258     }
2259     if (!PyUnicode_Check(args[0])) {
2260         _PyArg_BadArgument("utf_32_be_encode", "argument 1", "str", args[0]);
2261         goto exit;
2262     }
2263     if (PyUnicode_READY(args[0]) == -1) {
2264         goto exit;
2265     }
2266     str = args[0];
2267     if (nargs < 2) {
2268         goto skip_optional;
2269     }
2270     if (args[1] == Py_None) {
2271         errors = NULL;
2272     }
2273     else if (PyUnicode_Check(args[1])) {
2274         Py_ssize_t errors_length;
2275         errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
2276         if (errors == NULL) {
2277             goto exit;
2278         }
2279         if (strlen(errors) != (size_t)errors_length) {
2280             PyErr_SetString(PyExc_ValueError, "embedded null character");
2281             goto exit;
2282         }
2283     }
2284     else {
2285         _PyArg_BadArgument("utf_32_be_encode", "argument 2", "str or None", args[1]);
2286         goto exit;
2287     }
2288 skip_optional:
2289     return_value = _codecs_utf_32_be_encode_impl(module, str, errors);
2290 
2291 exit:
2292     return return_value;
2293 }
2294 
2295 PyDoc_STRVAR(_codecs_unicode_escape_encode__doc__,
2296 "unicode_escape_encode($module, str, errors=None, /)\n"
2297 "--\n"
2298 "\n");
2299 
2300 #define _CODECS_UNICODE_ESCAPE_ENCODE_METHODDEF    \
2301     {"unicode_escape_encode", (PyCFunction)(void(*)(void))_codecs_unicode_escape_encode, METH_FASTCALL, _codecs_unicode_escape_encode__doc__},
2302 
2303 static PyObject *
2304 _codecs_unicode_escape_encode_impl(PyObject *module, PyObject *str,
2305                                    const char *errors);
2306 
2307 static PyObject *
_codecs_unicode_escape_encode(PyObject * module,PyObject * const * args,Py_ssize_t nargs)2308 _codecs_unicode_escape_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
2309 {
2310     PyObject *return_value = NULL;
2311     PyObject *str;
2312     const char *errors = NULL;
2313 
2314     if (!_PyArg_CheckPositional("unicode_escape_encode", nargs, 1, 2)) {
2315         goto exit;
2316     }
2317     if (!PyUnicode_Check(args[0])) {
2318         _PyArg_BadArgument("unicode_escape_encode", "argument 1", "str", args[0]);
2319         goto exit;
2320     }
2321     if (PyUnicode_READY(args[0]) == -1) {
2322         goto exit;
2323     }
2324     str = args[0];
2325     if (nargs < 2) {
2326         goto skip_optional;
2327     }
2328     if (args[1] == Py_None) {
2329         errors = NULL;
2330     }
2331     else if (PyUnicode_Check(args[1])) {
2332         Py_ssize_t errors_length;
2333         errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
2334         if (errors == NULL) {
2335             goto exit;
2336         }
2337         if (strlen(errors) != (size_t)errors_length) {
2338             PyErr_SetString(PyExc_ValueError, "embedded null character");
2339             goto exit;
2340         }
2341     }
2342     else {
2343         _PyArg_BadArgument("unicode_escape_encode", "argument 2", "str or None", args[1]);
2344         goto exit;
2345     }
2346 skip_optional:
2347     return_value = _codecs_unicode_escape_encode_impl(module, str, errors);
2348 
2349 exit:
2350     return return_value;
2351 }
2352 
2353 PyDoc_STRVAR(_codecs_raw_unicode_escape_encode__doc__,
2354 "raw_unicode_escape_encode($module, str, errors=None, /)\n"
2355 "--\n"
2356 "\n");
2357 
2358 #define _CODECS_RAW_UNICODE_ESCAPE_ENCODE_METHODDEF    \
2359     {"raw_unicode_escape_encode", (PyCFunction)(void(*)(void))_codecs_raw_unicode_escape_encode, METH_FASTCALL, _codecs_raw_unicode_escape_encode__doc__},
2360 
2361 static PyObject *
2362 _codecs_raw_unicode_escape_encode_impl(PyObject *module, PyObject *str,
2363                                        const char *errors);
2364 
2365 static PyObject *
_codecs_raw_unicode_escape_encode(PyObject * module,PyObject * const * args,Py_ssize_t nargs)2366 _codecs_raw_unicode_escape_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
2367 {
2368     PyObject *return_value = NULL;
2369     PyObject *str;
2370     const char *errors = NULL;
2371 
2372     if (!_PyArg_CheckPositional("raw_unicode_escape_encode", nargs, 1, 2)) {
2373         goto exit;
2374     }
2375     if (!PyUnicode_Check(args[0])) {
2376         _PyArg_BadArgument("raw_unicode_escape_encode", "argument 1", "str", args[0]);
2377         goto exit;
2378     }
2379     if (PyUnicode_READY(args[0]) == -1) {
2380         goto exit;
2381     }
2382     str = args[0];
2383     if (nargs < 2) {
2384         goto skip_optional;
2385     }
2386     if (args[1] == Py_None) {
2387         errors = NULL;
2388     }
2389     else if (PyUnicode_Check(args[1])) {
2390         Py_ssize_t errors_length;
2391         errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
2392         if (errors == NULL) {
2393             goto exit;
2394         }
2395         if (strlen(errors) != (size_t)errors_length) {
2396             PyErr_SetString(PyExc_ValueError, "embedded null character");
2397             goto exit;
2398         }
2399     }
2400     else {
2401         _PyArg_BadArgument("raw_unicode_escape_encode", "argument 2", "str or None", args[1]);
2402         goto exit;
2403     }
2404 skip_optional:
2405     return_value = _codecs_raw_unicode_escape_encode_impl(module, str, errors);
2406 
2407 exit:
2408     return return_value;
2409 }
2410 
2411 PyDoc_STRVAR(_codecs_latin_1_encode__doc__,
2412 "latin_1_encode($module, str, errors=None, /)\n"
2413 "--\n"
2414 "\n");
2415 
2416 #define _CODECS_LATIN_1_ENCODE_METHODDEF    \
2417     {"latin_1_encode", (PyCFunction)(void(*)(void))_codecs_latin_1_encode, METH_FASTCALL, _codecs_latin_1_encode__doc__},
2418 
2419 static PyObject *
2420 _codecs_latin_1_encode_impl(PyObject *module, PyObject *str,
2421                             const char *errors);
2422 
2423 static PyObject *
_codecs_latin_1_encode(PyObject * module,PyObject * const * args,Py_ssize_t nargs)2424 _codecs_latin_1_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
2425 {
2426     PyObject *return_value = NULL;
2427     PyObject *str;
2428     const char *errors = NULL;
2429 
2430     if (!_PyArg_CheckPositional("latin_1_encode", nargs, 1, 2)) {
2431         goto exit;
2432     }
2433     if (!PyUnicode_Check(args[0])) {
2434         _PyArg_BadArgument("latin_1_encode", "argument 1", "str", args[0]);
2435         goto exit;
2436     }
2437     if (PyUnicode_READY(args[0]) == -1) {
2438         goto exit;
2439     }
2440     str = args[0];
2441     if (nargs < 2) {
2442         goto skip_optional;
2443     }
2444     if (args[1] == Py_None) {
2445         errors = NULL;
2446     }
2447     else if (PyUnicode_Check(args[1])) {
2448         Py_ssize_t errors_length;
2449         errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
2450         if (errors == NULL) {
2451             goto exit;
2452         }
2453         if (strlen(errors) != (size_t)errors_length) {
2454             PyErr_SetString(PyExc_ValueError, "embedded null character");
2455             goto exit;
2456         }
2457     }
2458     else {
2459         _PyArg_BadArgument("latin_1_encode", "argument 2", "str or None", args[1]);
2460         goto exit;
2461     }
2462 skip_optional:
2463     return_value = _codecs_latin_1_encode_impl(module, str, errors);
2464 
2465 exit:
2466     return return_value;
2467 }
2468 
2469 PyDoc_STRVAR(_codecs_ascii_encode__doc__,
2470 "ascii_encode($module, str, errors=None, /)\n"
2471 "--\n"
2472 "\n");
2473 
2474 #define _CODECS_ASCII_ENCODE_METHODDEF    \
2475     {"ascii_encode", (PyCFunction)(void(*)(void))_codecs_ascii_encode, METH_FASTCALL, _codecs_ascii_encode__doc__},
2476 
2477 static PyObject *
2478 _codecs_ascii_encode_impl(PyObject *module, PyObject *str,
2479                           const char *errors);
2480 
2481 static PyObject *
_codecs_ascii_encode(PyObject * module,PyObject * const * args,Py_ssize_t nargs)2482 _codecs_ascii_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
2483 {
2484     PyObject *return_value = NULL;
2485     PyObject *str;
2486     const char *errors = NULL;
2487 
2488     if (!_PyArg_CheckPositional("ascii_encode", nargs, 1, 2)) {
2489         goto exit;
2490     }
2491     if (!PyUnicode_Check(args[0])) {
2492         _PyArg_BadArgument("ascii_encode", "argument 1", "str", args[0]);
2493         goto exit;
2494     }
2495     if (PyUnicode_READY(args[0]) == -1) {
2496         goto exit;
2497     }
2498     str = args[0];
2499     if (nargs < 2) {
2500         goto skip_optional;
2501     }
2502     if (args[1] == Py_None) {
2503         errors = NULL;
2504     }
2505     else if (PyUnicode_Check(args[1])) {
2506         Py_ssize_t errors_length;
2507         errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
2508         if (errors == NULL) {
2509             goto exit;
2510         }
2511         if (strlen(errors) != (size_t)errors_length) {
2512             PyErr_SetString(PyExc_ValueError, "embedded null character");
2513             goto exit;
2514         }
2515     }
2516     else {
2517         _PyArg_BadArgument("ascii_encode", "argument 2", "str or None", args[1]);
2518         goto exit;
2519     }
2520 skip_optional:
2521     return_value = _codecs_ascii_encode_impl(module, str, errors);
2522 
2523 exit:
2524     return return_value;
2525 }
2526 
2527 PyDoc_STRVAR(_codecs_charmap_encode__doc__,
2528 "charmap_encode($module, str, errors=None, mapping=None, /)\n"
2529 "--\n"
2530 "\n");
2531 
2532 #define _CODECS_CHARMAP_ENCODE_METHODDEF    \
2533     {"charmap_encode", (PyCFunction)(void(*)(void))_codecs_charmap_encode, METH_FASTCALL, _codecs_charmap_encode__doc__},
2534 
2535 static PyObject *
2536 _codecs_charmap_encode_impl(PyObject *module, PyObject *str,
2537                             const char *errors, PyObject *mapping);
2538 
2539 static PyObject *
_codecs_charmap_encode(PyObject * module,PyObject * const * args,Py_ssize_t nargs)2540 _codecs_charmap_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
2541 {
2542     PyObject *return_value = NULL;
2543     PyObject *str;
2544     const char *errors = NULL;
2545     PyObject *mapping = Py_None;
2546 
2547     if (!_PyArg_CheckPositional("charmap_encode", nargs, 1, 3)) {
2548         goto exit;
2549     }
2550     if (!PyUnicode_Check(args[0])) {
2551         _PyArg_BadArgument("charmap_encode", "argument 1", "str", args[0]);
2552         goto exit;
2553     }
2554     if (PyUnicode_READY(args[0]) == -1) {
2555         goto exit;
2556     }
2557     str = args[0];
2558     if (nargs < 2) {
2559         goto skip_optional;
2560     }
2561     if (args[1] == Py_None) {
2562         errors = NULL;
2563     }
2564     else if (PyUnicode_Check(args[1])) {
2565         Py_ssize_t errors_length;
2566         errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
2567         if (errors == NULL) {
2568             goto exit;
2569         }
2570         if (strlen(errors) != (size_t)errors_length) {
2571             PyErr_SetString(PyExc_ValueError, "embedded null character");
2572             goto exit;
2573         }
2574     }
2575     else {
2576         _PyArg_BadArgument("charmap_encode", "argument 2", "str or None", args[1]);
2577         goto exit;
2578     }
2579     if (nargs < 3) {
2580         goto skip_optional;
2581     }
2582     mapping = args[2];
2583 skip_optional:
2584     return_value = _codecs_charmap_encode_impl(module, str, errors, mapping);
2585 
2586 exit:
2587     return return_value;
2588 }
2589 
2590 PyDoc_STRVAR(_codecs_charmap_build__doc__,
2591 "charmap_build($module, map, /)\n"
2592 "--\n"
2593 "\n");
2594 
2595 #define _CODECS_CHARMAP_BUILD_METHODDEF    \
2596     {"charmap_build", (PyCFunction)_codecs_charmap_build, METH_O, _codecs_charmap_build__doc__},
2597 
2598 static PyObject *
2599 _codecs_charmap_build_impl(PyObject *module, PyObject *map);
2600 
2601 static PyObject *
_codecs_charmap_build(PyObject * module,PyObject * arg)2602 _codecs_charmap_build(PyObject *module, PyObject *arg)
2603 {
2604     PyObject *return_value = NULL;
2605     PyObject *map;
2606 
2607     if (!PyUnicode_Check(arg)) {
2608         _PyArg_BadArgument("charmap_build", "argument", "str", arg);
2609         goto exit;
2610     }
2611     if (PyUnicode_READY(arg) == -1) {
2612         goto exit;
2613     }
2614     map = arg;
2615     return_value = _codecs_charmap_build_impl(module, map);
2616 
2617 exit:
2618     return return_value;
2619 }
2620 
2621 #if defined(MS_WINDOWS)
2622 
2623 PyDoc_STRVAR(_codecs_mbcs_encode__doc__,
2624 "mbcs_encode($module, str, errors=None, /)\n"
2625 "--\n"
2626 "\n");
2627 
2628 #define _CODECS_MBCS_ENCODE_METHODDEF    \
2629     {"mbcs_encode", (PyCFunction)(void(*)(void))_codecs_mbcs_encode, METH_FASTCALL, _codecs_mbcs_encode__doc__},
2630 
2631 static PyObject *
2632 _codecs_mbcs_encode_impl(PyObject *module, PyObject *str, const char *errors);
2633 
2634 static PyObject *
_codecs_mbcs_encode(PyObject * module,PyObject * const * args,Py_ssize_t nargs)2635 _codecs_mbcs_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
2636 {
2637     PyObject *return_value = NULL;
2638     PyObject *str;
2639     const char *errors = NULL;
2640 
2641     if (!_PyArg_CheckPositional("mbcs_encode", nargs, 1, 2)) {
2642         goto exit;
2643     }
2644     if (!PyUnicode_Check(args[0])) {
2645         _PyArg_BadArgument("mbcs_encode", "argument 1", "str", args[0]);
2646         goto exit;
2647     }
2648     if (PyUnicode_READY(args[0]) == -1) {
2649         goto exit;
2650     }
2651     str = args[0];
2652     if (nargs < 2) {
2653         goto skip_optional;
2654     }
2655     if (args[1] == Py_None) {
2656         errors = NULL;
2657     }
2658     else if (PyUnicode_Check(args[1])) {
2659         Py_ssize_t errors_length;
2660         errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
2661         if (errors == NULL) {
2662             goto exit;
2663         }
2664         if (strlen(errors) != (size_t)errors_length) {
2665             PyErr_SetString(PyExc_ValueError, "embedded null character");
2666             goto exit;
2667         }
2668     }
2669     else {
2670         _PyArg_BadArgument("mbcs_encode", "argument 2", "str or None", args[1]);
2671         goto exit;
2672     }
2673 skip_optional:
2674     return_value = _codecs_mbcs_encode_impl(module, str, errors);
2675 
2676 exit:
2677     return return_value;
2678 }
2679 
2680 #endif /* defined(MS_WINDOWS) */
2681 
2682 #if defined(MS_WINDOWS)
2683 
2684 PyDoc_STRVAR(_codecs_oem_encode__doc__,
2685 "oem_encode($module, str, errors=None, /)\n"
2686 "--\n"
2687 "\n");
2688 
2689 #define _CODECS_OEM_ENCODE_METHODDEF    \
2690     {"oem_encode", (PyCFunction)(void(*)(void))_codecs_oem_encode, METH_FASTCALL, _codecs_oem_encode__doc__},
2691 
2692 static PyObject *
2693 _codecs_oem_encode_impl(PyObject *module, PyObject *str, const char *errors);
2694 
2695 static PyObject *
_codecs_oem_encode(PyObject * module,PyObject * const * args,Py_ssize_t nargs)2696 _codecs_oem_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
2697 {
2698     PyObject *return_value = NULL;
2699     PyObject *str;
2700     const char *errors = NULL;
2701 
2702     if (!_PyArg_CheckPositional("oem_encode", nargs, 1, 2)) {
2703         goto exit;
2704     }
2705     if (!PyUnicode_Check(args[0])) {
2706         _PyArg_BadArgument("oem_encode", "argument 1", "str", args[0]);
2707         goto exit;
2708     }
2709     if (PyUnicode_READY(args[0]) == -1) {
2710         goto exit;
2711     }
2712     str = args[0];
2713     if (nargs < 2) {
2714         goto skip_optional;
2715     }
2716     if (args[1] == Py_None) {
2717         errors = NULL;
2718     }
2719     else if (PyUnicode_Check(args[1])) {
2720         Py_ssize_t errors_length;
2721         errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
2722         if (errors == NULL) {
2723             goto exit;
2724         }
2725         if (strlen(errors) != (size_t)errors_length) {
2726             PyErr_SetString(PyExc_ValueError, "embedded null character");
2727             goto exit;
2728         }
2729     }
2730     else {
2731         _PyArg_BadArgument("oem_encode", "argument 2", "str or None", args[1]);
2732         goto exit;
2733     }
2734 skip_optional:
2735     return_value = _codecs_oem_encode_impl(module, str, errors);
2736 
2737 exit:
2738     return return_value;
2739 }
2740 
2741 #endif /* defined(MS_WINDOWS) */
2742 
2743 #if defined(MS_WINDOWS)
2744 
2745 PyDoc_STRVAR(_codecs_code_page_encode__doc__,
2746 "code_page_encode($module, code_page, str, errors=None, /)\n"
2747 "--\n"
2748 "\n");
2749 
2750 #define _CODECS_CODE_PAGE_ENCODE_METHODDEF    \
2751     {"code_page_encode", (PyCFunction)(void(*)(void))_codecs_code_page_encode, METH_FASTCALL, _codecs_code_page_encode__doc__},
2752 
2753 static PyObject *
2754 _codecs_code_page_encode_impl(PyObject *module, int code_page, PyObject *str,
2755                               const char *errors);
2756 
2757 static PyObject *
_codecs_code_page_encode(PyObject * module,PyObject * const * args,Py_ssize_t nargs)2758 _codecs_code_page_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
2759 {
2760     PyObject *return_value = NULL;
2761     int code_page;
2762     PyObject *str;
2763     const char *errors = NULL;
2764 
2765     if (!_PyArg_CheckPositional("code_page_encode", nargs, 2, 3)) {
2766         goto exit;
2767     }
2768     if (PyFloat_Check(args[0])) {
2769         PyErr_SetString(PyExc_TypeError,
2770                         "integer argument expected, got float" );
2771         goto exit;
2772     }
2773     code_page = _PyLong_AsInt(args[0]);
2774     if (code_page == -1 && PyErr_Occurred()) {
2775         goto exit;
2776     }
2777     if (!PyUnicode_Check(args[1])) {
2778         _PyArg_BadArgument("code_page_encode", "argument 2", "str", args[1]);
2779         goto exit;
2780     }
2781     if (PyUnicode_READY(args[1]) == -1) {
2782         goto exit;
2783     }
2784     str = args[1];
2785     if (nargs < 3) {
2786         goto skip_optional;
2787     }
2788     if (args[2] == Py_None) {
2789         errors = NULL;
2790     }
2791     else if (PyUnicode_Check(args[2])) {
2792         Py_ssize_t errors_length;
2793         errors = PyUnicode_AsUTF8AndSize(args[2], &errors_length);
2794         if (errors == NULL) {
2795             goto exit;
2796         }
2797         if (strlen(errors) != (size_t)errors_length) {
2798             PyErr_SetString(PyExc_ValueError, "embedded null character");
2799             goto exit;
2800         }
2801     }
2802     else {
2803         _PyArg_BadArgument("code_page_encode", "argument 3", "str or None", args[2]);
2804         goto exit;
2805     }
2806 skip_optional:
2807     return_value = _codecs_code_page_encode_impl(module, code_page, str, errors);
2808 
2809 exit:
2810     return return_value;
2811 }
2812 
2813 #endif /* defined(MS_WINDOWS) */
2814 
2815 PyDoc_STRVAR(_codecs_register_error__doc__,
2816 "register_error($module, errors, handler, /)\n"
2817 "--\n"
2818 "\n"
2819 "Register the specified error handler under the name errors.\n"
2820 "\n"
2821 "handler must be a callable object, that will be called with an exception\n"
2822 "instance containing information about the location of the encoding/decoding\n"
2823 "error and must return a (replacement, new position) tuple.");
2824 
2825 #define _CODECS_REGISTER_ERROR_METHODDEF    \
2826     {"register_error", (PyCFunction)(void(*)(void))_codecs_register_error, METH_FASTCALL, _codecs_register_error__doc__},
2827 
2828 static PyObject *
2829 _codecs_register_error_impl(PyObject *module, const char *errors,
2830                             PyObject *handler);
2831 
2832 static PyObject *
_codecs_register_error(PyObject * module,PyObject * const * args,Py_ssize_t nargs)2833 _codecs_register_error(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
2834 {
2835     PyObject *return_value = NULL;
2836     const char *errors;
2837     PyObject *handler;
2838 
2839     if (!_PyArg_CheckPositional("register_error", nargs, 2, 2)) {
2840         goto exit;
2841     }
2842     if (!PyUnicode_Check(args[0])) {
2843         _PyArg_BadArgument("register_error", "argument 1", "str", args[0]);
2844         goto exit;
2845     }
2846     Py_ssize_t errors_length;
2847     errors = PyUnicode_AsUTF8AndSize(args[0], &errors_length);
2848     if (errors == NULL) {
2849         goto exit;
2850     }
2851     if (strlen(errors) != (size_t)errors_length) {
2852         PyErr_SetString(PyExc_ValueError, "embedded null character");
2853         goto exit;
2854     }
2855     handler = args[1];
2856     return_value = _codecs_register_error_impl(module, errors, handler);
2857 
2858 exit:
2859     return return_value;
2860 }
2861 
2862 PyDoc_STRVAR(_codecs_lookup_error__doc__,
2863 "lookup_error($module, name, /)\n"
2864 "--\n"
2865 "\n"
2866 "lookup_error(errors) -> handler\n"
2867 "\n"
2868 "Return the error handler for the specified error handling name or raise a\n"
2869 "LookupError, if no handler exists under this name.");
2870 
2871 #define _CODECS_LOOKUP_ERROR_METHODDEF    \
2872     {"lookup_error", (PyCFunction)_codecs_lookup_error, METH_O, _codecs_lookup_error__doc__},
2873 
2874 static PyObject *
2875 _codecs_lookup_error_impl(PyObject *module, const char *name);
2876 
2877 static PyObject *
_codecs_lookup_error(PyObject * module,PyObject * arg)2878 _codecs_lookup_error(PyObject *module, PyObject *arg)
2879 {
2880     PyObject *return_value = NULL;
2881     const char *name;
2882 
2883     if (!PyUnicode_Check(arg)) {
2884         _PyArg_BadArgument("lookup_error", "argument", "str", arg);
2885         goto exit;
2886     }
2887     Py_ssize_t name_length;
2888     name = PyUnicode_AsUTF8AndSize(arg, &name_length);
2889     if (name == NULL) {
2890         goto exit;
2891     }
2892     if (strlen(name) != (size_t)name_length) {
2893         PyErr_SetString(PyExc_ValueError, "embedded null character");
2894         goto exit;
2895     }
2896     return_value = _codecs_lookup_error_impl(module, name);
2897 
2898 exit:
2899     return return_value;
2900 }
2901 
2902 #ifndef _CODECS_MBCS_DECODE_METHODDEF
2903     #define _CODECS_MBCS_DECODE_METHODDEF
2904 #endif /* !defined(_CODECS_MBCS_DECODE_METHODDEF) */
2905 
2906 #ifndef _CODECS_OEM_DECODE_METHODDEF
2907     #define _CODECS_OEM_DECODE_METHODDEF
2908 #endif /* !defined(_CODECS_OEM_DECODE_METHODDEF) */
2909 
2910 #ifndef _CODECS_CODE_PAGE_DECODE_METHODDEF
2911     #define _CODECS_CODE_PAGE_DECODE_METHODDEF
2912 #endif /* !defined(_CODECS_CODE_PAGE_DECODE_METHODDEF) */
2913 
2914 #ifndef _CODECS_MBCS_ENCODE_METHODDEF
2915     #define _CODECS_MBCS_ENCODE_METHODDEF
2916 #endif /* !defined(_CODECS_MBCS_ENCODE_METHODDEF) */
2917 
2918 #ifndef _CODECS_OEM_ENCODE_METHODDEF
2919     #define _CODECS_OEM_ENCODE_METHODDEF
2920 #endif /* !defined(_CODECS_OEM_ENCODE_METHODDEF) */
2921 
2922 #ifndef _CODECS_CODE_PAGE_ENCODE_METHODDEF
2923     #define _CODECS_CODE_PAGE_ENCODE_METHODDEF
2924 #endif /* !defined(_CODECS_CODE_PAGE_ENCODE_METHODDEF) */
2925 /*[clinic end generated code: output=51b42d170889524c input=a9049054013a1b77]*/
2926