Coverage Report

Created: 2022-07-08 09:39

/home/mdboom/Work/builds/cpython/Objects/clinic/bytesobject.c.h
Line
Count
Source (jump to first uncovered line)
1
/*[clinic input]
2
preserve
3
[clinic start generated code]*/
4
5
PyDoc_STRVAR(bytes___bytes____doc__,
6
"__bytes__($self, /)\n"
7
"--\n"
8
"\n"
9
"Convert this value to exact type bytes.");
10
11
#define BYTES___BYTES___METHODDEF    \
12
    {"__bytes__", (PyCFunction)bytes___bytes__, METH_NOARGS, bytes___bytes____doc__},
13
14
static PyObject *
15
bytes___bytes___impl(PyBytesObject *self);
16
17
static PyObject *
18
bytes___bytes__(PyBytesObject *self, PyObject *Py_UNUSED(ignored))
19
{
20
    return bytes___bytes___impl(self);
21
}
22
23
PyDoc_STRVAR(bytes_split__doc__,
24
"split($self, /, sep=None, maxsplit=-1)\n"
25
"--\n"
26
"\n"
27
"Return a list of the sections in the bytes, using sep as the delimiter.\n"
28
"\n"
29
"  sep\n"
30
"    The delimiter according which to split the bytes.\n"
31
"    None (the default value) means split on ASCII whitespace characters\n"
32
"    (space, tab, return, newline, formfeed, vertical tab).\n"
33
"  maxsplit\n"
34
"    Maximum number of splits to do.\n"
35
"    -1 (the default value) means no limit.");
36
37
#define BYTES_SPLIT_METHODDEF    \
38
    {"split", _PyCFunction_CAST(bytes_split), METH_FASTCALL|METH_KEYWORDS, bytes_split__doc__},
39
40
static PyObject *
41
bytes_split_impl(PyBytesObject *self, PyObject *sep, Py_ssize_t maxsplit);
42
43
static PyObject *
44
bytes_split(PyBytesObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
45
{
46
    PyObject *return_value = NULL;
47
    static const char * const _keywords[] = {"sep", "maxsplit", NULL};
48
    static _PyArg_Parser _parser = {NULL, _keywords, "split", 0};
49
    PyObject *argsbuf[2];
50
    Py_ssize_t noptargs = nargs + (kwnames ? 
PyTuple_GET_SIZE5
(kwnames) :
07.14k
) - 0;
  Branch (50:36): [True: 5, False: 7.14k]
51
    PyObject *sep = Py_None;
52
    Py_ssize_t maxsplit = -1;
53
54
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 2, 0, argsbuf);
55
    if (!args) {
  Branch (55:9): [True: 1, False: 7.14k]
56
        goto exit;
57
    }
58
    if (!noptargs) {
  Branch (58:9): [True: 120, False: 7.02k]
59
        goto skip_optional_pos;
60
    }
61
    if (args[0]) {
  Branch (61:9): [True: 7.02k, False: 1]
62
        sep = args[0];
63
        if (!--noptargs) {
  Branch (63:13): [True: 3.09k, False: 3.93k]
64
            goto skip_optional_pos;
65
        }
66
    }
67
    {
68
        Py_ssize_t ival = -1;
69
        PyObject *iobj = _PyNumber_Index(args[1]);
70
        if (iobj != NULL) {
  Branch (70:13): [True: 3.93k, False: 0]
71
            ival = PyLong_AsSsize_t(iobj);
72
            Py_DECREF(iobj);
73
        }
74
        if (ival == -1 && 
PyErr_Occurred()0
) {
  Branch (74:13): [True: 0, False: 3.93k]
  Branch (74:27): [True: 0, False: 0]
75
            goto exit;
76
        }
77
        maxsplit = ival;
78
    }
79
skip_optional_pos:
80
    return_value = bytes_split_impl(self, sep, maxsplit);
81
82
exit:
83
    return return_value;
84
}
85
86
PyDoc_STRVAR(bytes_partition__doc__,
87
"partition($self, sep, /)\n"
88
"--\n"
89
"\n"
90
"Partition the bytes into three parts using the given separator.\n"
91
"\n"
92
"This will search for the separator sep in the bytes. If the separator is found,\n"
93
"returns a 3-tuple containing the part before the separator, the separator\n"
94
"itself, and the part after it.\n"
95
"\n"
96
"If the separator is not found, returns a 3-tuple containing the original bytes\n"
97
"object and two empty bytes objects.");
98
99
#define BYTES_PARTITION_METHODDEF    \
100
    {"partition", (PyCFunction)bytes_partition, METH_O, bytes_partition__doc__},
101
102
static PyObject *
103
bytes_partition_impl(PyBytesObject *self, Py_buffer *sep);
104
105
static PyObject *
106
bytes_partition(PyBytesObject *self, PyObject *arg)
107
{
108
    PyObject *return_value = NULL;
109
    Py_buffer sep = {NULL, NULL};
110
111
    if (PyObject_GetBuffer(arg, &sep, PyBUF_SIMPLE) != 0) {
  Branch (111:9): [True: 2, False: 882]
112
        goto exit;
113
    }
114
    if (!PyBuffer_IsContiguous(&sep, 'C')) {
  Branch (114:9): [True: 0, False: 882]
115
        _PyArg_BadArgument("partition", "argument", "contiguous buffer", arg);
116
        goto exit;
117
    }
118
    return_value = bytes_partition_impl(self, &sep);
119
120
exit:
121
    /* Cleanup for sep */
122
    if (sep.obj) {
  Branch (122:9): [True: 882, False: 2]
123
       PyBuffer_Release(&sep);
124
    }
125
126
    return return_value;
127
}
128
129
PyDoc_STRVAR(bytes_rpartition__doc__,
130
"rpartition($self, sep, /)\n"
131
"--\n"
132
"\n"
133
"Partition the bytes into three parts using the given separator.\n"
134
"\n"
135
"This will search for the separator sep in the bytes, starting at the end. If\n"
136
"the separator is found, returns a 3-tuple containing the part before the\n"
137
"separator, the separator itself, and the part after it.\n"
138
"\n"
139
"If the separator is not found, returns a 3-tuple containing two empty bytes\n"
140
"objects and the original bytes object.");
141
142
#define BYTES_RPARTITION_METHODDEF    \
143
    {"rpartition", (PyCFunction)bytes_rpartition, METH_O, bytes_rpartition__doc__},
144
145
static PyObject *
146
bytes_rpartition_impl(PyBytesObject *self, Py_buffer *sep);
147
148
static PyObject *
149
bytes_rpartition(PyBytesObject *self, PyObject *arg)
150
{
151
    PyObject *return_value = NULL;
152
    Py_buffer sep = {NULL, NULL};
153
154
    if (PyObject_GetBuffer(arg, &sep, PyBUF_SIMPLE) != 0) {
  Branch (154:9): [True: 2, False: 341]
155
        goto exit;
156
    }
157
    if (!PyBuffer_IsContiguous(&sep, 'C')) {
  Branch (157:9): [True: 0, False: 341]
158
        _PyArg_BadArgument("rpartition", "argument", "contiguous buffer", arg);
159
        goto exit;
160
    }
161
    return_value = bytes_rpartition_impl(self, &sep);
162
163
exit:
164
    /* Cleanup for sep */
165
    if (sep.obj) {
  Branch (165:9): [True: 341, False: 2]
166
       PyBuffer_Release(&sep);
167
    }
168
169
    return return_value;
170
}
171
172
PyDoc_STRVAR(bytes_rsplit__doc__,
173
"rsplit($self, /, sep=None, maxsplit=-1)\n"
174
"--\n"
175
"\n"
176
"Return a list of the sections in the bytes, using sep as the delimiter.\n"
177
"\n"
178
"  sep\n"
179
"    The delimiter according which to split the bytes.\n"
180
"    None (the default value) means split on ASCII whitespace characters\n"
181
"    (space, tab, return, newline, formfeed, vertical tab).\n"
182
"  maxsplit\n"
183
"    Maximum number of splits to do.\n"
184
"    -1 (the default value) means no limit.\n"
185
"\n"
186
"Splitting is done starting at the end of the bytes and working to the front.");
187
188
#define BYTES_RSPLIT_METHODDEF    \
189
    {"rsplit", _PyCFunction_CAST(bytes_rsplit), METH_FASTCALL|METH_KEYWORDS, bytes_rsplit__doc__},
190
191
static PyObject *
192
bytes_rsplit_impl(PyBytesObject *self, PyObject *sep, Py_ssize_t maxsplit);
193
194
static PyObject *
195
bytes_rsplit(PyBytesObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
196
{
197
    PyObject *return_value = NULL;
198
    static const char * const _keywords[] = {"sep", "maxsplit", NULL};
199
    static _PyArg_Parser _parser = {NULL, _keywords, "rsplit", 0};
200
    PyObject *argsbuf[2];
201
    Py_ssize_t noptargs = nargs + (kwnames ? 
PyTuple_GET_SIZE5
(kwnames) :
083
) - 0;
  Branch (201:36): [True: 5, False: 83]
202
    PyObject *sep = Py_None;
203
    Py_ssize_t maxsplit = -1;
204
205
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 2, 0, argsbuf);
206
    if (!args) {
  Branch (206:9): [True: 1, False: 87]
207
        goto exit;
208
    }
209
    if (!noptargs) {
  Branch (209:9): [True: 12, False: 75]
210
        goto skip_optional_pos;
211
    }
212
    if (args[0]) {
  Branch (212:9): [True: 74, False: 1]
213
        sep = args[0];
214
        if (!--noptargs) {
  Branch (214:13): [True: 30, False: 44]
215
            goto skip_optional_pos;
216
        }
217
    }
218
    {
219
        Py_ssize_t ival = -1;
220
        PyObject *iobj = _PyNumber_Index(args[1]);
221
        if (iobj != NULL) {
  Branch (221:13): [True: 45, False: 0]
222
            ival = PyLong_AsSsize_t(iobj);
223
            Py_DECREF(iobj);
224
        }
225
        if (ival == -1 && 
PyErr_Occurred()0
) {
  Branch (225:13): [True: 0, False: 45]
  Branch (225:27): [True: 0, False: 0]
226
            goto exit;
227
        }
228
        maxsplit = ival;
229
    }
230
skip_optional_pos:
231
    return_value = bytes_rsplit_impl(self, sep, maxsplit);
232
233
exit:
234
    return return_value;
235
}
236
237
PyDoc_STRVAR(bytes_join__doc__,
238
"join($self, iterable_of_bytes, /)\n"
239
"--\n"
240
"\n"
241
"Concatenate any number of bytes objects.\n"
242
"\n"
243
"The bytes whose method is called is inserted in between each pair.\n"
244
"\n"
245
"The result is returned as a new bytes object.\n"
246
"\n"
247
"Example: b\'.\'.join([b\'ab\', b\'pq\', b\'rs\']) -> b\'ab.pq.rs\'.");
248
249
#define BYTES_JOIN_METHODDEF    \
250
    {"join", (PyCFunction)bytes_join, METH_O, bytes_join__doc__},
251
252
PyDoc_STRVAR(bytes_strip__doc__,
253
"strip($self, bytes=None, /)\n"
254
"--\n"
255
"\n"
256
"Strip leading and trailing bytes contained in the argument.\n"
257
"\n"
258
"If the argument is omitted or None, strip leading and trailing ASCII whitespace.");
259
260
#define BYTES_STRIP_METHODDEF    \
261
    {"strip", _PyCFunction_CAST(bytes_strip), METH_FASTCALL, bytes_strip__doc__},
262
263
static PyObject *
264
bytes_strip_impl(PyBytesObject *self, PyObject *bytes);
265
266
static PyObject *
267
bytes_strip(PyBytesObject *self, PyObject *const *args, Py_ssize_t nargs)
268
{
269
    PyObject *return_value = NULL;
270
    PyObject *bytes = Py_None;
271
272
    if (!_PyArg_CheckPositional("strip", nargs, 0, 1)) {
273
        goto exit;
274
    }
275
    if (nargs < 1) {
  Branch (275:9): [True: 1.50k, False: 561]
276
        goto skip_optional;
277
    }
278
    bytes = args[0];
279
skip_optional:
280
    return_value = bytes_strip_impl(self, bytes);
281
282
exit:
283
    return return_value;
284
}
285
286
PyDoc_STRVAR(bytes_lstrip__doc__,
287
"lstrip($self, bytes=None, /)\n"
288
"--\n"
289
"\n"
290
"Strip leading bytes contained in the argument.\n"
291
"\n"
292
"If the argument is omitted or None, strip leading  ASCII whitespace.");
293
294
#define BYTES_LSTRIP_METHODDEF    \
295
    {"lstrip", _PyCFunction_CAST(bytes_lstrip), METH_FASTCALL, bytes_lstrip__doc__},
296
297
static PyObject *
298
bytes_lstrip_impl(PyBytesObject *self, PyObject *bytes);
299
300
static PyObject *
301
bytes_lstrip(PyBytesObject *self, PyObject *const *args, Py_ssize_t nargs)
302
{
303
    PyObject *return_value = NULL;
304
    PyObject *bytes = Py_None;
305
306
    if (!_PyArg_CheckPositional("lstrip", nargs, 0, 1)) {
307
        goto exit;
308
    }
309
    if (nargs < 1) {
  Branch (309:9): [True: 7, False: 132]
310
        goto skip_optional;
311
    }
312
    bytes = args[0];
313
skip_optional:
314
    return_value = bytes_lstrip_impl(self, bytes);
315
316
exit:
317
    return return_value;
318
}
319
320
PyDoc_STRVAR(bytes_rstrip__doc__,
321
"rstrip($self, bytes=None, /)\n"
322
"--\n"
323
"\n"
324
"Strip trailing bytes contained in the argument.\n"
325
"\n"
326
"If the argument is omitted or None, strip trailing ASCII whitespace.");
327
328
#define BYTES_RSTRIP_METHODDEF    \
329
    {"rstrip", _PyCFunction_CAST(bytes_rstrip), METH_FASTCALL, bytes_rstrip__doc__},
330
331
static PyObject *
332
bytes_rstrip_impl(PyBytesObject *self, PyObject *bytes);
333
334
static PyObject *
335
bytes_rstrip(PyBytesObject *self, PyObject *const *args, Py_ssize_t nargs)
336
{
337
    PyObject *return_value = NULL;
338
    PyObject *bytes = Py_None;
339
340
    if (!_PyArg_CheckPositional("rstrip", nargs, 0, 1)) {
341
        goto exit;
342
    }
343
    if (nargs < 1) {
  Branch (343:9): [True: 235, False: 4.92k]
344
        goto skip_optional;
345
    }
346
    bytes = args[0];
347
skip_optional:
348
    return_value = bytes_rstrip_impl(self, bytes);
349
350
exit:
351
    return return_value;
352
}
353
354
PyDoc_STRVAR(bytes_translate__doc__,
355
"translate($self, table, /, delete=b\'\')\n"
356
"--\n"
357
"\n"
358
"Return a copy with each character mapped by the given translation table.\n"
359
"\n"
360
"  table\n"
361
"    Translation table, which must be a bytes object of length 256.\n"
362
"\n"
363
"All characters occurring in the optional argument delete are removed.\n"
364
"The remaining characters are mapped through the given translation table.");
365
366
#define BYTES_TRANSLATE_METHODDEF    \
367
    {"translate", _PyCFunction_CAST(bytes_translate), METH_FASTCALL|METH_KEYWORDS, bytes_translate__doc__},
368
369
static PyObject *
370
bytes_translate_impl(PyBytesObject *self, PyObject *table,
371
                     PyObject *deletechars);
372
373
static PyObject *
374
bytes_translate(PyBytesObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
375
{
376
    PyObject *return_value = NULL;
377
    static const char * const _keywords[] = {"", "delete", NULL};
378
    static _PyArg_Parser _parser = {NULL, _keywords, "translate", 0};
379
    PyObject *argsbuf[2];
380
    Py_ssize_t noptargs = nargs + (kwnames ? 
PyTuple_GET_SIZE3
(kwnames) :
0149
) - 1;
  Branch (380:36): [True: 3, False: 149]
381
    PyObject *table;
382
    PyObject *deletechars = NULL;
383
384
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf);
385
    if (!args) {
  Branch (385:9): [True: 1, False: 151]
386
        goto exit;
387
    }
388
    table = args[0];
389
    if (!noptargs) {
  Branch (389:9): [True: 143, False: 8]
390
        goto skip_optional_pos;
391
    }
392
    deletechars = args[1];
393
skip_optional_pos:
394
    return_value = bytes_translate_impl(self, table, deletechars);
395
396
exit:
397
    return return_value;
398
}
399
400
PyDoc_STRVAR(bytes_maketrans__doc__,
401
"maketrans(frm, to, /)\n"
402
"--\n"
403
"\n"
404
"Return a translation table useable for the bytes or bytearray translate method.\n"
405
"\n"
406
"The returned table will be one where each byte in frm is mapped to the byte at\n"
407
"the same position in to.\n"
408
"\n"
409
"The bytes objects frm and to must be of the same length.");
410
411
#define BYTES_MAKETRANS_METHODDEF    \
412
    {"maketrans", _PyCFunction_CAST(bytes_maketrans), METH_FASTCALL|METH_STATIC, bytes_maketrans__doc__},
413
414
static PyObject *
415
bytes_maketrans_impl(Py_buffer *frm, Py_buffer *to);
416
417
static PyObject *
418
bytes_maketrans(void *null, PyObject *const *args, Py_ssize_t nargs)
419
{
420
    PyObject *return_value = NULL;
421
    Py_buffer frm = {NULL, NULL};
422
    Py_buffer to = {NULL, NULL};
423
424
    if (!_PyArg_CheckPositional("maketrans", nargs, 2, 2)) {
425
        goto exit;
426
    }
427
    if (PyObject_GetBuffer(args[0], &frm, PyBUF_SIMPLE) != 0) {
  Branch (427:9): [True: 1, False: 25]
428
        goto exit;
429
    }
430
    if (!PyBuffer_IsContiguous(&frm, 'C')) {
  Branch (430:9): [True: 0, False: 25]
431
        _PyArg_BadArgument("maketrans", "argument 1", "contiguous buffer", args[0]);
432
        goto exit;
433
    }
434
    if (PyObject_GetBuffer(args[1], &to, PyBUF_SIMPLE) != 0) {
  Branch (434:9): [True: 1, False: 24]
435
        goto exit;
436
    }
437
    if (!PyBuffer_IsContiguous(&to, 'C')) {
  Branch (437:9): [True: 0, False: 24]
438
        _PyArg_BadArgument("maketrans", "argument 2", "contiguous buffer", args[1]);
439
        goto exit;
440
    }
441
    return_value = bytes_maketrans_impl(&frm, &to);
442
443
exit:
444
    /* Cleanup for frm */
445
    if (frm.obj) {
  Branch (445:9): [True: 25, False: 1]
446
       PyBuffer_Release(&frm);
447
    }
448
    /* Cleanup for to */
449
    if (to.obj) {
  Branch (449:9): [True: 24, False: 2]
450
       PyBuffer_Release(&to);
451
    }
452
453
    return return_value;
454
}
455
456
PyDoc_STRVAR(bytes_replace__doc__,
457
"replace($self, old, new, count=-1, /)\n"
458
"--\n"
459
"\n"
460
"Return a copy with all occurrences of substring old replaced by new.\n"
461
"\n"
462
"  count\n"
463
"    Maximum number of occurrences to replace.\n"
464
"    -1 (the default value) means replace all occurrences.\n"
465
"\n"
466
"If the optional argument count is given, only the first count occurrences are\n"
467
"replaced.");
468
469
#define BYTES_REPLACE_METHODDEF    \
470
    {"replace", _PyCFunction_CAST(bytes_replace), METH_FASTCALL, bytes_replace__doc__},
471
472
static PyObject *
473
bytes_replace_impl(PyBytesObject *self, Py_buffer *old, Py_buffer *new,
474
                   Py_ssize_t count);
475
476
static PyObject *
477
bytes_replace(PyBytesObject *self, PyObject *const *args, Py_ssize_t nargs)
478
{
479
    PyObject *return_value = NULL;
480
    Py_buffer old = {NULL, NULL};
481
    Py_buffer new = {NULL, NULL};
482
    Py_ssize_t count = -1;
483
484
    if (!_PyArg_CheckPositional("replace", nargs, 2, 3)) {
485
        goto exit;
486
    }
487
    if (PyObject_GetBuffer(args[0], &old, PyBUF_SIMPLE) != 0) {
  Branch (487:9): [True: 5, False: 72.8k]
488
        goto exit;
489
    }
490
    if (!PyBuffer_IsContiguous(&old, 'C')) {
  Branch (490:9): [True: 0, False: 72.8k]
491
        _PyArg_BadArgument("replace", "argument 1", "contiguous buffer", args[0]);
492
        goto exit;
493
    }
494
    if (PyObject_GetBuffer(args[1], &new, PyBUF_SIMPLE) != 0) {
  Branch (494:9): [True: 1, False: 72.8k]
495
        goto exit;
496
    }
497
    if (!PyBuffer_IsContiguous(&new, 'C')) {
  Branch (497:9): [True: 0, False: 72.8k]
498
        _PyArg_BadArgument("replace", "argument 2", "contiguous buffer", args[1]);
499
        goto exit;
500
    }
501
    if (nargs < 3) {
  Branch (501:9): [True: 72.7k, False: 81]
502
        goto skip_optional;
503
    }
504
    {
505
        Py_ssize_t ival = -1;
506
        PyObject *iobj = _PyNumber_Index(args[2]);
507
        if (iobj != NULL) {
  Branch (507:13): [True: 81, False: 0]
508
            ival = PyLong_AsSsize_t(iobj);
509
            Py_DECREF(iobj);
510
        }
511
        if (ival == -1 && 
PyErr_Occurred()8
) {
  Branch (511:13): [True: 8, False: 73]
  Branch (511:27): [True: 0, False: 8]
512
            goto exit;
513
        }
514
        count = ival;
515
    }
516
skip_optional:
517
    return_value = bytes_replace_impl(self, &old, &new, count);
518
519
exit:
520
    /* Cleanup for old */
521
    if (old.obj) {
  Branch (521:9): [True: 72.8k, False: 7]
522
       PyBuffer_Release(&old);
523
    }
524
    /* Cleanup for new */
525
    if (new.obj) {
  Branch (525:9): [True: 72.8k, False: 8]
526
       PyBuffer_Release(&new);
527
    }
528
529
    return return_value;
530
}
531
532
PyDoc_STRVAR(bytes_removeprefix__doc__,
533
"removeprefix($self, prefix, /)\n"
534
"--\n"
535
"\n"
536
"Return a bytes object with the given prefix string removed if present.\n"
537
"\n"
538
"If the bytes starts with the prefix string, return bytes[len(prefix):].\n"
539
"Otherwise, return a copy of the original bytes.");
540
541
#define BYTES_REMOVEPREFIX_METHODDEF    \
542
    {"removeprefix", (PyCFunction)bytes_removeprefix, METH_O, bytes_removeprefix__doc__},
543
544
static PyObject *
545
bytes_removeprefix_impl(PyBytesObject *self, Py_buffer *prefix);
546
547
static PyObject *
548
bytes_removeprefix(PyBytesObject *self, PyObject *arg)
549
{
550
    PyObject *return_value = NULL;
551
    Py_buffer prefix = {NULL, NULL};
552
553
    if (PyObject_GetBuffer(arg, &prefix, PyBUF_SIMPLE) != 0) {
  Branch (553:9): [True: 2, False: 27]
554
        goto exit;
555
    }
556
    if (!PyBuffer_IsContiguous(&prefix, 'C')) {
  Branch (556:9): [True: 0, False: 27]
557
        _PyArg_BadArgument("removeprefix", "argument", "contiguous buffer", arg);
558
        goto exit;
559
    }
560
    return_value = bytes_removeprefix_impl(self, &prefix);
561
562
exit:
563
    /* Cleanup for prefix */
564
    if (prefix.obj) {
  Branch (564:9): [True: 27, False: 2]
565
       PyBuffer_Release(&prefix);
566
    }
567
568
    return return_value;
569
}
570
571
PyDoc_STRVAR(bytes_removesuffix__doc__,
572
"removesuffix($self, suffix, /)\n"
573
"--\n"
574
"\n"
575
"Return a bytes object with the given suffix string removed if present.\n"
576
"\n"
577
"If the bytes ends with the suffix string and that suffix is not empty,\n"
578
"return bytes[:-len(prefix)].  Otherwise, return a copy of the original\n"
579
"bytes.");
580
581
#define BYTES_REMOVESUFFIX_METHODDEF    \
582
    {"removesuffix", (PyCFunction)bytes_removesuffix, METH_O, bytes_removesuffix__doc__},
583
584
static PyObject *
585
bytes_removesuffix_impl(PyBytesObject *self, Py_buffer *suffix);
586
587
static PyObject *
588
bytes_removesuffix(PyBytesObject *self, PyObject *arg)
589
{
590
    PyObject *return_value = NULL;
591
    Py_buffer suffix = {NULL, NULL};
592
593
    if (PyObject_GetBuffer(arg, &suffix, PyBUF_SIMPLE) != 0) {
  Branch (593:9): [True: 2, False: 15]
594
        goto exit;
595
    }
596
    if (!PyBuffer_IsContiguous(&suffix, 'C')) {
  Branch (596:9): [True: 0, False: 15]
597
        _PyArg_BadArgument("removesuffix", "argument", "contiguous buffer", arg);
598
        goto exit;
599
    }
600
    return_value = bytes_removesuffix_impl(self, &suffix);
601
602
exit:
603
    /* Cleanup for suffix */
604
    if (suffix.obj) {
  Branch (604:9): [True: 15, False: 2]
605
       PyBuffer_Release(&suffix);
606
    }
607
608
    return return_value;
609
}
610
611
PyDoc_STRVAR(bytes_decode__doc__,
612
"decode($self, /, encoding=\'utf-8\', errors=\'strict\')\n"
613
"--\n"
614
"\n"
615
"Decode the bytes using the codec registered for encoding.\n"
616
"\n"
617
"  encoding\n"
618
"    The encoding with which to decode the bytes.\n"
619
"  errors\n"
620
"    The error handling scheme to use for the handling of decoding errors.\n"
621
"    The default is \'strict\' meaning that decoding errors raise a\n"
622
"    UnicodeDecodeError. Other possible values are \'ignore\' and \'replace\'\n"
623
"    as well as any other name registered with codecs.register_error that\n"
624
"    can handle UnicodeDecodeErrors.");
625
626
#define BYTES_DECODE_METHODDEF    \
627
    {"decode", _PyCFunction_CAST(bytes_decode), METH_FASTCALL|METH_KEYWORDS, bytes_decode__doc__},
628
629
static PyObject *
630
bytes_decode_impl(PyBytesObject *self, const char *encoding,
631
                  const char *errors);
632
633
static PyObject *
634
bytes_decode(PyBytesObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
635
{
636
    PyObject *return_value = NULL;
637
    static const char * const _keywords[] = {"encoding", "errors", NULL};
638
    static _PyArg_Parser _parser = {NULL, _keywords, "decode", 0};
639
    PyObject *argsbuf[2];
640
    Py_ssize_t noptargs = nargs + (kwnames ? 
PyTuple_GET_SIZE647
(kwnames) :
05.67M
) - 0;
  Branch (640:36): [True: 647, False: 5.67M]
641
    const char *encoding = NULL;
642
    const char *errors = NULL;
643
644
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 2, 0, argsbuf);
645
    if (!args) {
  Branch (645:9): [True: 0, False: 5.67M]
646
        goto exit;
647
    }
648
    if (!noptargs) {
  Branch (648:9): [True: 4.91k, False: 5.66M]
649
        goto skip_optional_pos;
650
    }
651
    if (args[0]) {
  Branch (651:9): [True: 5.66M, False: 0]
652
        if (!PyUnicode_Check(args[0])) {
  Branch (652:13): [True: 0, False: 5.66M]
653
            _PyArg_BadArgument("decode", "argument 'encoding'", "str", args[0]);
654
            goto exit;
655
        }
656
        Py_ssize_t encoding_length;
657
        encoding = PyUnicode_AsUTF8AndSize(args[0], &encoding_length);
658
        if (encoding == NULL) {
  Branch (658:13): [True: 1, False: 5.66M]
659
            goto exit;
660
        }
661
        if (strlen(encoding) != (size_t)encoding_length) {
  Branch (661:13): [True: 0, False: 5.66M]
662
            PyErr_SetString(PyExc_ValueError, "embedded null character");
663
            goto exit;
664
        }
665
        if (!--noptargs) {
  Branch (665:13): [True: 4.94M, False: 719k]
666
            goto skip_optional_pos;
667
        }
668
    }
669
    if (!PyUnicode_Check(args[1])) {
  Branch (669:9): [True: 0, False: 719k]
670
        _PyArg_BadArgument("decode", "argument 'errors'", "str", args[1]);
671
        goto exit;
672
    }
673
    Py_ssize_t errors_length;
674
    errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
675
    if (errors == NULL) {
  Branch (675:9): [True: 0, False: 719k]
676
        goto exit;
677
    }
678
    if (strlen(errors) != (size_t)errors_length) {
  Branch (678:9): [True: 0, False: 719k]
679
        PyErr_SetString(PyExc_ValueError, "embedded null character");
680
        goto exit;
681
    }
682
skip_optional_pos:
683
    return_value = bytes_decode_impl(self, encoding, errors);
684
685
exit:
686
    return return_value;
687
}
688
689
PyDoc_STRVAR(bytes_splitlines__doc__,
690
"splitlines($self, /, keepends=False)\n"
691
"--\n"
692
"\n"
693
"Return a list of the lines in the bytes, breaking at line boundaries.\n"
694
"\n"
695
"Line breaks are not included in the resulting list unless keepends is given and\n"
696
"true.");
697
698
#define BYTES_SPLITLINES_METHODDEF    \
699
    {"splitlines", _PyCFunction_CAST(bytes_splitlines), METH_FASTCALL|METH_KEYWORDS, bytes_splitlines__doc__},
700
701
static PyObject *
702
bytes_splitlines_impl(PyBytesObject *self, int keepends);
703
704
static PyObject *
705
bytes_splitlines(PyBytesObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
706
{
707
    PyObject *return_value = NULL;
708
    static const char * const _keywords[] = {"keepends", NULL};
709
    static _PyArg_Parser _parser = {NULL, _keywords, "splitlines", 0};
710
    PyObject *argsbuf[1];
711
    Py_ssize_t noptargs = nargs + (kwnames ? 
PyTuple_GET_SIZE481
(kwnames) :
0179
) - 0;
  Branch (711:36): [True: 481, False: 179]
712
    int keepends = 0;
713
714
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
715
    if (!args) {
  Branch (715:9): [True: 1, False: 659]
716
        goto exit;
717
    }
718
    if (!noptargs) {
  Branch (718:9): [True: 176, False: 483]
719
        goto skip_optional_pos;
720
    }
721
    keepends = _PyLong_AsInt(args[0]);
722
    if (keepends == -1 && 
PyErr_Occurred()0
) {
  Branch (722:9): [True: 0, False: 483]
  Branch (722:27): [True: 0, False: 0]
723
        goto exit;
724
    }
725
skip_optional_pos:
726
    return_value = bytes_splitlines_impl(self, keepends);
727
728
exit:
729
    return return_value;
730
}
731
732
PyDoc_STRVAR(bytes_fromhex__doc__,
733
"fromhex($type, string, /)\n"
734
"--\n"
735
"\n"
736
"Create a bytes object from a string of hexadecimal numbers.\n"
737
"\n"
738
"Spaces between two numbers are accepted.\n"
739
"Example: bytes.fromhex(\'B9 01EF\') -> b\'\\\\xb9\\\\x01\\\\xef\'.");
740
741
#define BYTES_FROMHEX_METHODDEF    \
742
    {"fromhex", (PyCFunction)bytes_fromhex, METH_O|METH_CLASS, bytes_fromhex__doc__},
743
744
static PyObject *
745
bytes_fromhex_impl(PyTypeObject *type, PyObject *string);
746
747
static PyObject *
748
bytes_fromhex(PyTypeObject *type, PyObject *arg)
749
{
750
    PyObject *return_value = NULL;
751
    PyObject *string;
752
753
    if (!PyUnicode_Check(arg)) {
  Branch (753:9): [True: 2, False: 1.49k]
754
        _PyArg_BadArgument("fromhex", "argument", "str", arg);
755
        goto exit;
756
    }
757
    if (PyUnicode_READY(arg) == -1) {
  Branch (757:9): [True: 0, False: 1.49k]
758
        goto exit;
759
    }
760
    string = arg;
761
    return_value = bytes_fromhex_impl(type, string);
762
763
exit:
764
    return return_value;
765
}
766
767
PyDoc_STRVAR(bytes_hex__doc__,
768
"hex($self, /, sep=<unrepresentable>, bytes_per_sep=1)\n"
769
"--\n"
770
"\n"
771
"Create a string of hexadecimal numbers from a bytes object.\n"
772
"\n"
773
"  sep\n"
774
"    An optional single character or byte to separate hex bytes.\n"
775
"  bytes_per_sep\n"
776
"    How many bytes between separators.  Positive values count from the\n"
777
"    right, negative values count from the left.\n"
778
"\n"
779
"Example:\n"
780
">>> value = b\'\\xb9\\x01\\xef\'\n"
781
">>> value.hex()\n"
782
"\'b901ef\'\n"
783
">>> value.hex(\':\')\n"
784
"\'b9:01:ef\'\n"
785
">>> value.hex(\':\', 2)\n"
786
"\'b9:01ef\'\n"
787
">>> value.hex(\':\', -2)\n"
788
"\'b901:ef\'");
789
790
#define BYTES_HEX_METHODDEF    \
791
    {"hex", _PyCFunction_CAST(bytes_hex), METH_FASTCALL|METH_KEYWORDS, bytes_hex__doc__},
792
793
static PyObject *
794
bytes_hex_impl(PyBytesObject *self, PyObject *sep, int bytes_per_sep);
795
796
static PyObject *
797
bytes_hex(PyBytesObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
798
{
799
    PyObject *return_value = NULL;
800
    static const char * const _keywords[] = {"sep", "bytes_per_sep", NULL};
801
    static _PyArg_Parser _parser = {NULL, _keywords, "hex", 0};
802
    PyObject *argsbuf[2];
803
    Py_ssize_t noptargs = nargs + (kwnames ? 
PyTuple_GET_SIZE0
(kwnames) : 0) - 0;
  Branch (803:36): [True: 0, False: 58]
804
    PyObject *sep = NULL;
805
    int bytes_per_sep = 1;
806
807
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 2, 0, argsbuf);
808
    if (!args) {
  Branch (808:9): [True: 0, False: 58]
809
        goto exit;
810
    }
811
    if (!noptargs) {
  Branch (811:9): [True: 10, False: 48]
812
        goto skip_optional_pos;
813
    }
814
    if (args[0]) {
  Branch (814:9): [True: 48, False: 0]
815
        sep = args[0];
816
        if (!--noptargs) {
  Branch (816:13): [True: 17, False: 31]
817
            goto skip_optional_pos;
818
        }
819
    }
820
    bytes_per_sep = _PyLong_AsInt(args[1]);
821
    if (bytes_per_sep == -1 && 
PyErr_Occurred()1
) {
  Branch (821:9): [True: 1, False: 30]
  Branch (821:32): [True: 0, False: 1]
822
        goto exit;
823
    }
824
skip_optional_pos:
825
    return_value = bytes_hex_impl(self, sep, bytes_per_sep);
826
827
exit:
828
    return return_value;
829
}
830
831
static PyObject *
832
bytes_new_impl(PyTypeObject *type, PyObject *x, const char *encoding,
833
               const char *errors);
834
835
static PyObject *
836
bytes_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
837
{
838
    PyObject *return_value = NULL;
839
    static const char * const _keywords[] = {"source", "encoding", "errors", NULL};
840
    static _PyArg_Parser _parser = {NULL, _keywords, "bytes", 0};
841
    PyObject *argsbuf[3];
842
    PyObject * const *fastargs;
843
    Py_ssize_t nargs = PyTuple_GET_SIZE(args);
844
    Py_ssize_t noptargs = nargs + (kwargs ? 
PyDict_GET_SIZE79
(kwargs) :
0478k
) - 0;
  Branch (844:36): [True: 79, False: 478k]
845
    PyObject *x = NULL;
846
    const char *encoding = NULL;
847
    const char *errors = NULL;
848
849
    fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 0, 3, 0, argsbuf);
850
    if (!fastargs) {
  Branch (850:9): [True: 0, False: 478k]
851
        goto exit;
852
    }
853
    if (!noptargs) {
  Branch (853:9): [True: 119, False: 478k]
854
        goto skip_optional_pos;
855
    }
856
    if (fastargs[0]) {
  Branch (856:9): [True: 478k, False: 2]
857
        x = fastargs[0];
858
        if (!--noptargs) {
  Branch (858:13): [True: 442k, False: 36.6k]
859
            goto skip_optional_pos;
860
        }
861
    }
862
    if (fastargs[1]) {
  Branch (862:9): [True: 36.6k, False: 4]
863
        if (!PyUnicode_Check(fastargs[1])) {
  Branch (863:13): [True: 1, False: 36.6k]
864
            _PyArg_BadArgument("bytes", "argument 'encoding'", "str", fastargs[1]);
865
            goto exit;
866
        }
867
        Py_ssize_t encoding_length;
868
        encoding = PyUnicode_AsUTF8AndSize(fastargs[1], &encoding_length);
869
        if (encoding == NULL) {
  Branch (869:13): [True: 0, False: 36.6k]
870
            goto exit;
871
        }
872
        if (strlen(encoding) != (size_t)encoding_length) {
  Branch (872:13): [True: 0, False: 36.6k]
873
            PyErr_SetString(PyExc_ValueError, "embedded null character");
874
            goto exit;
875
        }
876
        if (!--noptargs) {
  Branch (876:13): [True: 36.6k, False: 2]
877
            goto skip_optional_pos;
878
        }
879
    }
880
    if (!PyUnicode_Check(fastargs[2])) {
  Branch (880:9): [True: 1, False: 5]
881
        _PyArg_BadArgument("bytes", "argument 'errors'", "str", fastargs[2]);
882
        goto exit;
883
    }
884
    Py_ssize_t errors_length;
885
    errors = PyUnicode_AsUTF8AndSize(fastargs[2], &errors_length);
886
    if (errors == NULL) {
  Branch (886:9): [True: 0, False: 5]
887
        goto exit;
888
    }
889
    if (strlen(errors) != (size_t)errors_length) {
  Branch (889:9): [True: 0, False: 5]
890
        PyErr_SetString(PyExc_ValueError, "embedded null character");
891
        goto exit;
892
    }
893
skip_optional_pos:
894
    return_value = bytes_new_impl(type, x, encoding, errors);
895
896
exit:
897
    return return_value;
898
}
899
/*[clinic end generated code: output=5727702e63a0a8b7 input=a9049054013a1b77]*/