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