Debian Codegraph @

Modules/clinic/_codecsmodule.c.h

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