Coverage Report

Created: 2026-10-17 06:15

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