Coverage Report

Created: 2026-07-14 06:16

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