Coverage Report

Created: 2025-07-11 06:59

/src/Python-3.8.3/Objects/clinic/bytearrayobject.c.h
Line
Count
Source (jump to first uncovered line)
1
/*[clinic input]
2
preserve
3
[clinic start generated code]*/
4
5
PyDoc_STRVAR(bytearray_clear__doc__,
6
"clear($self, /)\n"
7
"--\n"
8
"\n"
9
"Remove all items from the bytearray.");
10
11
#define BYTEARRAY_CLEAR_METHODDEF    \
12
    {"clear", (PyCFunction)bytearray_clear, METH_NOARGS, bytearray_clear__doc__},
13
14
static PyObject *
15
bytearray_clear_impl(PyByteArrayObject *self);
16
17
static PyObject *
18
bytearray_clear(PyByteArrayObject *self, PyObject *Py_UNUSED(ignored))
19
0
{
20
0
    return bytearray_clear_impl(self);
21
0
}
22
23
PyDoc_STRVAR(bytearray_copy__doc__,
24
"copy($self, /)\n"
25
"--\n"
26
"\n"
27
"Return a copy of B.");
28
29
#define BYTEARRAY_COPY_METHODDEF    \
30
    {"copy", (PyCFunction)bytearray_copy, METH_NOARGS, bytearray_copy__doc__},
31
32
static PyObject *
33
bytearray_copy_impl(PyByteArrayObject *self);
34
35
static PyObject *
36
bytearray_copy(PyByteArrayObject *self, PyObject *Py_UNUSED(ignored))
37
0
{
38
0
    return bytearray_copy_impl(self);
39
0
}
40
41
PyDoc_STRVAR(bytearray_translate__doc__,
42
"translate($self, table, /, delete=b\'\')\n"
43
"--\n"
44
"\n"
45
"Return a copy with each character mapped by the given translation table.\n"
46
"\n"
47
"  table\n"
48
"    Translation table, which must be a bytes object of length 256.\n"
49
"\n"
50
"All characters occurring in the optional argument delete are removed.\n"
51
"The remaining characters are mapped through the given translation table.");
52
53
#define BYTEARRAY_TRANSLATE_METHODDEF    \
54
    {"translate", (PyCFunction)(void(*)(void))bytearray_translate, METH_FASTCALL|METH_KEYWORDS, bytearray_translate__doc__},
55
56
static PyObject *
57
bytearray_translate_impl(PyByteArrayObject *self, PyObject *table,
58
                         PyObject *deletechars);
59
60
static PyObject *
61
bytearray_translate(PyByteArrayObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
62
9
{
63
9
    PyObject *return_value = NULL;
64
9
    static const char * const _keywords[] = {"", "delete", NULL};
65
9
    static _PyArg_Parser _parser = {NULL, _keywords, "translate", 0};
66
9
    PyObject *argsbuf[2];
67
9
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
68
9
    PyObject *table;
69
9
    PyObject *deletechars = NULL;
70
71
9
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf);
72
9
    if (!args) {
73
0
        goto exit;
74
0
    }
75
9
    table = args[0];
76
9
    if (!noptargs) {
77
9
        goto skip_optional_pos;
78
9
    }
79
0
    deletechars = args[1];
80
9
skip_optional_pos:
81
9
    return_value = bytearray_translate_impl(self, table, deletechars);
82
83
9
exit:
84
9
    return return_value;
85
9
}
86
87
PyDoc_STRVAR(bytearray_maketrans__doc__,
88
"maketrans(frm, to, /)\n"
89
"--\n"
90
"\n"
91
"Return a translation table useable for the bytes or bytearray translate method.\n"
92
"\n"
93
"The returned table will be one where each byte in frm is mapped to the byte at\n"
94
"the same position in to.\n"
95
"\n"
96
"The bytes objects frm and to must be of the same length.");
97
98
#define BYTEARRAY_MAKETRANS_METHODDEF    \
99
    {"maketrans", (PyCFunction)(void(*)(void))bytearray_maketrans, METH_FASTCALL|METH_STATIC, bytearray_maketrans__doc__},
100
101
static PyObject *
102
bytearray_maketrans_impl(Py_buffer *frm, Py_buffer *to);
103
104
static PyObject *
105
bytearray_maketrans(void *null, PyObject *const *args, Py_ssize_t nargs)
106
0
{
107
0
    PyObject *return_value = NULL;
108
0
    Py_buffer frm = {NULL, NULL};
109
0
    Py_buffer to = {NULL, NULL};
110
111
0
    if (!_PyArg_CheckPositional("maketrans", nargs, 2, 2)) {
112
0
        goto exit;
113
0
    }
114
0
    if (PyObject_GetBuffer(args[0], &frm, PyBUF_SIMPLE) != 0) {
115
0
        goto exit;
116
0
    }
117
0
    if (!PyBuffer_IsContiguous(&frm, 'C')) {
118
0
        _PyArg_BadArgument("maketrans", "argument 1", "contiguous buffer", args[0]);
119
0
        goto exit;
120
0
    }
121
0
    if (PyObject_GetBuffer(args[1], &to, PyBUF_SIMPLE) != 0) {
122
0
        goto exit;
123
0
    }
124
0
    if (!PyBuffer_IsContiguous(&to, 'C')) {
125
0
        _PyArg_BadArgument("maketrans", "argument 2", "contiguous buffer", args[1]);
126
0
        goto exit;
127
0
    }
128
0
    return_value = bytearray_maketrans_impl(&frm, &to);
129
130
0
exit:
131
    /* Cleanup for frm */
132
0
    if (frm.obj) {
133
0
       PyBuffer_Release(&frm);
134
0
    }
135
    /* Cleanup for to */
136
0
    if (to.obj) {
137
0
       PyBuffer_Release(&to);
138
0
    }
139
140
0
    return return_value;
141
0
}
142
143
PyDoc_STRVAR(bytearray_replace__doc__,
144
"replace($self, old, new, count=-1, /)\n"
145
"--\n"
146
"\n"
147
"Return a copy with all occurrences of substring old replaced by new.\n"
148
"\n"
149
"  count\n"
150
"    Maximum number of occurrences to replace.\n"
151
"    -1 (the default value) means replace all occurrences.\n"
152
"\n"
153
"If the optional argument count is given, only the first count occurrences are\n"
154
"replaced.");
155
156
#define BYTEARRAY_REPLACE_METHODDEF    \
157
    {"replace", (PyCFunction)(void(*)(void))bytearray_replace, METH_FASTCALL, bytearray_replace__doc__},
158
159
static PyObject *
160
bytearray_replace_impl(PyByteArrayObject *self, Py_buffer *old,
161
                       Py_buffer *new, Py_ssize_t count);
162
163
static PyObject *
164
bytearray_replace(PyByteArrayObject *self, PyObject *const *args, Py_ssize_t nargs)
165
0
{
166
0
    PyObject *return_value = NULL;
167
0
    Py_buffer old = {NULL, NULL};
168
0
    Py_buffer new = {NULL, NULL};
169
0
    Py_ssize_t count = -1;
170
171
0
    if (!_PyArg_CheckPositional("replace", nargs, 2, 3)) {
172
0
        goto exit;
173
0
    }
174
0
    if (PyObject_GetBuffer(args[0], &old, PyBUF_SIMPLE) != 0) {
175
0
        goto exit;
176
0
    }
177
0
    if (!PyBuffer_IsContiguous(&old, 'C')) {
178
0
        _PyArg_BadArgument("replace", "argument 1", "contiguous buffer", args[0]);
179
0
        goto exit;
180
0
    }
181
0
    if (PyObject_GetBuffer(args[1], &new, PyBUF_SIMPLE) != 0) {
182
0
        goto exit;
183
0
    }
184
0
    if (!PyBuffer_IsContiguous(&new, 'C')) {
185
0
        _PyArg_BadArgument("replace", "argument 2", "contiguous buffer", args[1]);
186
0
        goto exit;
187
0
    }
188
0
    if (nargs < 3) {
189
0
        goto skip_optional;
190
0
    }
191
0
    if (PyFloat_Check(args[2])) {
192
0
        PyErr_SetString(PyExc_TypeError,
193
0
                        "integer argument expected, got float" );
194
0
        goto exit;
195
0
    }
196
0
    {
197
0
        Py_ssize_t ival = -1;
198
0
        PyObject *iobj = PyNumber_Index(args[2]);
199
0
        if (iobj != NULL) {
200
0
            ival = PyLong_AsSsize_t(iobj);
201
0
            Py_DECREF(iobj);
202
0
        }
203
0
        if (ival == -1 && PyErr_Occurred()) {
204
0
            goto exit;
205
0
        }
206
0
        count = ival;
207
0
    }
208
0
skip_optional:
209
0
    return_value = bytearray_replace_impl(self, &old, &new, count);
210
211
0
exit:
212
    /* Cleanup for old */
213
0
    if (old.obj) {
214
0
       PyBuffer_Release(&old);
215
0
    }
216
    /* Cleanup for new */
217
0
    if (new.obj) {
218
0
       PyBuffer_Release(&new);
219
0
    }
220
221
0
    return return_value;
222
0
}
223
224
PyDoc_STRVAR(bytearray_split__doc__,
225
"split($self, /, sep=None, maxsplit=-1)\n"
226
"--\n"
227
"\n"
228
"Return a list of the sections in the bytearray, using sep as the delimiter.\n"
229
"\n"
230
"  sep\n"
231
"    The delimiter according which to split the bytearray.\n"
232
"    None (the default value) means split on ASCII whitespace characters\n"
233
"    (space, tab, return, newline, formfeed, vertical tab).\n"
234
"  maxsplit\n"
235
"    Maximum number of splits to do.\n"
236
"    -1 (the default value) means no limit.");
237
238
#define BYTEARRAY_SPLIT_METHODDEF    \
239
    {"split", (PyCFunction)(void(*)(void))bytearray_split, METH_FASTCALL|METH_KEYWORDS, bytearray_split__doc__},
240
241
static PyObject *
242
bytearray_split_impl(PyByteArrayObject *self, PyObject *sep,
243
                     Py_ssize_t maxsplit);
244
245
static PyObject *
246
bytearray_split(PyByteArrayObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
247
0
{
248
0
    PyObject *return_value = NULL;
249
0
    static const char * const _keywords[] = {"sep", "maxsplit", NULL};
250
0
    static _PyArg_Parser _parser = {NULL, _keywords, "split", 0};
251
0
    PyObject *argsbuf[2];
252
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
253
0
    PyObject *sep = Py_None;
254
0
    Py_ssize_t maxsplit = -1;
255
256
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 2, 0, argsbuf);
257
0
    if (!args) {
258
0
        goto exit;
259
0
    }
260
0
    if (!noptargs) {
261
0
        goto skip_optional_pos;
262
0
    }
263
0
    if (args[0]) {
264
0
        sep = args[0];
265
0
        if (!--noptargs) {
266
0
            goto skip_optional_pos;
267
0
        }
268
0
    }
269
0
    if (PyFloat_Check(args[1])) {
270
0
        PyErr_SetString(PyExc_TypeError,
271
0
                        "integer argument expected, got float" );
272
0
        goto exit;
273
0
    }
274
0
    {
275
0
        Py_ssize_t ival = -1;
276
0
        PyObject *iobj = PyNumber_Index(args[1]);
277
0
        if (iobj != NULL) {
278
0
            ival = PyLong_AsSsize_t(iobj);
279
0
            Py_DECREF(iobj);
280
0
        }
281
0
        if (ival == -1 && PyErr_Occurred()) {
282
0
            goto exit;
283
0
        }
284
0
        maxsplit = ival;
285
0
    }
286
0
skip_optional_pos:
287
0
    return_value = bytearray_split_impl(self, sep, maxsplit);
288
289
0
exit:
290
0
    return return_value;
291
0
}
292
293
PyDoc_STRVAR(bytearray_partition__doc__,
294
"partition($self, sep, /)\n"
295
"--\n"
296
"\n"
297
"Partition the bytearray into three parts using the given separator.\n"
298
"\n"
299
"This will search for the separator sep in the bytearray. If the separator is\n"
300
"found, returns a 3-tuple containing the part before the separator, the\n"
301
"separator itself, and the part after it as new bytearray objects.\n"
302
"\n"
303
"If the separator is not found, returns a 3-tuple containing the copy of the\n"
304
"original bytearray object and two empty bytearray objects.");
305
306
#define BYTEARRAY_PARTITION_METHODDEF    \
307
    {"partition", (PyCFunction)bytearray_partition, METH_O, bytearray_partition__doc__},
308
309
PyDoc_STRVAR(bytearray_rpartition__doc__,
310
"rpartition($self, sep, /)\n"
311
"--\n"
312
"\n"
313
"Partition the bytearray into three parts using the given separator.\n"
314
"\n"
315
"This will search for the separator sep in the bytearray, starting at the end.\n"
316
"If the separator is found, returns a 3-tuple containing the part before the\n"
317
"separator, the separator itself, and the part after it as new bytearray\n"
318
"objects.\n"
319
"\n"
320
"If the separator is not found, returns a 3-tuple containing two empty bytearray\n"
321
"objects and the copy of the original bytearray object.");
322
323
#define BYTEARRAY_RPARTITION_METHODDEF    \
324
    {"rpartition", (PyCFunction)bytearray_rpartition, METH_O, bytearray_rpartition__doc__},
325
326
PyDoc_STRVAR(bytearray_rsplit__doc__,
327
"rsplit($self, /, sep=None, maxsplit=-1)\n"
328
"--\n"
329
"\n"
330
"Return a list of the sections in the bytearray, using sep as the delimiter.\n"
331
"\n"
332
"  sep\n"
333
"    The delimiter according which to split the bytearray.\n"
334
"    None (the default value) means split on ASCII whitespace characters\n"
335
"    (space, tab, return, newline, formfeed, vertical tab).\n"
336
"  maxsplit\n"
337
"    Maximum number of splits to do.\n"
338
"    -1 (the default value) means no limit.\n"
339
"\n"
340
"Splitting is done starting at the end of the bytearray and working to the front.");
341
342
#define BYTEARRAY_RSPLIT_METHODDEF    \
343
    {"rsplit", (PyCFunction)(void(*)(void))bytearray_rsplit, METH_FASTCALL|METH_KEYWORDS, bytearray_rsplit__doc__},
344
345
static PyObject *
346
bytearray_rsplit_impl(PyByteArrayObject *self, PyObject *sep,
347
                      Py_ssize_t maxsplit);
348
349
static PyObject *
350
bytearray_rsplit(PyByteArrayObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
351
0
{
352
0
    PyObject *return_value = NULL;
353
0
    static const char * const _keywords[] = {"sep", "maxsplit", NULL};
354
0
    static _PyArg_Parser _parser = {NULL, _keywords, "rsplit", 0};
355
0
    PyObject *argsbuf[2];
356
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
357
0
    PyObject *sep = Py_None;
358
0
    Py_ssize_t maxsplit = -1;
359
360
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 2, 0, argsbuf);
361
0
    if (!args) {
362
0
        goto exit;
363
0
    }
364
0
    if (!noptargs) {
365
0
        goto skip_optional_pos;
366
0
    }
367
0
    if (args[0]) {
368
0
        sep = args[0];
369
0
        if (!--noptargs) {
370
0
            goto skip_optional_pos;
371
0
        }
372
0
    }
373
0
    if (PyFloat_Check(args[1])) {
374
0
        PyErr_SetString(PyExc_TypeError,
375
0
                        "integer argument expected, got float" );
376
0
        goto exit;
377
0
    }
378
0
    {
379
0
        Py_ssize_t ival = -1;
380
0
        PyObject *iobj = PyNumber_Index(args[1]);
381
0
        if (iobj != NULL) {
382
0
            ival = PyLong_AsSsize_t(iobj);
383
0
            Py_DECREF(iobj);
384
0
        }
385
0
        if (ival == -1 && PyErr_Occurred()) {
386
0
            goto exit;
387
0
        }
388
0
        maxsplit = ival;
389
0
    }
390
0
skip_optional_pos:
391
0
    return_value = bytearray_rsplit_impl(self, sep, maxsplit);
392
393
0
exit:
394
0
    return return_value;
395
0
}
396
397
PyDoc_STRVAR(bytearray_reverse__doc__,
398
"reverse($self, /)\n"
399
"--\n"
400
"\n"
401
"Reverse the order of the values in B in place.");
402
403
#define BYTEARRAY_REVERSE_METHODDEF    \
404
    {"reverse", (PyCFunction)bytearray_reverse, METH_NOARGS, bytearray_reverse__doc__},
405
406
static PyObject *
407
bytearray_reverse_impl(PyByteArrayObject *self);
408
409
static PyObject *
410
bytearray_reverse(PyByteArrayObject *self, PyObject *Py_UNUSED(ignored))
411
0
{
412
0
    return bytearray_reverse_impl(self);
413
0
}
414
415
PyDoc_STRVAR(bytearray_insert__doc__,
416
"insert($self, index, item, /)\n"
417
"--\n"
418
"\n"
419
"Insert a single item into the bytearray before the given index.\n"
420
"\n"
421
"  index\n"
422
"    The index where the value is to be inserted.\n"
423
"  item\n"
424
"    The item to be inserted.");
425
426
#define BYTEARRAY_INSERT_METHODDEF    \
427
    {"insert", (PyCFunction)(void(*)(void))bytearray_insert, METH_FASTCALL, bytearray_insert__doc__},
428
429
static PyObject *
430
bytearray_insert_impl(PyByteArrayObject *self, Py_ssize_t index, int item);
431
432
static PyObject *
433
bytearray_insert(PyByteArrayObject *self, PyObject *const *args, Py_ssize_t nargs)
434
0
{
435
0
    PyObject *return_value = NULL;
436
0
    Py_ssize_t index;
437
0
    int item;
438
439
0
    if (!_PyArg_CheckPositional("insert", nargs, 2, 2)) {
440
0
        goto exit;
441
0
    }
442
0
    if (PyFloat_Check(args[0])) {
443
0
        PyErr_SetString(PyExc_TypeError,
444
0
                        "integer argument expected, got float" );
445
0
        goto exit;
446
0
    }
447
0
    {
448
0
        Py_ssize_t ival = -1;
449
0
        PyObject *iobj = PyNumber_Index(args[0]);
450
0
        if (iobj != NULL) {
451
0
            ival = PyLong_AsSsize_t(iobj);
452
0
            Py_DECREF(iobj);
453
0
        }
454
0
        if (ival == -1 && PyErr_Occurred()) {
455
0
            goto exit;
456
0
        }
457
0
        index = ival;
458
0
    }
459
0
    if (!_getbytevalue(args[1], &item)) {
460
0
        goto exit;
461
0
    }
462
0
    return_value = bytearray_insert_impl(self, index, item);
463
464
0
exit:
465
0
    return return_value;
466
0
}
467
468
PyDoc_STRVAR(bytearray_append__doc__,
469
"append($self, item, /)\n"
470
"--\n"
471
"\n"
472
"Append a single item to the end of the bytearray.\n"
473
"\n"
474
"  item\n"
475
"    The item to be appended.");
476
477
#define BYTEARRAY_APPEND_METHODDEF    \
478
    {"append", (PyCFunction)bytearray_append, METH_O, bytearray_append__doc__},
479
480
static PyObject *
481
bytearray_append_impl(PyByteArrayObject *self, int item);
482
483
static PyObject *
484
bytearray_append(PyByteArrayObject *self, PyObject *arg)
485
0
{
486
0
    PyObject *return_value = NULL;
487
0
    int item;
488
489
0
    if (!_getbytevalue(arg, &item)) {
490
0
        goto exit;
491
0
    }
492
0
    return_value = bytearray_append_impl(self, item);
493
494
0
exit:
495
0
    return return_value;
496
0
}
497
498
PyDoc_STRVAR(bytearray_extend__doc__,
499
"extend($self, iterable_of_ints, /)\n"
500
"--\n"
501
"\n"
502
"Append all the items from the iterator or sequence to the end of the bytearray.\n"
503
"\n"
504
"  iterable_of_ints\n"
505
"    The iterable of items to append.");
506
507
#define BYTEARRAY_EXTEND_METHODDEF    \
508
    {"extend", (PyCFunction)bytearray_extend, METH_O, bytearray_extend__doc__},
509
510
PyDoc_STRVAR(bytearray_pop__doc__,
511
"pop($self, index=-1, /)\n"
512
"--\n"
513
"\n"
514
"Remove and return a single item from B.\n"
515
"\n"
516
"  index\n"
517
"    The index from where to remove the item.\n"
518
"    -1 (the default value) means remove the last item.\n"
519
"\n"
520
"If no index argument is given, will pop the last item.");
521
522
#define BYTEARRAY_POP_METHODDEF    \
523
    {"pop", (PyCFunction)(void(*)(void))bytearray_pop, METH_FASTCALL, bytearray_pop__doc__},
524
525
static PyObject *
526
bytearray_pop_impl(PyByteArrayObject *self, Py_ssize_t index);
527
528
static PyObject *
529
bytearray_pop(PyByteArrayObject *self, PyObject *const *args, Py_ssize_t nargs)
530
0
{
531
0
    PyObject *return_value = NULL;
532
0
    Py_ssize_t index = -1;
533
534
0
    if (!_PyArg_CheckPositional("pop", nargs, 0, 1)) {
535
0
        goto exit;
536
0
    }
537
0
    if (nargs < 1) {
538
0
        goto skip_optional;
539
0
    }
540
0
    if (PyFloat_Check(args[0])) {
541
0
        PyErr_SetString(PyExc_TypeError,
542
0
                        "integer argument expected, got float" );
543
0
        goto exit;
544
0
    }
545
0
    {
546
0
        Py_ssize_t ival = -1;
547
0
        PyObject *iobj = PyNumber_Index(args[0]);
548
0
        if (iobj != NULL) {
549
0
            ival = PyLong_AsSsize_t(iobj);
550
0
            Py_DECREF(iobj);
551
0
        }
552
0
        if (ival == -1 && PyErr_Occurred()) {
553
0
            goto exit;
554
0
        }
555
0
        index = ival;
556
0
    }
557
0
skip_optional:
558
0
    return_value = bytearray_pop_impl(self, index);
559
560
0
exit:
561
0
    return return_value;
562
0
}
563
564
PyDoc_STRVAR(bytearray_remove__doc__,
565
"remove($self, value, /)\n"
566
"--\n"
567
"\n"
568
"Remove the first occurrence of a value in the bytearray.\n"
569
"\n"
570
"  value\n"
571
"    The value to remove.");
572
573
#define BYTEARRAY_REMOVE_METHODDEF    \
574
    {"remove", (PyCFunction)bytearray_remove, METH_O, bytearray_remove__doc__},
575
576
static PyObject *
577
bytearray_remove_impl(PyByteArrayObject *self, int value);
578
579
static PyObject *
580
bytearray_remove(PyByteArrayObject *self, PyObject *arg)
581
0
{
582
0
    PyObject *return_value = NULL;
583
0
    int value;
584
585
0
    if (!_getbytevalue(arg, &value)) {
586
0
        goto exit;
587
0
    }
588
0
    return_value = bytearray_remove_impl(self, value);
589
590
0
exit:
591
0
    return return_value;
592
0
}
593
594
PyDoc_STRVAR(bytearray_strip__doc__,
595
"strip($self, bytes=None, /)\n"
596
"--\n"
597
"\n"
598
"Strip leading and trailing bytes contained in the argument.\n"
599
"\n"
600
"If the argument is omitted or None, strip leading and trailing ASCII whitespace.");
601
602
#define BYTEARRAY_STRIP_METHODDEF    \
603
    {"strip", (PyCFunction)(void(*)(void))bytearray_strip, METH_FASTCALL, bytearray_strip__doc__},
604
605
static PyObject *
606
bytearray_strip_impl(PyByteArrayObject *self, PyObject *bytes);
607
608
static PyObject *
609
bytearray_strip(PyByteArrayObject *self, PyObject *const *args, Py_ssize_t nargs)
610
0
{
611
0
    PyObject *return_value = NULL;
612
0
    PyObject *bytes = Py_None;
613
614
0
    if (!_PyArg_CheckPositional("strip", nargs, 0, 1)) {
615
0
        goto exit;
616
0
    }
617
0
    if (nargs < 1) {
618
0
        goto skip_optional;
619
0
    }
620
0
    bytes = args[0];
621
0
skip_optional:
622
0
    return_value = bytearray_strip_impl(self, bytes);
623
624
0
exit:
625
0
    return return_value;
626
0
}
627
628
PyDoc_STRVAR(bytearray_lstrip__doc__,
629
"lstrip($self, bytes=None, /)\n"
630
"--\n"
631
"\n"
632
"Strip leading bytes contained in the argument.\n"
633
"\n"
634
"If the argument is omitted or None, strip leading ASCII whitespace.");
635
636
#define BYTEARRAY_LSTRIP_METHODDEF    \
637
    {"lstrip", (PyCFunction)(void(*)(void))bytearray_lstrip, METH_FASTCALL, bytearray_lstrip__doc__},
638
639
static PyObject *
640
bytearray_lstrip_impl(PyByteArrayObject *self, PyObject *bytes);
641
642
static PyObject *
643
bytearray_lstrip(PyByteArrayObject *self, PyObject *const *args, Py_ssize_t nargs)
644
0
{
645
0
    PyObject *return_value = NULL;
646
0
    PyObject *bytes = Py_None;
647
648
0
    if (!_PyArg_CheckPositional("lstrip", nargs, 0, 1)) {
649
0
        goto exit;
650
0
    }
651
0
    if (nargs < 1) {
652
0
        goto skip_optional;
653
0
    }
654
0
    bytes = args[0];
655
0
skip_optional:
656
0
    return_value = bytearray_lstrip_impl(self, bytes);
657
658
0
exit:
659
0
    return return_value;
660
0
}
661
662
PyDoc_STRVAR(bytearray_rstrip__doc__,
663
"rstrip($self, bytes=None, /)\n"
664
"--\n"
665
"\n"
666
"Strip trailing bytes contained in the argument.\n"
667
"\n"
668
"If the argument is omitted or None, strip trailing ASCII whitespace.");
669
670
#define BYTEARRAY_RSTRIP_METHODDEF    \
671
    {"rstrip", (PyCFunction)(void(*)(void))bytearray_rstrip, METH_FASTCALL, bytearray_rstrip__doc__},
672
673
static PyObject *
674
bytearray_rstrip_impl(PyByteArrayObject *self, PyObject *bytes);
675
676
static PyObject *
677
bytearray_rstrip(PyByteArrayObject *self, PyObject *const *args, Py_ssize_t nargs)
678
0
{
679
0
    PyObject *return_value = NULL;
680
0
    PyObject *bytes = Py_None;
681
682
0
    if (!_PyArg_CheckPositional("rstrip", nargs, 0, 1)) {
683
0
        goto exit;
684
0
    }
685
0
    if (nargs < 1) {
686
0
        goto skip_optional;
687
0
    }
688
0
    bytes = args[0];
689
0
skip_optional:
690
0
    return_value = bytearray_rstrip_impl(self, bytes);
691
692
0
exit:
693
0
    return return_value;
694
0
}
695
696
PyDoc_STRVAR(bytearray_decode__doc__,
697
"decode($self, /, encoding=\'utf-8\', errors=\'strict\')\n"
698
"--\n"
699
"\n"
700
"Decode the bytearray using the codec registered for encoding.\n"
701
"\n"
702
"  encoding\n"
703
"    The encoding with which to decode the bytearray.\n"
704
"  errors\n"
705
"    The error handling scheme to use for the handling of decoding errors.\n"
706
"    The default is \'strict\' meaning that decoding errors raise a\n"
707
"    UnicodeDecodeError. Other possible values are \'ignore\' and \'replace\'\n"
708
"    as well as any other name registered with codecs.register_error that\n"
709
"    can handle UnicodeDecodeErrors.");
710
711
#define BYTEARRAY_DECODE_METHODDEF    \
712
    {"decode", (PyCFunction)(void(*)(void))bytearray_decode, METH_FASTCALL|METH_KEYWORDS, bytearray_decode__doc__},
713
714
static PyObject *
715
bytearray_decode_impl(PyByteArrayObject *self, const char *encoding,
716
                      const char *errors);
717
718
static PyObject *
719
bytearray_decode(PyByteArrayObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
720
0
{
721
0
    PyObject *return_value = NULL;
722
0
    static const char * const _keywords[] = {"encoding", "errors", NULL};
723
0
    static _PyArg_Parser _parser = {NULL, _keywords, "decode", 0};
724
0
    PyObject *argsbuf[2];
725
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
726
0
    const char *encoding = NULL;
727
0
    const char *errors = NULL;
728
729
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 2, 0, argsbuf);
730
0
    if (!args) {
731
0
        goto exit;
732
0
    }
733
0
    if (!noptargs) {
734
0
        goto skip_optional_pos;
735
0
    }
736
0
    if (args[0]) {
737
0
        if (!PyUnicode_Check(args[0])) {
738
0
            _PyArg_BadArgument("decode", "argument 'encoding'", "str", args[0]);
739
0
            goto exit;
740
0
        }
741
0
        Py_ssize_t encoding_length;
742
0
        encoding = PyUnicode_AsUTF8AndSize(args[0], &encoding_length);
743
0
        if (encoding == NULL) {
744
0
            goto exit;
745
0
        }
746
0
        if (strlen(encoding) != (size_t)encoding_length) {
747
0
            PyErr_SetString(PyExc_ValueError, "embedded null character");
748
0
            goto exit;
749
0
        }
750
0
        if (!--noptargs) {
751
0
            goto skip_optional_pos;
752
0
        }
753
0
    }
754
0
    if (!PyUnicode_Check(args[1])) {
755
0
        _PyArg_BadArgument("decode", "argument 'errors'", "str", args[1]);
756
0
        goto exit;
757
0
    }
758
0
    Py_ssize_t errors_length;
759
0
    errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
760
0
    if (errors == NULL) {
761
0
        goto exit;
762
0
    }
763
0
    if (strlen(errors) != (size_t)errors_length) {
764
0
        PyErr_SetString(PyExc_ValueError, "embedded null character");
765
0
        goto exit;
766
0
    }
767
0
skip_optional_pos:
768
0
    return_value = bytearray_decode_impl(self, encoding, errors);
769
770
0
exit:
771
0
    return return_value;
772
0
}
773
774
PyDoc_STRVAR(bytearray_join__doc__,
775
"join($self, iterable_of_bytes, /)\n"
776
"--\n"
777
"\n"
778
"Concatenate any number of bytes/bytearray objects.\n"
779
"\n"
780
"The bytearray whose method is called is inserted in between each pair.\n"
781
"\n"
782
"The result is returned as a new bytearray object.");
783
784
#define BYTEARRAY_JOIN_METHODDEF    \
785
    {"join", (PyCFunction)bytearray_join, METH_O, bytearray_join__doc__},
786
787
PyDoc_STRVAR(bytearray_splitlines__doc__,
788
"splitlines($self, /, keepends=False)\n"
789
"--\n"
790
"\n"
791
"Return a list of the lines in the bytearray, breaking at line boundaries.\n"
792
"\n"
793
"Line breaks are not included in the resulting list unless keepends is given and\n"
794
"true.");
795
796
#define BYTEARRAY_SPLITLINES_METHODDEF    \
797
    {"splitlines", (PyCFunction)(void(*)(void))bytearray_splitlines, METH_FASTCALL|METH_KEYWORDS, bytearray_splitlines__doc__},
798
799
static PyObject *
800
bytearray_splitlines_impl(PyByteArrayObject *self, int keepends);
801
802
static PyObject *
803
bytearray_splitlines(PyByteArrayObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
804
0
{
805
0
    PyObject *return_value = NULL;
806
0
    static const char * const _keywords[] = {"keepends", NULL};
807
0
    static _PyArg_Parser _parser = {NULL, _keywords, "splitlines", 0};
808
0
    PyObject *argsbuf[1];
809
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
810
0
    int keepends = 0;
811
812
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
813
0
    if (!args) {
814
0
        goto exit;
815
0
    }
816
0
    if (!noptargs) {
817
0
        goto skip_optional_pos;
818
0
    }
819
0
    if (PyFloat_Check(args[0])) {
820
0
        PyErr_SetString(PyExc_TypeError,
821
0
                        "integer argument expected, got float" );
822
0
        goto exit;
823
0
    }
824
0
    keepends = _PyLong_AsInt(args[0]);
825
0
    if (keepends == -1 && PyErr_Occurred()) {
826
0
        goto exit;
827
0
    }
828
0
skip_optional_pos:
829
0
    return_value = bytearray_splitlines_impl(self, keepends);
830
831
0
exit:
832
0
    return return_value;
833
0
}
834
835
PyDoc_STRVAR(bytearray_fromhex__doc__,
836
"fromhex($type, string, /)\n"
837
"--\n"
838
"\n"
839
"Create a bytearray object from a string of hexadecimal numbers.\n"
840
"\n"
841
"Spaces between two numbers are accepted.\n"
842
"Example: bytearray.fromhex(\'B9 01EF\') -> bytearray(b\'\\\\xb9\\\\x01\\\\xef\')");
843
844
#define BYTEARRAY_FROMHEX_METHODDEF    \
845
    {"fromhex", (PyCFunction)bytearray_fromhex, METH_O|METH_CLASS, bytearray_fromhex__doc__},
846
847
static PyObject *
848
bytearray_fromhex_impl(PyTypeObject *type, PyObject *string);
849
850
static PyObject *
851
bytearray_fromhex(PyTypeObject *type, PyObject *arg)
852
0
{
853
0
    PyObject *return_value = NULL;
854
0
    PyObject *string;
855
856
0
    if (!PyUnicode_Check(arg)) {
857
0
        _PyArg_BadArgument("fromhex", "argument", "str", arg);
858
0
        goto exit;
859
0
    }
860
0
    if (PyUnicode_READY(arg) == -1) {
861
0
        goto exit;
862
0
    }
863
0
    string = arg;
864
0
    return_value = bytearray_fromhex_impl(type, string);
865
866
0
exit:
867
0
    return return_value;
868
0
}
869
870
PyDoc_STRVAR(bytearray_hex__doc__,
871
"hex($self, /, sep=<unrepresentable>, bytes_per_sep=1)\n"
872
"--\n"
873
"\n"
874
"Create a str of hexadecimal numbers from a bytearray object.\n"
875
"\n"
876
"  sep\n"
877
"    An optional single character or byte to separate hex bytes.\n"
878
"  bytes_per_sep\n"
879
"    How many bytes between separators.  Positive values count from the\n"
880
"    right, negative values count from the left.\n"
881
"\n"
882
"Example:\n"
883
">>> value = bytearray([0xb9, 0x01, 0xef])\n"
884
">>> value.hex()\n"
885
"\'b901ef\'\n"
886
">>> value.hex(\':\')\n"
887
"\'b9:01:ef\'\n"
888
">>> value.hex(\':\', 2)\n"
889
"\'b9:01ef\'\n"
890
">>> value.hex(\':\', -2)\n"
891
"\'b901:ef\'");
892
893
#define BYTEARRAY_HEX_METHODDEF    \
894
    {"hex", (PyCFunction)(void(*)(void))bytearray_hex, METH_FASTCALL|METH_KEYWORDS, bytearray_hex__doc__},
895
896
static PyObject *
897
bytearray_hex_impl(PyByteArrayObject *self, PyObject *sep, int bytes_per_sep);
898
899
static PyObject *
900
bytearray_hex(PyByteArrayObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
901
0
{
902
0
    PyObject *return_value = NULL;
903
0
    static const char * const _keywords[] = {"sep", "bytes_per_sep", NULL};
904
0
    static _PyArg_Parser _parser = {NULL, _keywords, "hex", 0};
905
0
    PyObject *argsbuf[2];
906
0
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
907
0
    PyObject *sep = NULL;
908
0
    int bytes_per_sep = 1;
909
910
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 2, 0, argsbuf);
911
0
    if (!args) {
912
0
        goto exit;
913
0
    }
914
0
    if (!noptargs) {
915
0
        goto skip_optional_pos;
916
0
    }
917
0
    if (args[0]) {
918
0
        sep = args[0];
919
0
        if (!--noptargs) {
920
0
            goto skip_optional_pos;
921
0
        }
922
0
    }
923
0
    if (PyFloat_Check(args[1])) {
924
0
        PyErr_SetString(PyExc_TypeError,
925
0
                        "integer argument expected, got float" );
926
0
        goto exit;
927
0
    }
928
0
    bytes_per_sep = _PyLong_AsInt(args[1]);
929
0
    if (bytes_per_sep == -1 && PyErr_Occurred()) {
930
0
        goto exit;
931
0
    }
932
0
skip_optional_pos:
933
0
    return_value = bytearray_hex_impl(self, sep, bytes_per_sep);
934
935
0
exit:
936
0
    return return_value;
937
0
}
938
939
PyDoc_STRVAR(bytearray_reduce__doc__,
940
"__reduce__($self, /)\n"
941
"--\n"
942
"\n"
943
"Return state information for pickling.");
944
945
#define BYTEARRAY_REDUCE_METHODDEF    \
946
    {"__reduce__", (PyCFunction)bytearray_reduce, METH_NOARGS, bytearray_reduce__doc__},
947
948
static PyObject *
949
bytearray_reduce_impl(PyByteArrayObject *self);
950
951
static PyObject *
952
bytearray_reduce(PyByteArrayObject *self, PyObject *Py_UNUSED(ignored))
953
0
{
954
0
    return bytearray_reduce_impl(self);
955
0
}
956
957
PyDoc_STRVAR(bytearray_reduce_ex__doc__,
958
"__reduce_ex__($self, proto=0, /)\n"
959
"--\n"
960
"\n"
961
"Return state information for pickling.");
962
963
#define BYTEARRAY_REDUCE_EX_METHODDEF    \
964
    {"__reduce_ex__", (PyCFunction)(void(*)(void))bytearray_reduce_ex, METH_FASTCALL, bytearray_reduce_ex__doc__},
965
966
static PyObject *
967
bytearray_reduce_ex_impl(PyByteArrayObject *self, int proto);
968
969
static PyObject *
970
bytearray_reduce_ex(PyByteArrayObject *self, PyObject *const *args, Py_ssize_t nargs)
971
0
{
972
0
    PyObject *return_value = NULL;
973
0
    int proto = 0;
974
975
0
    if (!_PyArg_CheckPositional("__reduce_ex__", nargs, 0, 1)) {
976
0
        goto exit;
977
0
    }
978
0
    if (nargs < 1) {
979
0
        goto skip_optional;
980
0
    }
981
0
    if (PyFloat_Check(args[0])) {
982
0
        PyErr_SetString(PyExc_TypeError,
983
0
                        "integer argument expected, got float" );
984
0
        goto exit;
985
0
    }
986
0
    proto = _PyLong_AsInt(args[0]);
987
0
    if (proto == -1 && PyErr_Occurred()) {
988
0
        goto exit;
989
0
    }
990
0
skip_optional:
991
0
    return_value = bytearray_reduce_ex_impl(self, proto);
992
993
0
exit:
994
0
    return return_value;
995
0
}
996
997
PyDoc_STRVAR(bytearray_sizeof__doc__,
998
"__sizeof__($self, /)\n"
999
"--\n"
1000
"\n"
1001
"Returns the size of the bytearray object in memory, in bytes.");
1002
1003
#define BYTEARRAY_SIZEOF_METHODDEF    \
1004
    {"__sizeof__", (PyCFunction)bytearray_sizeof, METH_NOARGS, bytearray_sizeof__doc__},
1005
1006
static PyObject *
1007
bytearray_sizeof_impl(PyByteArrayObject *self);
1008
1009
static PyObject *
1010
bytearray_sizeof(PyByteArrayObject *self, PyObject *Py_UNUSED(ignored))
1011
0
{
1012
0
    return bytearray_sizeof_impl(self);
1013
0
}
1014
/*[clinic end generated code: output=508dce79cf2dffcc input=a9049054013a1b77]*/