Coverage Report

Created: 2025-07-11 06:59

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