Coverage Report

Created: 2025-07-04 06:49

/src/cpython/Modules/clinic/_codecsmodule.c.h
Line
Count
Source (jump to first uncovered line)
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
0
{
50
0
    PyObject *return_value = NULL;
51
0
    const char *encoding;
52
53
0
    if (!PyUnicode_Check(arg)) {
54
0
        _PyArg_BadArgument("lookup", "argument", "str", arg);
55
0
        goto exit;
56
0
    }
57
0
    Py_ssize_t encoding_length;
58
0
    encoding = PyUnicode_AsUTF8AndSize(arg, &encoding_length);
59
0
    if (encoding == NULL) {
60
0
        goto exit;
61
0
    }
62
0
    if (strlen(encoding) != (size_t)encoding_length) {
63
0
        PyErr_SetString(PyExc_ValueError, "embedded null character");
64
0
        goto exit;
65
0
    }
66
0
    return_value = _codecs_lookup_impl(module, encoding);
67
68
0
exit:
69
0
    return return_value;
70
0
}
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
0
{
94
0
    PyObject *return_value = NULL;
95
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
96
97
0
    #define NUM_KEYWORDS 3
98
0
    static struct {
99
0
        PyGC_Head _this_is_not_used;
100
0
        PyObject_VAR_HEAD
101
0
        Py_hash_t ob_hash;
102
0
        PyObject *ob_item[NUM_KEYWORDS];
103
0
    } _kwtuple = {
104
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
105
0
        .ob_hash = -1,
106
0
        .ob_item = { &_Py_ID(obj), &_Py_ID(encoding), &_Py_ID(errors), },
107
0
    };
108
0
    #undef NUM_KEYWORDS
109
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
110
111
    #else  // !Py_BUILD_CORE
112
    #  define KWTUPLE NULL
113
    #endif  // !Py_BUILD_CORE
114
115
0
    static const char * const _keywords[] = {"obj", "encoding", "errors", NULL};
116
0
    static _PyArg_Parser _parser = {
117
0
        .keywords = _keywords,
118
0
        .fname = "encode",
119
0
        .kwtuple = KWTUPLE,
120
0
    };
121
0
    #undef KWTUPLE
122
0
    PyObject *argsbuf[3];
123
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
124
0
    PyObject *obj;
125
0
    const char *encoding = NULL;
126
0
    const char *errors = NULL;
127
128
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
129
0
            /*minpos*/ 1, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
130
0
    if (!args) {
131
0
        goto exit;
132
0
    }
133
0
    obj = args[0];
134
0
    if (!noptargs) {
135
0
        goto skip_optional_pos;
136
0
    }
137
0
    if (args[1]) {
138
0
        if (!PyUnicode_Check(args[1])) {
139
0
            _PyArg_BadArgument("encode", "argument 'encoding'", "str", args[1]);
140
0
            goto exit;
141
0
        }
142
0
        Py_ssize_t encoding_length;
143
0
        encoding = PyUnicode_AsUTF8AndSize(args[1], &encoding_length);
144
0
        if (encoding == NULL) {
145
0
            goto exit;
146
0
        }
147
0
        if (strlen(encoding) != (size_t)encoding_length) {
148
0
            PyErr_SetString(PyExc_ValueError, "embedded null character");
149
0
            goto exit;
150
0
        }
151
0
        if (!--noptargs) {
152
0
            goto skip_optional_pos;
153
0
        }
154
0
    }
155
0
    if (!PyUnicode_Check(args[2])) {
156
0
        _PyArg_BadArgument("encode", "argument 'errors'", "str", args[2]);
157
0
        goto exit;
158
0
    }
159
0
    Py_ssize_t errors_length;
160
0
    errors = PyUnicode_AsUTF8AndSize(args[2], &errors_length);
161
0
    if (errors == NULL) {
162
0
        goto exit;
163
0
    }
164
0
    if (strlen(errors) != (size_t)errors_length) {
165
0
        PyErr_SetString(PyExc_ValueError, "embedded null character");
166
0
        goto exit;
167
0
    }
168
0
skip_optional_pos:
169
0
    return_value = _codecs_encode_impl(module, obj, encoding, errors);
170
171
0
exit:
172
0
    return return_value;
173
0
}
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
0
{
197
0
    PyObject *return_value = NULL;
198
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
199
200
0
    #define NUM_KEYWORDS 3
201
0
    static struct {
202
0
        PyGC_Head _this_is_not_used;
203
0
        PyObject_VAR_HEAD
204
0
        Py_hash_t ob_hash;
205
0
        PyObject *ob_item[NUM_KEYWORDS];
206
0
    } _kwtuple = {
207
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
208
0
        .ob_hash = -1,
209
0
        .ob_item = { &_Py_ID(obj), &_Py_ID(encoding), &_Py_ID(errors), },
210
0
    };
211
0
    #undef NUM_KEYWORDS
212
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
213
214
    #else  // !Py_BUILD_CORE
215
    #  define KWTUPLE NULL
216
    #endif  // !Py_BUILD_CORE
217
218
0
    static const char * const _keywords[] = {"obj", "encoding", "errors", NULL};
219
0
    static _PyArg_Parser _parser = {
220
0
        .keywords = _keywords,
221
0
        .fname = "decode",
222
0
        .kwtuple = KWTUPLE,
223
0
    };
224
0
    #undef KWTUPLE
225
0
    PyObject *argsbuf[3];
226
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
227
0
    PyObject *obj;
228
0
    const char *encoding = NULL;
229
0
    const char *errors = NULL;
230
231
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
232
0
            /*minpos*/ 1, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
233
0
    if (!args) {
234
0
        goto exit;
235
0
    }
236
0
    obj = args[0];
237
0
    if (!noptargs) {
238
0
        goto skip_optional_pos;
239
0
    }
240
0
    if (args[1]) {
241
0
        if (!PyUnicode_Check(args[1])) {
242
0
            _PyArg_BadArgument("decode", "argument 'encoding'", "str", args[1]);
243
0
            goto exit;
244
0
        }
245
0
        Py_ssize_t encoding_length;
246
0
        encoding = PyUnicode_AsUTF8AndSize(args[1], &encoding_length);
247
0
        if (encoding == NULL) {
248
0
            goto exit;
249
0
        }
250
0
        if (strlen(encoding) != (size_t)encoding_length) {
251
0
            PyErr_SetString(PyExc_ValueError, "embedded null character");
252
0
            goto exit;
253
0
        }
254
0
        if (!--noptargs) {
255
0
            goto skip_optional_pos;
256
0
        }
257
0
    }
258
0
    if (!PyUnicode_Check(args[2])) {
259
0
        _PyArg_BadArgument("decode", "argument 'errors'", "str", args[2]);
260
0
        goto exit;
261
0
    }
262
0
    Py_ssize_t errors_length;
263
0
    errors = PyUnicode_AsUTF8AndSize(args[2], &errors_length);
264
0
    if (errors == NULL) {
265
0
        goto exit;
266
0
    }
267
0
    if (strlen(errors) != (size_t)errors_length) {
268
0
        PyErr_SetString(PyExc_ValueError, "embedded null character");
269
0
        goto exit;
270
0
    }
271
0
skip_optional_pos:
272
0
    return_value = _codecs_decode_impl(module, obj, encoding, errors);
273
274
0
exit:
275
0
    return return_value;
276
0
}
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
0
{
293
0
    PyObject *return_value = NULL;
294
0
    Py_buffer data = {NULL, NULL};
295
0
    const char *errors = NULL;
296
297
0
    if (!_PyArg_CheckPositional("escape_decode", nargs, 1, 2)) {
298
0
        goto exit;
299
0
    }
300
0
    if (PyUnicode_Check(args[0])) {
301
0
        Py_ssize_t len;
302
0
        const char *ptr = PyUnicode_AsUTF8AndSize(args[0], &len);
303
0
        if (ptr == NULL) {
304
0
            goto exit;
305
0
        }
306
0
        if (PyBuffer_FillInfo(&data, args[0], (void *)ptr, len, 1, PyBUF_SIMPLE) < 0) {
307
0
            goto exit;
308
0
        }
309
0
    }
310
0
    else { /* any bytes-like object */
311
0
        if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
312
0
            goto exit;
313
0
        }
314
0
    }
315
0
    if (nargs < 2) {
316
0
        goto skip_optional;
317
0
    }
318
0
    if (args[1] == Py_None) {
319
0
        errors = NULL;
320
0
    }
321
0
    else if (PyUnicode_Check(args[1])) {
322
0
        Py_ssize_t errors_length;
323
0
        errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
324
0
        if (errors == NULL) {
325
0
            goto exit;
326
0
        }
327
0
        if (strlen(errors) != (size_t)errors_length) {
328
0
            PyErr_SetString(PyExc_ValueError, "embedded null character");
329
0
            goto exit;
330
0
        }
331
0
    }
332
0
    else {
333
0
        _PyArg_BadArgument("escape_decode", "argument 2", "str or None", args[1]);
334
0
        goto exit;
335
0
    }
336
0
skip_optional:
337
0
    return_value = _codecs_escape_decode_impl(module, &data, errors);
338
339
0
exit:
340
    /* Cleanup for data */
341
0
    if (data.obj) {
342
0
       PyBuffer_Release(&data);
343
0
    }
344
345
0
    return return_value;
346
0
}
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
0
{
363
0
    PyObject *return_value = NULL;
364
0
    PyObject *data;
365
0
    const char *errors = NULL;
366
367
0
    if (!_PyArg_CheckPositional("escape_encode", nargs, 1, 2)) {
368
0
        goto exit;
369
0
    }
370
0
    if (!PyBytes_Check(args[0])) {
371
0
        _PyArg_BadArgument("escape_encode", "argument 1", "bytes", args[0]);
372
0
        goto exit;
373
0
    }
374
0
    data = args[0];
375
0
    if (nargs < 2) {
376
0
        goto skip_optional;
377
0
    }
378
0
    if (args[1] == Py_None) {
379
0
        errors = NULL;
380
0
    }
381
0
    else if (PyUnicode_Check(args[1])) {
382
0
        Py_ssize_t errors_length;
383
0
        errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
384
0
        if (errors == NULL) {
385
0
            goto exit;
386
0
        }
387
0
        if (strlen(errors) != (size_t)errors_length) {
388
0
            PyErr_SetString(PyExc_ValueError, "embedded null character");
389
0
            goto exit;
390
0
        }
391
0
    }
392
0
    else {
393
0
        _PyArg_BadArgument("escape_encode", "argument 2", "str or None", args[1]);
394
0
        goto exit;
395
0
    }
396
0
skip_optional:
397
0
    return_value = _codecs_escape_encode_impl(module, data, errors);
398
399
0
exit:
400
0
    return return_value;
401
0
}
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
20.6k
{
418
20.6k
    PyObject *return_value = NULL;
419
20.6k
    Py_buffer data = {NULL, NULL};
420
20.6k
    const char *errors = NULL;
421
20.6k
    int final = 0;
422
423
20.6k
    if (!_PyArg_CheckPositional("utf_7_decode", nargs, 1, 3)) {
424
0
        goto exit;
425
0
    }
426
20.6k
    if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
427
0
        goto exit;
428
0
    }
429
20.6k
    if (nargs < 2) {
430
0
        goto skip_optional;
431
0
    }
432
20.6k
    if (args[1] == Py_None) {
433
0
        errors = NULL;
434
0
    }
435
20.6k
    else if (PyUnicode_Check(args[1])) {
436
20.6k
        Py_ssize_t errors_length;
437
20.6k
        errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
438
20.6k
        if (errors == NULL) {
439
0
            goto exit;
440
0
        }
441
20.6k
        if (strlen(errors) != (size_t)errors_length) {
442
0
            PyErr_SetString(PyExc_ValueError, "embedded null character");
443
0
            goto exit;
444
0
        }
445
20.6k
    }
446
0
    else {
447
0
        _PyArg_BadArgument("utf_7_decode", "argument 2", "str or None", args[1]);
448
0
        goto exit;
449
0
    }
450
20.6k
    if (nargs < 3) {
451
0
        goto skip_optional;
452
0
    }
453
20.6k
    final = PyObject_IsTrue(args[2]);
454
20.6k
    if (final < 0) {
455
0
        goto exit;
456
0
    }
457
20.6k
skip_optional:
458
20.6k
    return_value = _codecs_utf_7_decode_impl(module, &data, errors, final);
459
460
20.6k
exit:
461
    /* Cleanup for data */
462
20.6k
    if (data.obj) {
463
20.6k
       PyBuffer_Release(&data);
464
20.6k
    }
465
466
20.6k
    return return_value;
467
20.6k
}
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
69.6k
{
484
69.6k
    PyObject *return_value = NULL;
485
69.6k
    Py_buffer data = {NULL, NULL};
486
69.6k
    const char *errors = NULL;
487
69.6k
    int final = 0;
488
489
69.6k
    if (!_PyArg_CheckPositional("utf_8_decode", nargs, 1, 3)) {
490
0
        goto exit;
491
0
    }
492
69.6k
    if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
493
0
        goto exit;
494
0
    }
495
69.6k
    if (nargs < 2) {
496
0
        goto skip_optional;
497
0
    }
498
69.6k
    if (args[1] == Py_None) {
499
0
        errors = NULL;
500
0
    }
501
69.6k
    else if (PyUnicode_Check(args[1])) {
502
69.6k
        Py_ssize_t errors_length;
503
69.6k
        errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
504
69.6k
        if (errors == NULL) {
505
0
            goto exit;
506
0
        }
507
69.6k
        if (strlen(errors) != (size_t)errors_length) {
508
0
            PyErr_SetString(PyExc_ValueError, "embedded null character");
509
0
            goto exit;
510
0
        }
511
69.6k
    }
512
0
    else {
513
0
        _PyArg_BadArgument("utf_8_decode", "argument 2", "str or None", args[1]);
514
0
        goto exit;
515
0
    }
516
69.6k
    if (nargs < 3) {
517
0
        goto skip_optional;
518
0
    }
519
69.6k
    final = PyObject_IsTrue(args[2]);
520
69.6k
    if (final < 0) {
521
0
        goto exit;
522
0
    }
523
69.6k
skip_optional:
524
69.6k
    return_value = _codecs_utf_8_decode_impl(module, &data, errors, final);
525
526
69.6k
exit:
527
    /* Cleanup for data */
528
69.6k
    if (data.obj) {
529
69.6k
       PyBuffer_Release(&data);
530
69.6k
    }
531
532
69.6k
    return return_value;
533
69.6k
}
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
12.3k
{
550
12.3k
    PyObject *return_value = NULL;
551
12.3k
    Py_buffer data = {NULL, NULL};
552
12.3k
    const char *errors = NULL;
553
12.3k
    int final = 0;
554
555
12.3k
    if (!_PyArg_CheckPositional("utf_16_decode", nargs, 1, 3)) {
556
0
        goto exit;
557
0
    }
558
12.3k
    if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
559
0
        goto exit;
560
0
    }
561
12.3k
    if (nargs < 2) {
562
0
        goto skip_optional;
563
0
    }
564
12.3k
    if (args[1] == Py_None) {
565
0
        errors = NULL;
566
0
    }
567
12.3k
    else if (PyUnicode_Check(args[1])) {
568
12.3k
        Py_ssize_t errors_length;
569
12.3k
        errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
570
12.3k
        if (errors == NULL) {
571
0
            goto exit;
572
0
        }
573
12.3k
        if (strlen(errors) != (size_t)errors_length) {
574
0
            PyErr_SetString(PyExc_ValueError, "embedded null character");
575
0
            goto exit;
576
0
        }
577
12.3k
    }
578
0
    else {
579
0
        _PyArg_BadArgument("utf_16_decode", "argument 2", "str or None", args[1]);
580
0
        goto exit;
581
0
    }
582
12.3k
    if (nargs < 3) {
583
0
        goto skip_optional;
584
0
    }
585
12.3k
    final = PyObject_IsTrue(args[2]);
586
12.3k
    if (final < 0) {
587
0
        goto exit;
588
0
    }
589
12.3k
skip_optional:
590
12.3k
    return_value = _codecs_utf_16_decode_impl(module, &data, errors, final);
591
592
12.3k
exit:
593
    /* Cleanup for data */
594
12.3k
    if (data.obj) {
595
12.3k
       PyBuffer_Release(&data);
596
12.3k
    }
597
598
12.3k
    return return_value;
599
12.3k
}
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
20
{
616
20
    PyObject *return_value = NULL;
617
20
    Py_buffer data = {NULL, NULL};
618
20
    const char *errors = NULL;
619
20
    int final = 0;
620
621
20
    if (!_PyArg_CheckPositional("utf_16_le_decode", nargs, 1, 3)) {
622
0
        goto exit;
623
0
    }
624
20
    if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
625
0
        goto exit;
626
0
    }
627
20
    if (nargs < 2) {
628
0
        goto skip_optional;
629
0
    }
630
20
    if (args[1] == Py_None) {
631
0
        errors = NULL;
632
0
    }
633
20
    else if (PyUnicode_Check(args[1])) {
634
20
        Py_ssize_t errors_length;
635
20
        errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
636
20
        if (errors == NULL) {
637
0
            goto exit;
638
0
        }
639
20
        if (strlen(errors) != (size_t)errors_length) {
640
0
            PyErr_SetString(PyExc_ValueError, "embedded null character");
641
0
            goto exit;
642
0
        }
643
20
    }
644
0
    else {
645
0
        _PyArg_BadArgument("utf_16_le_decode", "argument 2", "str or None", args[1]);
646
0
        goto exit;
647
0
    }
648
20
    if (nargs < 3) {
649
0
        goto skip_optional;
650
0
    }
651
20
    final = PyObject_IsTrue(args[2]);
652
20
    if (final < 0) {
653
0
        goto exit;
654
0
    }
655
20
skip_optional:
656
20
    return_value = _codecs_utf_16_le_decode_impl(module, &data, errors, final);
657
658
20
exit:
659
    /* Cleanup for data */
660
20
    if (data.obj) {
661
20
       PyBuffer_Release(&data);
662
20
    }
663
664
20
    return return_value;
665
20
}
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
136
{
682
136
    PyObject *return_value = NULL;
683
136
    Py_buffer data = {NULL, NULL};
684
136
    const char *errors = NULL;
685
136
    int final = 0;
686
687
136
    if (!_PyArg_CheckPositional("utf_16_be_decode", nargs, 1, 3)) {
688
0
        goto exit;
689
0
    }
690
136
    if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
691
0
        goto exit;
692
0
    }
693
136
    if (nargs < 2) {
694
0
        goto skip_optional;
695
0
    }
696
136
    if (args[1] == Py_None) {
697
0
        errors = NULL;
698
0
    }
699
136
    else if (PyUnicode_Check(args[1])) {
700
136
        Py_ssize_t errors_length;
701
136
        errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
702
136
        if (errors == NULL) {
703
0
            goto exit;
704
0
        }
705
136
        if (strlen(errors) != (size_t)errors_length) {
706
0
            PyErr_SetString(PyExc_ValueError, "embedded null character");
707
0
            goto exit;
708
0
        }
709
136
    }
710
0
    else {
711
0
        _PyArg_BadArgument("utf_16_be_decode", "argument 2", "str or None", args[1]);
712
0
        goto exit;
713
0
    }
714
136
    if (nargs < 3) {
715
0
        goto skip_optional;
716
0
    }
717
136
    final = PyObject_IsTrue(args[2]);
718
136
    if (final < 0) {
719
0
        goto exit;
720
0
    }
721
136
skip_optional:
722
136
    return_value = _codecs_utf_16_be_decode_impl(module, &data, errors, final);
723
724
136
exit:
725
    /* Cleanup for data */
726
136
    if (data.obj) {
727
136
       PyBuffer_Release(&data);
728
136
    }
729
730
136
    return return_value;
731
136
}
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
0
{
749
0
    PyObject *return_value = NULL;
750
0
    Py_buffer data = {NULL, NULL};
751
0
    const char *errors = NULL;
752
0
    int byteorder = 0;
753
0
    int final = 0;
754
755
0
    if (!_PyArg_CheckPositional("utf_16_ex_decode", nargs, 1, 4)) {
756
0
        goto exit;
757
0
    }
758
0
    if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
759
0
        goto exit;
760
0
    }
761
0
    if (nargs < 2) {
762
0
        goto skip_optional;
763
0
    }
764
0
    if (args[1] == Py_None) {
765
0
        errors = NULL;
766
0
    }
767
0
    else if (PyUnicode_Check(args[1])) {
768
0
        Py_ssize_t errors_length;
769
0
        errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
770
0
        if (errors == NULL) {
771
0
            goto exit;
772
0
        }
773
0
        if (strlen(errors) != (size_t)errors_length) {
774
0
            PyErr_SetString(PyExc_ValueError, "embedded null character");
775
0
            goto exit;
776
0
        }
777
0
    }
778
0
    else {
779
0
        _PyArg_BadArgument("utf_16_ex_decode", "argument 2", "str or None", args[1]);
780
0
        goto exit;
781
0
    }
782
0
    if (nargs < 3) {
783
0
        goto skip_optional;
784
0
    }
785
0
    byteorder = PyLong_AsInt(args[2]);
786
0
    if (byteorder == -1 && PyErr_Occurred()) {
787
0
        goto exit;
788
0
    }
789
0
    if (nargs < 4) {
790
0
        goto skip_optional;
791
0
    }
792
0
    final = PyObject_IsTrue(args[3]);
793
0
    if (final < 0) {
794
0
        goto exit;
795
0
    }
796
0
skip_optional:
797
0
    return_value = _codecs_utf_16_ex_decode_impl(module, &data, errors, byteorder, final);
798
799
0
exit:
800
    /* Cleanup for data */
801
0
    if (data.obj) {
802
0
       PyBuffer_Release(&data);
803
0
    }
804
805
0
    return return_value;
806
0
}
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
25.4k
{
823
25.4k
    PyObject *return_value = NULL;
824
25.4k
    Py_buffer data = {NULL, NULL};
825
25.4k
    const char *errors = NULL;
826
25.4k
    int final = 0;
827
828
25.4k
    if (!_PyArg_CheckPositional("utf_32_decode", nargs, 1, 3)) {
829
0
        goto exit;
830
0
    }
831
25.4k
    if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
832
0
        goto exit;
833
0
    }
834
25.4k
    if (nargs < 2) {
835
0
        goto skip_optional;
836
0
    }
837
25.4k
    if (args[1] == Py_None) {
838
0
        errors = NULL;
839
0
    }
840
25.4k
    else if (PyUnicode_Check(args[1])) {
841
25.4k
        Py_ssize_t errors_length;
842
25.4k
        errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
843
25.4k
        if (errors == NULL) {
844
0
            goto exit;
845
0
        }
846
25.4k
        if (strlen(errors) != (size_t)errors_length) {
847
0
            PyErr_SetString(PyExc_ValueError, "embedded null character");
848
0
            goto exit;
849
0
        }
850
25.4k
    }
851
0
    else {
852
0
        _PyArg_BadArgument("utf_32_decode", "argument 2", "str or None", args[1]);
853
0
        goto exit;
854
0
    }
855
25.4k
    if (nargs < 3) {
856
0
        goto skip_optional;
857
0
    }
858
25.4k
    final = PyObject_IsTrue(args[2]);
859
25.4k
    if (final < 0) {
860
0
        goto exit;
861
0
    }
862
25.4k
skip_optional:
863
25.4k
    return_value = _codecs_utf_32_decode_impl(module, &data, errors, final);
864
865
25.4k
exit:
866
    /* Cleanup for data */
867
25.4k
    if (data.obj) {
868
25.4k
       PyBuffer_Release(&data);
869
25.4k
    }
870
871
25.4k
    return return_value;
872
25.4k
}
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
10
{
889
10
    PyObject *return_value = NULL;
890
10
    Py_buffer data = {NULL, NULL};
891
10
    const char *errors = NULL;
892
10
    int final = 0;
893
894
10
    if (!_PyArg_CheckPositional("utf_32_le_decode", nargs, 1, 3)) {
895
0
        goto exit;
896
0
    }
897
10
    if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
898
0
        goto exit;
899
0
    }
900
10
    if (nargs < 2) {
901
0
        goto skip_optional;
902
0
    }
903
10
    if (args[1] == Py_None) {
904
0
        errors = NULL;
905
0
    }
906
10
    else if (PyUnicode_Check(args[1])) {
907
10
        Py_ssize_t errors_length;
908
10
        errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
909
10
        if (errors == NULL) {
910
0
            goto exit;
911
0
        }
912
10
        if (strlen(errors) != (size_t)errors_length) {
913
0
            PyErr_SetString(PyExc_ValueError, "embedded null character");
914
0
            goto exit;
915
0
        }
916
10
    }
917
0
    else {
918
0
        _PyArg_BadArgument("utf_32_le_decode", "argument 2", "str or None", args[1]);
919
0
        goto exit;
920
0
    }
921
10
    if (nargs < 3) {
922
0
        goto skip_optional;
923
0
    }
924
10
    final = PyObject_IsTrue(args[2]);
925
10
    if (final < 0) {
926
0
        goto exit;
927
0
    }
928
10
skip_optional:
929
10
    return_value = _codecs_utf_32_le_decode_impl(module, &data, errors, final);
930
931
10
exit:
932
    /* Cleanup for data */
933
10
    if (data.obj) {
934
10
       PyBuffer_Release(&data);
935
10
    }
936
937
10
    return return_value;
938
10
}
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
52
{
955
52
    PyObject *return_value = NULL;
956
52
    Py_buffer data = {NULL, NULL};
957
52
    const char *errors = NULL;
958
52
    int final = 0;
959
960
52
    if (!_PyArg_CheckPositional("utf_32_be_decode", nargs, 1, 3)) {
961
0
        goto exit;
962
0
    }
963
52
    if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
964
0
        goto exit;
965
0
    }
966
52
    if (nargs < 2) {
967
0
        goto skip_optional;
968
0
    }
969
52
    if (args[1] == Py_None) {
970
0
        errors = NULL;
971
0
    }
972
52
    else if (PyUnicode_Check(args[1])) {
973
52
        Py_ssize_t errors_length;
974
52
        errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
975
52
        if (errors == NULL) {
976
0
            goto exit;
977
0
        }
978
52
        if (strlen(errors) != (size_t)errors_length) {
979
0
            PyErr_SetString(PyExc_ValueError, "embedded null character");
980
0
            goto exit;
981
0
        }
982
52
    }
983
0
    else {
984
0
        _PyArg_BadArgument("utf_32_be_decode", "argument 2", "str or None", args[1]);
985
0
        goto exit;
986
0
    }
987
52
    if (nargs < 3) {
988
0
        goto skip_optional;
989
0
    }
990
52
    final = PyObject_IsTrue(args[2]);
991
52
    if (final < 0) {
992
0
        goto exit;
993
0
    }
994
52
skip_optional:
995
52
    return_value = _codecs_utf_32_be_decode_impl(module, &data, errors, final);
996
997
52
exit:
998
    /* Cleanup for data */
999
52
    if (data.obj) {
1000
52
       PyBuffer_Release(&data);
1001
52
    }
1002
1003
52
    return return_value;
1004
52
}
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
0
{
1022
0
    PyObject *return_value = NULL;
1023
0
    Py_buffer data = {NULL, NULL};
1024
0
    const char *errors = NULL;
1025
0
    int byteorder = 0;
1026
0
    int final = 0;
1027
1028
0
    if (!_PyArg_CheckPositional("utf_32_ex_decode", nargs, 1, 4)) {
1029
0
        goto exit;
1030
0
    }
1031
0
    if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
1032
0
        goto exit;
1033
0
    }
1034
0
    if (nargs < 2) {
1035
0
        goto skip_optional;
1036
0
    }
1037
0
    if (args[1] == Py_None) {
1038
0
        errors = NULL;
1039
0
    }
1040
0
    else if (PyUnicode_Check(args[1])) {
1041
0
        Py_ssize_t errors_length;
1042
0
        errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
1043
0
        if (errors == NULL) {
1044
0
            goto exit;
1045
0
        }
1046
0
        if (strlen(errors) != (size_t)errors_length) {
1047
0
            PyErr_SetString(PyExc_ValueError, "embedded null character");
1048
0
            goto exit;
1049
0
        }
1050
0
    }
1051
0
    else {
1052
0
        _PyArg_BadArgument("utf_32_ex_decode", "argument 2", "str or None", args[1]);
1053
0
        goto exit;
1054
0
    }
1055
0
    if (nargs < 3) {
1056
0
        goto skip_optional;
1057
0
    }
1058
0
    byteorder = PyLong_AsInt(args[2]);
1059
0
    if (byteorder == -1 && PyErr_Occurred()) {
1060
0
        goto exit;
1061
0
    }
1062
0
    if (nargs < 4) {
1063
0
        goto skip_optional;
1064
0
    }
1065
0
    final = PyObject_IsTrue(args[3]);
1066
0
    if (final < 0) {
1067
0
        goto exit;
1068
0
    }
1069
0
skip_optional:
1070
0
    return_value = _codecs_utf_32_ex_decode_impl(module, &data, errors, byteorder, final);
1071
1072
0
exit:
1073
    /* Cleanup for data */
1074
0
    if (data.obj) {
1075
0
       PyBuffer_Release(&data);
1076
0
    }
1077
1078
0
    return return_value;
1079
0
}
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
0
{
1096
0
    PyObject *return_value = NULL;
1097
0
    Py_buffer data = {NULL, NULL};
1098
0
    const char *errors = NULL;
1099
0
    int final = 1;
1100
1101
0
    if (!_PyArg_CheckPositional("unicode_escape_decode", nargs, 1, 3)) {
1102
0
        goto exit;
1103
0
    }
1104
0
    if (PyUnicode_Check(args[0])) {
1105
0
        Py_ssize_t len;
1106
0
        const char *ptr = PyUnicode_AsUTF8AndSize(args[0], &len);
1107
0
        if (ptr == NULL) {
1108
0
            goto exit;
1109
0
        }
1110
0
        if (PyBuffer_FillInfo(&data, args[0], (void *)ptr, len, 1, PyBUF_SIMPLE) < 0) {
1111
0
            goto exit;
1112
0
        }
1113
0
    }
1114
0
    else { /* any bytes-like object */
1115
0
        if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
1116
0
            goto exit;
1117
0
        }
1118
0
    }
1119
0
    if (nargs < 2) {
1120
0
        goto skip_optional;
1121
0
    }
1122
0
    if (args[1] == Py_None) {
1123
0
        errors = NULL;
1124
0
    }
1125
0
    else if (PyUnicode_Check(args[1])) {
1126
0
        Py_ssize_t errors_length;
1127
0
        errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
1128
0
        if (errors == NULL) {
1129
0
            goto exit;
1130
0
        }
1131
0
        if (strlen(errors) != (size_t)errors_length) {
1132
0
            PyErr_SetString(PyExc_ValueError, "embedded null character");
1133
0
            goto exit;
1134
0
        }
1135
0
    }
1136
0
    else {
1137
0
        _PyArg_BadArgument("unicode_escape_decode", "argument 2", "str or None", args[1]);
1138
0
        goto exit;
1139
0
    }
1140
0
    if (nargs < 3) {
1141
0
        goto skip_optional;
1142
0
    }
1143
0
    final = PyObject_IsTrue(args[2]);
1144
0
    if (final < 0) {
1145
0
        goto exit;
1146
0
    }
1147
0
skip_optional:
1148
0
    return_value = _codecs_unicode_escape_decode_impl(module, &data, errors, final);
1149
1150
0
exit:
1151
    /* Cleanup for data */
1152
0
    if (data.obj) {
1153
0
       PyBuffer_Release(&data);
1154
0
    }
1155
1156
0
    return return_value;
1157
0
}
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
0
{
1174
0
    PyObject *return_value = NULL;
1175
0
    Py_buffer data = {NULL, NULL};
1176
0
    const char *errors = NULL;
1177
0
    int final = 1;
1178
1179
0
    if (!_PyArg_CheckPositional("raw_unicode_escape_decode", nargs, 1, 3)) {
1180
0
        goto exit;
1181
0
    }
1182
0
    if (PyUnicode_Check(args[0])) {
1183
0
        Py_ssize_t len;
1184
0
        const char *ptr = PyUnicode_AsUTF8AndSize(args[0], &len);
1185
0
        if (ptr == NULL) {
1186
0
            goto exit;
1187
0
        }
1188
0
        if (PyBuffer_FillInfo(&data, args[0], (void *)ptr, len, 1, PyBUF_SIMPLE) < 0) {
1189
0
            goto exit;
1190
0
        }
1191
0
    }
1192
0
    else { /* any bytes-like object */
1193
0
        if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
1194
0
            goto exit;
1195
0
        }
1196
0
    }
1197
0
    if (nargs < 2) {
1198
0
        goto skip_optional;
1199
0
    }
1200
0
    if (args[1] == Py_None) {
1201
0
        errors = NULL;
1202
0
    }
1203
0
    else if (PyUnicode_Check(args[1])) {
1204
0
        Py_ssize_t errors_length;
1205
0
        errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
1206
0
        if (errors == NULL) {
1207
0
            goto exit;
1208
0
        }
1209
0
        if (strlen(errors) != (size_t)errors_length) {
1210
0
            PyErr_SetString(PyExc_ValueError, "embedded null character");
1211
0
            goto exit;
1212
0
        }
1213
0
    }
1214
0
    else {
1215
0
        _PyArg_BadArgument("raw_unicode_escape_decode", "argument 2", "str or None", args[1]);
1216
0
        goto exit;
1217
0
    }
1218
0
    if (nargs < 3) {
1219
0
        goto skip_optional;
1220
0
    }
1221
0
    final = PyObject_IsTrue(args[2]);
1222
0
    if (final < 0) {
1223
0
        goto exit;
1224
0
    }
1225
0
skip_optional:
1226
0
    return_value = _codecs_raw_unicode_escape_decode_impl(module, &data, errors, final);
1227
1228
0
exit:
1229
    /* Cleanup for data */
1230
0
    if (data.obj) {
1231
0
       PyBuffer_Release(&data);
1232
0
    }
1233
1234
0
    return return_value;
1235
0
}
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
5.23k
{
1252
5.23k
    PyObject *return_value = NULL;
1253
5.23k
    Py_buffer data = {NULL, NULL};
1254
5.23k
    const char *errors = NULL;
1255
1256
5.23k
    if (!_PyArg_CheckPositional("latin_1_decode", nargs, 1, 2)) {
1257
0
        goto exit;
1258
0
    }
1259
5.23k
    if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
1260
0
        goto exit;
1261
0
    }
1262
5.23k
    if (nargs < 2) {
1263
916
        goto skip_optional;
1264
916
    }
1265
4.32k
    if (args[1] == Py_None) {
1266
0
        errors = NULL;
1267
0
    }
1268
4.32k
    else if (PyUnicode_Check(args[1])) {
1269
4.32k
        Py_ssize_t errors_length;
1270
4.32k
        errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
1271
4.32k
        if (errors == NULL) {
1272
0
            goto exit;
1273
0
        }
1274
4.32k
        if (strlen(errors) != (size_t)errors_length) {
1275
0
            PyErr_SetString(PyExc_ValueError, "embedded null character");
1276
0
            goto exit;
1277
0
        }
1278
4.32k
    }
1279
0
    else {
1280
0
        _PyArg_BadArgument("latin_1_decode", "argument 2", "str or None", args[1]);
1281
0
        goto exit;
1282
0
    }
1283
5.23k
skip_optional:
1284
5.23k
    return_value = _codecs_latin_1_decode_impl(module, &data, errors);
1285
1286
5.23k
exit:
1287
    /* Cleanup for data */
1288
5.23k
    if (data.obj) {
1289
5.23k
       PyBuffer_Release(&data);
1290
5.23k
    }
1291
1292
5.23k
    return return_value;
1293
5.23k
}
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
10.8k
{
1310
10.8k
    PyObject *return_value = NULL;
1311
10.8k
    Py_buffer data = {NULL, NULL};
1312
10.8k
    const char *errors = NULL;
1313
1314
10.8k
    if (!_PyArg_CheckPositional("ascii_decode", nargs, 1, 2)) {
1315
0
        goto exit;
1316
0
    }
1317
10.8k
    if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
1318
0
        goto exit;
1319
0
    }
1320
10.8k
    if (nargs < 2) {
1321
5.96k
        goto skip_optional;
1322
5.96k
    }
1323
4.89k
    if (args[1] == Py_None) {
1324
0
        errors = NULL;
1325
0
    }
1326
4.89k
    else if (PyUnicode_Check(args[1])) {
1327
4.89k
        Py_ssize_t errors_length;
1328
4.89k
        errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
1329
4.89k
        if (errors == NULL) {
1330
0
            goto exit;
1331
0
        }
1332
4.89k
        if (strlen(errors) != (size_t)errors_length) {
1333
0
            PyErr_SetString(PyExc_ValueError, "embedded null character");
1334
0
            goto exit;
1335
0
        }
1336
4.89k
    }
1337
0
    else {
1338
0
        _PyArg_BadArgument("ascii_decode", "argument 2", "str or None", args[1]);
1339
0
        goto exit;
1340
0
    }
1341
10.8k
skip_optional:
1342
10.8k
    return_value = _codecs_ascii_decode_impl(module, &data, errors);
1343
1344
10.8k
exit:
1345
    /* Cleanup for data */
1346
10.8k
    if (data.obj) {
1347
10.8k
       PyBuffer_Release(&data);
1348
10.8k
    }
1349
1350
10.8k
    return return_value;
1351
10.8k
}
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
10.2k
{
1368
10.2k
    PyObject *return_value = NULL;
1369
10.2k
    Py_buffer data = {NULL, NULL};
1370
10.2k
    const char *errors = NULL;
1371
10.2k
    PyObject *mapping = Py_None;
1372
1373
10.2k
    if (!_PyArg_CheckPositional("charmap_decode", nargs, 1, 3)) {
1374
0
        goto exit;
1375
0
    }
1376
10.2k
    if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
1377
0
        goto exit;
1378
0
    }
1379
10.2k
    if (nargs < 2) {
1380
0
        goto skip_optional;
1381
0
    }
1382
10.2k
    if (args[1] == Py_None) {
1383
0
        errors = NULL;
1384
0
    }
1385
10.2k
    else if (PyUnicode_Check(args[1])) {
1386
10.2k
        Py_ssize_t errors_length;
1387
10.2k
        errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
1388
10.2k
        if (errors == NULL) {
1389
0
            goto exit;
1390
0
        }
1391
10.2k
        if (strlen(errors) != (size_t)errors_length) {
1392
0
            PyErr_SetString(PyExc_ValueError, "embedded null character");
1393
0
            goto exit;
1394
0
        }
1395
10.2k
    }
1396
0
    else {
1397
0
        _PyArg_BadArgument("charmap_decode", "argument 2", "str or None", args[1]);
1398
0
        goto exit;
1399
0
    }
1400
10.2k
    if (nargs < 3) {
1401
0
        goto skip_optional;
1402
0
    }
1403
10.2k
    mapping = args[2];
1404
10.2k
skip_optional:
1405
10.2k
    return_value = _codecs_charmap_decode_impl(module, &data, errors, mapping);
1406
1407
10.2k
exit:
1408
    /* Cleanup for data */
1409
10.2k
    if (data.obj) {
1410
10.2k
       PyBuffer_Release(&data);
1411
10.2k
    }
1412
1413
10.2k
    return return_value;
1414
10.2k
}
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
0
{
1646
0
    PyObject *return_value = NULL;
1647
0
    Py_buffer data = {NULL, NULL};
1648
0
    const char *errors = NULL;
1649
1650
0
    if (!_PyArg_CheckPositional("readbuffer_encode", nargs, 1, 2)) {
1651
0
        goto exit;
1652
0
    }
1653
0
    if (PyUnicode_Check(args[0])) {
1654
0
        Py_ssize_t len;
1655
0
        const char *ptr = PyUnicode_AsUTF8AndSize(args[0], &len);
1656
0
        if (ptr == NULL) {
1657
0
            goto exit;
1658
0
        }
1659
0
        if (PyBuffer_FillInfo(&data, args[0], (void *)ptr, len, 1, PyBUF_SIMPLE) < 0) {
1660
0
            goto exit;
1661
0
        }
1662
0
    }
1663
0
    else { /* any bytes-like object */
1664
0
        if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
1665
0
            goto exit;
1666
0
        }
1667
0
    }
1668
0
    if (nargs < 2) {
1669
0
        goto skip_optional;
1670
0
    }
1671
0
    if (args[1] == Py_None) {
1672
0
        errors = NULL;
1673
0
    }
1674
0
    else if (PyUnicode_Check(args[1])) {
1675
0
        Py_ssize_t errors_length;
1676
0
        errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
1677
0
        if (errors == NULL) {
1678
0
            goto exit;
1679
0
        }
1680
0
        if (strlen(errors) != (size_t)errors_length) {
1681
0
            PyErr_SetString(PyExc_ValueError, "embedded null character");
1682
0
            goto exit;
1683
0
        }
1684
0
    }
1685
0
    else {
1686
0
        _PyArg_BadArgument("readbuffer_encode", "argument 2", "str or None", args[1]);
1687
0
        goto exit;
1688
0
    }
1689
0
skip_optional:
1690
0
    return_value = _codecs_readbuffer_encode_impl(module, &data, errors);
1691
1692
0
exit:
1693
    /* Cleanup for data */
1694
0
    if (data.obj) {
1695
0
       PyBuffer_Release(&data);
1696
0
    }
1697
1698
0
    return return_value;
1699
0
}
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
0
{
1716
0
    PyObject *return_value = NULL;
1717
0
    PyObject *str;
1718
0
    const char *errors = NULL;
1719
1720
0
    if (!_PyArg_CheckPositional("utf_7_encode", nargs, 1, 2)) {
1721
0
        goto exit;
1722
0
    }
1723
0
    if (!PyUnicode_Check(args[0])) {
1724
0
        _PyArg_BadArgument("utf_7_encode", "argument 1", "str", args[0]);
1725
0
        goto exit;
1726
0
    }
1727
0
    str = args[0];
1728
0
    if (nargs < 2) {
1729
0
        goto skip_optional;
1730
0
    }
1731
0
    if (args[1] == Py_None) {
1732
0
        errors = NULL;
1733
0
    }
1734
0
    else if (PyUnicode_Check(args[1])) {
1735
0
        Py_ssize_t errors_length;
1736
0
        errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
1737
0
        if (errors == NULL) {
1738
0
            goto exit;
1739
0
        }
1740
0
        if (strlen(errors) != (size_t)errors_length) {
1741
0
            PyErr_SetString(PyExc_ValueError, "embedded null character");
1742
0
            goto exit;
1743
0
        }
1744
0
    }
1745
0
    else {
1746
0
        _PyArg_BadArgument("utf_7_encode", "argument 2", "str or None", args[1]);
1747
0
        goto exit;
1748
0
    }
1749
0
skip_optional:
1750
0
    return_value = _codecs_utf_7_encode_impl(module, str, errors);
1751
1752
0
exit:
1753
0
    return return_value;
1754
0
}
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
0
{
1771
0
    PyObject *return_value = NULL;
1772
0
    PyObject *str;
1773
0
    const char *errors = NULL;
1774
1775
0
    if (!_PyArg_CheckPositional("utf_8_encode", nargs, 1, 2)) {
1776
0
        goto exit;
1777
0
    }
1778
0
    if (!PyUnicode_Check(args[0])) {
1779
0
        _PyArg_BadArgument("utf_8_encode", "argument 1", "str", args[0]);
1780
0
        goto exit;
1781
0
    }
1782
0
    str = args[0];
1783
0
    if (nargs < 2) {
1784
0
        goto skip_optional;
1785
0
    }
1786
0
    if (args[1] == Py_None) {
1787
0
        errors = NULL;
1788
0
    }
1789
0
    else if (PyUnicode_Check(args[1])) {
1790
0
        Py_ssize_t errors_length;
1791
0
        errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
1792
0
        if (errors == NULL) {
1793
0
            goto exit;
1794
0
        }
1795
0
        if (strlen(errors) != (size_t)errors_length) {
1796
0
            PyErr_SetString(PyExc_ValueError, "embedded null character");
1797
0
            goto exit;
1798
0
        }
1799
0
    }
1800
0
    else {
1801
0
        _PyArg_BadArgument("utf_8_encode", "argument 2", "str or None", args[1]);
1802
0
        goto exit;
1803
0
    }
1804
0
skip_optional:
1805
0
    return_value = _codecs_utf_8_encode_impl(module, str, errors);
1806
1807
0
exit:
1808
0
    return return_value;
1809
0
}
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
0
{
1826
0
    PyObject *return_value = NULL;
1827
0
    PyObject *str;
1828
0
    const char *errors = NULL;
1829
0
    int byteorder = 0;
1830
1831
0
    if (!_PyArg_CheckPositional("utf_16_encode", nargs, 1, 3)) {
1832
0
        goto exit;
1833
0
    }
1834
0
    if (!PyUnicode_Check(args[0])) {
1835
0
        _PyArg_BadArgument("utf_16_encode", "argument 1", "str", args[0]);
1836
0
        goto exit;
1837
0
    }
1838
0
    str = args[0];
1839
0
    if (nargs < 2) {
1840
0
        goto skip_optional;
1841
0
    }
1842
0
    if (args[1] == Py_None) {
1843
0
        errors = NULL;
1844
0
    }
1845
0
    else if (PyUnicode_Check(args[1])) {
1846
0
        Py_ssize_t errors_length;
1847
0
        errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
1848
0
        if (errors == NULL) {
1849
0
            goto exit;
1850
0
        }
1851
0
        if (strlen(errors) != (size_t)errors_length) {
1852
0
            PyErr_SetString(PyExc_ValueError, "embedded null character");
1853
0
            goto exit;
1854
0
        }
1855
0
    }
1856
0
    else {
1857
0
        _PyArg_BadArgument("utf_16_encode", "argument 2", "str or None", args[1]);
1858
0
        goto exit;
1859
0
    }
1860
0
    if (nargs < 3) {
1861
0
        goto skip_optional;
1862
0
    }
1863
0
    byteorder = PyLong_AsInt(args[2]);
1864
0
    if (byteorder == -1 && PyErr_Occurred()) {
1865
0
        goto exit;
1866
0
    }
1867
0
skip_optional:
1868
0
    return_value = _codecs_utf_16_encode_impl(module, str, errors, byteorder);
1869
1870
0
exit:
1871
0
    return return_value;
1872
0
}
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
0
{
1889
0
    PyObject *return_value = NULL;
1890
0
    PyObject *str;
1891
0
    const char *errors = NULL;
1892
1893
0
    if (!_PyArg_CheckPositional("utf_16_le_encode", nargs, 1, 2)) {
1894
0
        goto exit;
1895
0
    }
1896
0
    if (!PyUnicode_Check(args[0])) {
1897
0
        _PyArg_BadArgument("utf_16_le_encode", "argument 1", "str", args[0]);
1898
0
        goto exit;
1899
0
    }
1900
0
    str = args[0];
1901
0
    if (nargs < 2) {
1902
0
        goto skip_optional;
1903
0
    }
1904
0
    if (args[1] == Py_None) {
1905
0
        errors = NULL;
1906
0
    }
1907
0
    else if (PyUnicode_Check(args[1])) {
1908
0
        Py_ssize_t errors_length;
1909
0
        errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
1910
0
        if (errors == NULL) {
1911
0
            goto exit;
1912
0
        }
1913
0
        if (strlen(errors) != (size_t)errors_length) {
1914
0
            PyErr_SetString(PyExc_ValueError, "embedded null character");
1915
0
            goto exit;
1916
0
        }
1917
0
    }
1918
0
    else {
1919
0
        _PyArg_BadArgument("utf_16_le_encode", "argument 2", "str or None", args[1]);
1920
0
        goto exit;
1921
0
    }
1922
0
skip_optional:
1923
0
    return_value = _codecs_utf_16_le_encode_impl(module, str, errors);
1924
1925
0
exit:
1926
0
    return return_value;
1927
0
}
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
0
{
1944
0
    PyObject *return_value = NULL;
1945
0
    PyObject *str;
1946
0
    const char *errors = NULL;
1947
1948
0
    if (!_PyArg_CheckPositional("utf_16_be_encode", nargs, 1, 2)) {
1949
0
        goto exit;
1950
0
    }
1951
0
    if (!PyUnicode_Check(args[0])) {
1952
0
        _PyArg_BadArgument("utf_16_be_encode", "argument 1", "str", args[0]);
1953
0
        goto exit;
1954
0
    }
1955
0
    str = args[0];
1956
0
    if (nargs < 2) {
1957
0
        goto skip_optional;
1958
0
    }
1959
0
    if (args[1] == Py_None) {
1960
0
        errors = NULL;
1961
0
    }
1962
0
    else if (PyUnicode_Check(args[1])) {
1963
0
        Py_ssize_t errors_length;
1964
0
        errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
1965
0
        if (errors == NULL) {
1966
0
            goto exit;
1967
0
        }
1968
0
        if (strlen(errors) != (size_t)errors_length) {
1969
0
            PyErr_SetString(PyExc_ValueError, "embedded null character");
1970
0
            goto exit;
1971
0
        }
1972
0
    }
1973
0
    else {
1974
0
        _PyArg_BadArgument("utf_16_be_encode", "argument 2", "str or None", args[1]);
1975
0
        goto exit;
1976
0
    }
1977
0
skip_optional:
1978
0
    return_value = _codecs_utf_16_be_encode_impl(module, str, errors);
1979
1980
0
exit:
1981
0
    return return_value;
1982
0
}
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
0
{
1999
0
    PyObject *return_value = NULL;
2000
0
    PyObject *str;
2001
0
    const char *errors = NULL;
2002
0
    int byteorder = 0;
2003
2004
0
    if (!_PyArg_CheckPositional("utf_32_encode", nargs, 1, 3)) {
2005
0
        goto exit;
2006
0
    }
2007
0
    if (!PyUnicode_Check(args[0])) {
2008
0
        _PyArg_BadArgument("utf_32_encode", "argument 1", "str", args[0]);
2009
0
        goto exit;
2010
0
    }
2011
0
    str = args[0];
2012
0
    if (nargs < 2) {
2013
0
        goto skip_optional;
2014
0
    }
2015
0
    if (args[1] == Py_None) {
2016
0
        errors = NULL;
2017
0
    }
2018
0
    else if (PyUnicode_Check(args[1])) {
2019
0
        Py_ssize_t errors_length;
2020
0
        errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
2021
0
        if (errors == NULL) {
2022
0
            goto exit;
2023
0
        }
2024
0
        if (strlen(errors) != (size_t)errors_length) {
2025
0
            PyErr_SetString(PyExc_ValueError, "embedded null character");
2026
0
            goto exit;
2027
0
        }
2028
0
    }
2029
0
    else {
2030
0
        _PyArg_BadArgument("utf_32_encode", "argument 2", "str or None", args[1]);
2031
0
        goto exit;
2032
0
    }
2033
0
    if (nargs < 3) {
2034
0
        goto skip_optional;
2035
0
    }
2036
0
    byteorder = PyLong_AsInt(args[2]);
2037
0
    if (byteorder == -1 && PyErr_Occurred()) {
2038
0
        goto exit;
2039
0
    }
2040
0
skip_optional:
2041
0
    return_value = _codecs_utf_32_encode_impl(module, str, errors, byteorder);
2042
2043
0
exit:
2044
0
    return return_value;
2045
0
}
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
0
{
2062
0
    PyObject *return_value = NULL;
2063
0
    PyObject *str;
2064
0
    const char *errors = NULL;
2065
2066
0
    if (!_PyArg_CheckPositional("utf_32_le_encode", nargs, 1, 2)) {
2067
0
        goto exit;
2068
0
    }
2069
0
    if (!PyUnicode_Check(args[0])) {
2070
0
        _PyArg_BadArgument("utf_32_le_encode", "argument 1", "str", args[0]);
2071
0
        goto exit;
2072
0
    }
2073
0
    str = args[0];
2074
0
    if (nargs < 2) {
2075
0
        goto skip_optional;
2076
0
    }
2077
0
    if (args[1] == Py_None) {
2078
0
        errors = NULL;
2079
0
    }
2080
0
    else if (PyUnicode_Check(args[1])) {
2081
0
        Py_ssize_t errors_length;
2082
0
        errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
2083
0
        if (errors == NULL) {
2084
0
            goto exit;
2085
0
        }
2086
0
        if (strlen(errors) != (size_t)errors_length) {
2087
0
            PyErr_SetString(PyExc_ValueError, "embedded null character");
2088
0
            goto exit;
2089
0
        }
2090
0
    }
2091
0
    else {
2092
0
        _PyArg_BadArgument("utf_32_le_encode", "argument 2", "str or None", args[1]);
2093
0
        goto exit;
2094
0
    }
2095
0
skip_optional:
2096
0
    return_value = _codecs_utf_32_le_encode_impl(module, str, errors);
2097
2098
0
exit:
2099
0
    return return_value;
2100
0
}
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
0
{
2117
0
    PyObject *return_value = NULL;
2118
0
    PyObject *str;
2119
0
    const char *errors = NULL;
2120
2121
0
    if (!_PyArg_CheckPositional("utf_32_be_encode", nargs, 1, 2)) {
2122
0
        goto exit;
2123
0
    }
2124
0
    if (!PyUnicode_Check(args[0])) {
2125
0
        _PyArg_BadArgument("utf_32_be_encode", "argument 1", "str", args[0]);
2126
0
        goto exit;
2127
0
    }
2128
0
    str = args[0];
2129
0
    if (nargs < 2) {
2130
0
        goto skip_optional;
2131
0
    }
2132
0
    if (args[1] == Py_None) {
2133
0
        errors = NULL;
2134
0
    }
2135
0
    else if (PyUnicode_Check(args[1])) {
2136
0
        Py_ssize_t errors_length;
2137
0
        errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
2138
0
        if (errors == NULL) {
2139
0
            goto exit;
2140
0
        }
2141
0
        if (strlen(errors) != (size_t)errors_length) {
2142
0
            PyErr_SetString(PyExc_ValueError, "embedded null character");
2143
0
            goto exit;
2144
0
        }
2145
0
    }
2146
0
    else {
2147
0
        _PyArg_BadArgument("utf_32_be_encode", "argument 2", "str or None", args[1]);
2148
0
        goto exit;
2149
0
    }
2150
0
skip_optional:
2151
0
    return_value = _codecs_utf_32_be_encode_impl(module, str, errors);
2152
2153
0
exit:
2154
0
    return return_value;
2155
0
}
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
452k
{
2172
452k
    PyObject *return_value = NULL;
2173
452k
    PyObject *str;
2174
452k
    const char *errors = NULL;
2175
2176
452k
    if (!_PyArg_CheckPositional("unicode_escape_encode", nargs, 1, 2)) {
2177
0
        goto exit;
2178
0
    }
2179
452k
    if (!PyUnicode_Check(args[0])) {
2180
0
        _PyArg_BadArgument("unicode_escape_encode", "argument 1", "str", args[0]);
2181
0
        goto exit;
2182
0
    }
2183
452k
    str = args[0];
2184
452k
    if (nargs < 2) {
2185
452k
        goto skip_optional;
2186
452k
    }
2187
0
    if (args[1] == Py_None) {
2188
0
        errors = NULL;
2189
0
    }
2190
0
    else if (PyUnicode_Check(args[1])) {
2191
0
        Py_ssize_t errors_length;
2192
0
        errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
2193
0
        if (errors == NULL) {
2194
0
            goto exit;
2195
0
        }
2196
0
        if (strlen(errors) != (size_t)errors_length) {
2197
0
            PyErr_SetString(PyExc_ValueError, "embedded null character");
2198
0
            goto exit;
2199
0
        }
2200
0
    }
2201
0
    else {
2202
0
        _PyArg_BadArgument("unicode_escape_encode", "argument 2", "str or None", args[1]);
2203
0
        goto exit;
2204
0
    }
2205
452k
skip_optional:
2206
452k
    return_value = _codecs_unicode_escape_encode_impl(module, str, errors);
2207
2208
452k
exit:
2209
452k
    return return_value;
2210
452k
}
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
200k
{
2227
200k
    PyObject *return_value = NULL;
2228
200k
    PyObject *str;
2229
200k
    const char *errors = NULL;
2230
2231
200k
    if (!_PyArg_CheckPositional("raw_unicode_escape_encode", nargs, 1, 2)) {
2232
0
        goto exit;
2233
0
    }
2234
200k
    if (!PyUnicode_Check(args[0])) {
2235
0
        _PyArg_BadArgument("raw_unicode_escape_encode", "argument 1", "str", args[0]);
2236
0
        goto exit;
2237
0
    }
2238
200k
    str = args[0];
2239
200k
    if (nargs < 2) {
2240
200k
        goto skip_optional;
2241
200k
    }
2242
0
    if (args[1] == Py_None) {
2243
0
        errors = NULL;
2244
0
    }
2245
0
    else if (PyUnicode_Check(args[1])) {
2246
0
        Py_ssize_t errors_length;
2247
0
        errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
2248
0
        if (errors == NULL) {
2249
0
            goto exit;
2250
0
        }
2251
0
        if (strlen(errors) != (size_t)errors_length) {
2252
0
            PyErr_SetString(PyExc_ValueError, "embedded null character");
2253
0
            goto exit;
2254
0
        }
2255
0
    }
2256
0
    else {
2257
0
        _PyArg_BadArgument("raw_unicode_escape_encode", "argument 2", "str or None", args[1]);
2258
0
        goto exit;
2259
0
    }
2260
200k
skip_optional:
2261
200k
    return_value = _codecs_raw_unicode_escape_encode_impl(module, str, errors);
2262
2263
200k
exit:
2264
200k
    return return_value;
2265
200k
}
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
0
{
2282
0
    PyObject *return_value = NULL;
2283
0
    PyObject *str;
2284
0
    const char *errors = NULL;
2285
2286
0
    if (!_PyArg_CheckPositional("latin_1_encode", nargs, 1, 2)) {
2287
0
        goto exit;
2288
0
    }
2289
0
    if (!PyUnicode_Check(args[0])) {
2290
0
        _PyArg_BadArgument("latin_1_encode", "argument 1", "str", args[0]);
2291
0
        goto exit;
2292
0
    }
2293
0
    str = args[0];
2294
0
    if (nargs < 2) {
2295
0
        goto skip_optional;
2296
0
    }
2297
0
    if (args[1] == Py_None) {
2298
0
        errors = NULL;
2299
0
    }
2300
0
    else if (PyUnicode_Check(args[1])) {
2301
0
        Py_ssize_t errors_length;
2302
0
        errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
2303
0
        if (errors == NULL) {
2304
0
            goto exit;
2305
0
        }
2306
0
        if (strlen(errors) != (size_t)errors_length) {
2307
0
            PyErr_SetString(PyExc_ValueError, "embedded null character");
2308
0
            goto exit;
2309
0
        }
2310
0
    }
2311
0
    else {
2312
0
        _PyArg_BadArgument("latin_1_encode", "argument 2", "str or None", args[1]);
2313
0
        goto exit;
2314
0
    }
2315
0
skip_optional:
2316
0
    return_value = _codecs_latin_1_encode_impl(module, str, errors);
2317
2318
0
exit:
2319
0
    return return_value;
2320
0
}
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
0
{
2337
0
    PyObject *return_value = NULL;
2338
0
    PyObject *str;
2339
0
    const char *errors = NULL;
2340
2341
0
    if (!_PyArg_CheckPositional("ascii_encode", nargs, 1, 2)) {
2342
0
        goto exit;
2343
0
    }
2344
0
    if (!PyUnicode_Check(args[0])) {
2345
0
        _PyArg_BadArgument("ascii_encode", "argument 1", "str", args[0]);
2346
0
        goto exit;
2347
0
    }
2348
0
    str = args[0];
2349
0
    if (nargs < 2) {
2350
0
        goto skip_optional;
2351
0
    }
2352
0
    if (args[1] == Py_None) {
2353
0
        errors = NULL;
2354
0
    }
2355
0
    else if (PyUnicode_Check(args[1])) {
2356
0
        Py_ssize_t errors_length;
2357
0
        errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
2358
0
        if (errors == NULL) {
2359
0
            goto exit;
2360
0
        }
2361
0
        if (strlen(errors) != (size_t)errors_length) {
2362
0
            PyErr_SetString(PyExc_ValueError, "embedded null character");
2363
0
            goto exit;
2364
0
        }
2365
0
    }
2366
0
    else {
2367
0
        _PyArg_BadArgument("ascii_encode", "argument 2", "str or None", args[1]);
2368
0
        goto exit;
2369
0
    }
2370
0
skip_optional:
2371
0
    return_value = _codecs_ascii_encode_impl(module, str, errors);
2372
2373
0
exit:
2374
0
    return return_value;
2375
0
}
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
0
{
2392
0
    PyObject *return_value = NULL;
2393
0
    PyObject *str;
2394
0
    const char *errors = NULL;
2395
0
    PyObject *mapping = Py_None;
2396
2397
0
    if (!_PyArg_CheckPositional("charmap_encode", nargs, 1, 3)) {
2398
0
        goto exit;
2399
0
    }
2400
0
    if (!PyUnicode_Check(args[0])) {
2401
0
        _PyArg_BadArgument("charmap_encode", "argument 1", "str", args[0]);
2402
0
        goto exit;
2403
0
    }
2404
0
    str = args[0];
2405
0
    if (nargs < 2) {
2406
0
        goto skip_optional;
2407
0
    }
2408
0
    if (args[1] == Py_None) {
2409
0
        errors = NULL;
2410
0
    }
2411
0
    else if (PyUnicode_Check(args[1])) {
2412
0
        Py_ssize_t errors_length;
2413
0
        errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
2414
0
        if (errors == NULL) {
2415
0
            goto exit;
2416
0
        }
2417
0
        if (strlen(errors) != (size_t)errors_length) {
2418
0
            PyErr_SetString(PyExc_ValueError, "embedded null character");
2419
0
            goto exit;
2420
0
        }
2421
0
    }
2422
0
    else {
2423
0
        _PyArg_BadArgument("charmap_encode", "argument 2", "str or None", args[1]);
2424
0
        goto exit;
2425
0
    }
2426
0
    if (nargs < 3) {
2427
0
        goto skip_optional;
2428
0
    }
2429
0
    mapping = args[2];
2430
0
skip_optional:
2431
0
    return_value = _codecs_charmap_encode_impl(module, str, errors, mapping);
2432
2433
0
exit:
2434
0
    return return_value;
2435
0
}
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
115
{
2451
115
    PyObject *return_value = NULL;
2452
115
    PyObject *map;
2453
2454
115
    if (!PyUnicode_Check(arg)) {
2455
0
        _PyArg_BadArgument("charmap_build", "argument", "str", arg);
2456
0
        goto exit;
2457
0
    }
2458
115
    map = arg;
2459
115
    return_value = _codecs_charmap_build_impl(module, map);
2460
2461
115
exit:
2462
115
    return return_value;
2463
115
}
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
0
{
2665
0
    PyObject *return_value = NULL;
2666
0
    const char *errors;
2667
0
    PyObject *handler;
2668
2669
0
    if (!_PyArg_CheckPositional("register_error", nargs, 2, 2)) {
2670
0
        goto exit;
2671
0
    }
2672
0
    if (!PyUnicode_Check(args[0])) {
2673
0
        _PyArg_BadArgument("register_error", "argument 1", "str", args[0]);
2674
0
        goto exit;
2675
0
    }
2676
0
    Py_ssize_t errors_length;
2677
0
    errors = PyUnicode_AsUTF8AndSize(args[0], &errors_length);
2678
0
    if (errors == NULL) {
2679
0
        goto exit;
2680
0
    }
2681
0
    if (strlen(errors) != (size_t)errors_length) {
2682
0
        PyErr_SetString(PyExc_ValueError, "embedded null character");
2683
0
        goto exit;
2684
0
    }
2685
0
    handler = args[1];
2686
0
    return_value = _codecs_register_error_impl(module, errors, handler);
2687
2688
0
exit:
2689
0
    return return_value;
2690
0
}
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
0
{
2715
0
    PyObject *return_value = NULL;
2716
0
    const char *errors;
2717
0
    int _return_value;
2718
2719
0
    if (!PyUnicode_Check(arg)) {
2720
0
        _PyArg_BadArgument("_unregister_error", "argument", "str", arg);
2721
0
        goto exit;
2722
0
    }
2723
0
    Py_ssize_t errors_length;
2724
0
    errors = PyUnicode_AsUTF8AndSize(arg, &errors_length);
2725
0
    if (errors == NULL) {
2726
0
        goto exit;
2727
0
    }
2728
0
    if (strlen(errors) != (size_t)errors_length) {
2729
0
        PyErr_SetString(PyExc_ValueError, "embedded null character");
2730
0
        goto exit;
2731
0
    }
2732
0
    _return_value = _codecs__unregister_error_impl(module, errors);
2733
0
    if ((_return_value == -1) && PyErr_Occurred()) {
2734
0
        goto exit;
2735
0
    }
2736
0
    return_value = PyBool_FromLong((long)_return_value);
2737
2738
0
exit:
2739
0
    return return_value;
2740
0
}
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
96
{
2760
96
    PyObject *return_value = NULL;
2761
96
    const char *name;
2762
2763
96
    if (!PyUnicode_Check(arg)) {
2764
0
        _PyArg_BadArgument("lookup_error", "argument", "str", arg);
2765
0
        goto exit;
2766
0
    }
2767
96
    Py_ssize_t name_length;
2768
96
    name = PyUnicode_AsUTF8AndSize(arg, &name_length);
2769
96
    if (name == NULL) {
2770
0
        goto exit;
2771
0
    }
2772
96
    if (strlen(name) != (size_t)name_length) {
2773
0
        PyErr_SetString(PyExc_ValueError, "embedded null character");
2774
0
        goto exit;
2775
0
    }
2776
96
    return_value = _codecs_lookup_error_impl(module, name);
2777
2778
96
exit:
2779
96
    return return_value;
2780
96
}
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]*/