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