Debian Codegraph @

Objects/clinic/bytesobject.c.h

raw
1 /*[clinic input]
2 preserve
3 [clinic start generated code]*/
4
5 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
6 # include "pycore_gc.h" // PyGC_Head
7 # include "pycore_runtime.h" // _Py_ID()
8 #endif
9 #include "pycore_abstract.h" // _PyNumber_Index()
10 #include "pycore_modsupport.h" // _PyArg_UnpackKeywords()
11
12 PyDoc_STRVAR(bytes___bytes____doc__,
13 "__bytes__($self, /)\n"
14 "--\n"
15 "\n"
16 "Convert this value to exact type bytes.");
17
18 #define BYTES___BYTES___METHODDEF \
19 {"__bytes__", (PyCFunction)bytes___bytes__, METH_NOARGS, bytes___bytes____doc__},
20
21 static PyObject *
22 bytes___bytes___impl(PyBytesObject *self);
23
24 static PyObject *
25 bytes___bytes__(PyBytesObject *self, PyObject *Py_UNUSED(ignored))
26 {
27 return bytes___bytes___impl(self);
28 }
29
30 PyDoc_STRVAR(bytes_split__doc__,
31 "split($self, /, sep=None, maxsplit=-1)\n"
32 "--\n"
33 "\n"
34 "Return a list of the sections in the bytes, using sep as the delimiter.\n"
35 "\n"
36 " sep\n"
37 " The delimiter according which to split the bytes.\n"
38 " None (the default value) means split on ASCII whitespace characters\n"
39 " (space, tab, return, newline, formfeed, vertical tab).\n"
40 " maxsplit\n"
41 " Maximum number of splits to do.\n"
42 " -1 (the default value) means no limit.");
43
44 #define BYTES_SPLIT_METHODDEF \
45 {"split", _PyCFunction_CAST(bytes_split), METH_FASTCALL|METH_KEYWORDS, bytes_split__doc__},
46
47 static PyObject *
48 bytes_split_impl(PyBytesObject *self, PyObject *sep, Py_ssize_t maxsplit);
49
50 static PyObject *
51 bytes_split(PyBytesObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
52 {
53 PyObject *return_value = NULL;
54 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
55
56 #define NUM_KEYWORDS 2
57 static struct {
58 PyGC_Head _this_is_not_used;
59 PyObject_VAR_HEAD
60 PyObject *ob_item[NUM_KEYWORDS];
61 } _kwtuple = {
62 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
63 .ob_item = { &_Py_ID(sep), &_Py_ID(maxsplit), },
64 };
65 #undef NUM_KEYWORDS
66 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
67
68 #else // !Py_BUILD_CORE
69 # define KWTUPLE NULL
70 #endif // !Py_BUILD_CORE
71
72 static const char * const _keywords[] = {"sep", "maxsplit", NULL};
73 static _PyArg_Parser _parser = {
74 .keywords = _keywords,
75 .fname = "split",
76 .kwtuple = KWTUPLE,
77 };
78 #undef KWTUPLE
79 PyObject *argsbuf[2];
80 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
81 PyObject *sep = Py_None;
82 Py_ssize_t maxsplit = -1;
83
84 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 2, 0, argsbuf);
85 if (!args) {
86 goto exit;
87 }
88 if (!noptargs) {
89 goto skip_optional_pos;
90 }
91 if (args[0]) {
92 sep = args[0];
93 if (!--noptargs) {
94 goto skip_optional_pos;
95 }
96 }
97 {
98 Py_ssize_t ival = -1;
99 PyObject *iobj = _PyNumber_Index(args[1]);
100 if (iobj != NULL) {
101 ival = PyLong_AsSsize_t(iobj);
102 Py_DECREF(iobj);
103 }
104 if (ival == -1 && PyErr_Occurred()) {
105 goto exit;
106 }
107 maxsplit = ival;
108 }
109 skip_optional_pos:
110 return_value = bytes_split_impl(self, sep, maxsplit);
111
112 exit:
113 return return_value;
114 }
115
116 PyDoc_STRVAR(bytes_partition__doc__,
117 "partition($self, sep, /)\n"
118 "--\n"
119 "\n"
120 "Partition the bytes into three parts using the given separator.\n"
121 "\n"
122 "This will search for the separator sep in the bytes. If the separator is found,\n"
123 "returns a 3-tuple containing the part before the separator, the separator\n"
124 "itself, and the part after it.\n"
125 "\n"
126 "If the separator is not found, returns a 3-tuple containing the original bytes\n"
127 "object and two empty bytes objects.");
128
129 #define BYTES_PARTITION_METHODDEF \
130 {"partition", (PyCFunction)bytes_partition, METH_O, bytes_partition__doc__},
131
132 static PyObject *
133 bytes_partition_impl(PyBytesObject *self, Py_buffer *sep);
134
135 static PyObject *
136 bytes_partition(PyBytesObject *self, PyObject *arg)
137 {
138 PyObject *return_value = NULL;
139 Py_buffer sep = {NULL, NULL};
140
141 if (PyObject_GetBuffer(arg, &sep, PyBUF_SIMPLE) != 0) {
142 goto exit;
143 }
144 return_value = bytes_partition_impl(self, &sep);
145
146 exit:
147 /* Cleanup for sep */
148 if (sep.obj) {
149 PyBuffer_Release(&sep);
150 }
151
152 return return_value;
153 }
154
155 PyDoc_STRVAR(bytes_rpartition__doc__,
156 "rpartition($self, sep, /)\n"
157 "--\n"
158 "\n"
159 "Partition the bytes into three parts using the given separator.\n"
160 "\n"
161 "This will search for the separator sep in the bytes, starting at the end. If\n"
162 "the separator is found, returns a 3-tuple containing the part before the\n"
163 "separator, the separator itself, and the part after it.\n"
164 "\n"
165 "If the separator is not found, returns a 3-tuple containing two empty bytes\n"
166 "objects and the original bytes object.");
167
168 #define BYTES_RPARTITION_METHODDEF \
169 {"rpartition", (PyCFunction)bytes_rpartition, METH_O, bytes_rpartition__doc__},
170
171 static PyObject *
172 bytes_rpartition_impl(PyBytesObject *self, Py_buffer *sep);
173
174 static PyObject *
175 bytes_rpartition(PyBytesObject *self, PyObject *arg)
176 {
177 PyObject *return_value = NULL;
178 Py_buffer sep = {NULL, NULL};
179
180 if (PyObject_GetBuffer(arg, &sep, PyBUF_SIMPLE) != 0) {
181 goto exit;
182 }
183 return_value = bytes_rpartition_impl(self, &sep);
184
185 exit:
186 /* Cleanup for sep */
187 if (sep.obj) {
188 PyBuffer_Release(&sep);
189 }
190
191 return return_value;
192 }
193
194 PyDoc_STRVAR(bytes_rsplit__doc__,
195 "rsplit($self, /, sep=None, maxsplit=-1)\n"
196 "--\n"
197 "\n"
198 "Return a list of the sections in the bytes, using sep as the delimiter.\n"
199 "\n"
200 " sep\n"
201 " The delimiter according which to split the bytes.\n"
202 " None (the default value) means split on ASCII whitespace characters\n"
203 " (space, tab, return, newline, formfeed, vertical tab).\n"
204 " maxsplit\n"
205 " Maximum number of splits to do.\n"
206 " -1 (the default value) means no limit.\n"
207 "\n"
208 "Splitting is done starting at the end of the bytes and working to the front.");
209
210 #define BYTES_RSPLIT_METHODDEF \
211 {"rsplit", _PyCFunction_CAST(bytes_rsplit), METH_FASTCALL|METH_KEYWORDS, bytes_rsplit__doc__},
212
213 static PyObject *
214 bytes_rsplit_impl(PyBytesObject *self, PyObject *sep, Py_ssize_t maxsplit);
215
216 static PyObject *
217 bytes_rsplit(PyBytesObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
218 {
219 PyObject *return_value = NULL;
220 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
221
222 #define NUM_KEYWORDS 2
223 static struct {
224 PyGC_Head _this_is_not_used;
225 PyObject_VAR_HEAD
226 PyObject *ob_item[NUM_KEYWORDS];
227 } _kwtuple = {
228 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
229 .ob_item = { &_Py_ID(sep), &_Py_ID(maxsplit), },
230 };
231 #undef NUM_KEYWORDS
232 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
233
234 #else // !Py_BUILD_CORE
235 # define KWTUPLE NULL
236 #endif // !Py_BUILD_CORE
237
238 static const char * const _keywords[] = {"sep", "maxsplit", NULL};
239 static _PyArg_Parser _parser = {
240 .keywords = _keywords,
241 .fname = "rsplit",
242 .kwtuple = KWTUPLE,
243 };
244 #undef KWTUPLE
245 PyObject *argsbuf[2];
246 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
247 PyObject *sep = Py_None;
248 Py_ssize_t maxsplit = -1;
249
250 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 2, 0, argsbuf);
251 if (!args) {
252 goto exit;
253 }
254 if (!noptargs) {
255 goto skip_optional_pos;
256 }
257 if (args[0]) {
258 sep = args[0];
259 if (!--noptargs) {
260 goto skip_optional_pos;
261 }
262 }
263 {
264 Py_ssize_t ival = -1;
265 PyObject *iobj = _PyNumber_Index(args[1]);
266 if (iobj != NULL) {
267 ival = PyLong_AsSsize_t(iobj);
268 Py_DECREF(iobj);
269 }
270 if (ival == -1 && PyErr_Occurred()) {
271 goto exit;
272 }
273 maxsplit = ival;
274 }
275 skip_optional_pos:
276 return_value = bytes_rsplit_impl(self, sep, maxsplit);
277
278 exit:
279 return return_value;
280 }
281
282 PyDoc_STRVAR(bytes_join__doc__,
283 "join($self, iterable_of_bytes, /)\n"
284 "--\n"
285 "\n"
286 "Concatenate any number of bytes objects.\n"
287 "\n"
288 "The bytes whose method is called is inserted in between each pair.\n"
289 "\n"
290 "The result is returned as a new bytes object.\n"
291 "\n"
292 "Example: b\'.\'.join([b\'ab\', b\'pq\', b\'rs\']) -> b\'ab.pq.rs\'.");
293
294 #define BYTES_JOIN_METHODDEF \
295 {"join", (PyCFunction)bytes_join, METH_O, bytes_join__doc__},
296
297 PyDoc_STRVAR(bytes_find__doc__,
298 "find($self, sub[, start[, end]], /)\n"
299 "--\n"
300 "\n"
301 "Return the lowest index in B where subsection \'sub\' is found, such that \'sub\' is contained within B[start,end].\n"
302 "\n"
303 " start\n"
304 " Optional start position. Default: start of the bytes.\n"
305 " end\n"
306 " Optional stop position. Default: end of the bytes.\n"
307 "\n"
308 "Return -1 on failure.");
309
310 #define BYTES_FIND_METHODDEF \
311 {"find", _PyCFunction_CAST(bytes_find), METH_FASTCALL, bytes_find__doc__},
312
313 static PyObject *
314 bytes_find_impl(PyBytesObject *self, PyObject *sub, Py_ssize_t start,
315 Py_ssize_t end);
316
317 static PyObject *
318 bytes_find(PyBytesObject *self, PyObject *const *args, Py_ssize_t nargs)
319 {
320 PyObject *return_value = NULL;
321 PyObject *sub;
322 Py_ssize_t start = 0;
323 Py_ssize_t end = PY_SSIZE_T_MAX;
324
325 if (!_PyArg_CheckPositional("find", nargs, 1, 3)) {
326 goto exit;
327 }
328 sub = args[0];
329 if (nargs < 2) {
330 goto skip_optional;
331 }
332 if (!_PyEval_SliceIndex(args[1], &start)) {
333 goto exit;
334 }
335 if (nargs < 3) {
336 goto skip_optional;
337 }
338 if (!_PyEval_SliceIndex(args[2], &end)) {
339 goto exit;
340 }
341 skip_optional:
342 return_value = bytes_find_impl(self, sub, start, end);
343
344 exit:
345 return return_value;
346 }
347
348 PyDoc_STRVAR(bytes_index__doc__,
349 "index($self, sub[, start[, end]], /)\n"
350 "--\n"
351 "\n"
352 "Return the lowest index in B where subsection \'sub\' is found, such that \'sub\' is contained within B[start,end].\n"
353 "\n"
354 " start\n"
355 " Optional start position. Default: start of the bytes.\n"
356 " end\n"
357 " Optional stop position. Default: end of the bytes.\n"
358 "\n"
359 "Raise ValueError if the subsection is not found.");
360
361 #define BYTES_INDEX_METHODDEF \
362 {"index", _PyCFunction_CAST(bytes_index), METH_FASTCALL, bytes_index__doc__},
363
364 static PyObject *
365 bytes_index_impl(PyBytesObject *self, PyObject *sub, Py_ssize_t start,
366 Py_ssize_t end);
367
368 static PyObject *
369 bytes_index(PyBytesObject *self, PyObject *const *args, Py_ssize_t nargs)
370 {
371 PyObject *return_value = NULL;
372 PyObject *sub;
373 Py_ssize_t start = 0;
374 Py_ssize_t end = PY_SSIZE_T_MAX;
375
376 if (!_PyArg_CheckPositional("index", nargs, 1, 3)) {
377 goto exit;
378 }
379 sub = args[0];
380 if (nargs < 2) {
381 goto skip_optional;
382 }
383 if (!_PyEval_SliceIndex(args[1], &start)) {
384 goto exit;
385 }
386 if (nargs < 3) {
387 goto skip_optional;
388 }
389 if (!_PyEval_SliceIndex(args[2], &end)) {
390 goto exit;
391 }
392 skip_optional:
393 return_value = bytes_index_impl(self, sub, start, end);
394
395 exit:
396 return return_value;
397 }
398
399 PyDoc_STRVAR(bytes_rfind__doc__,
400 "rfind($self, sub[, start[, end]], /)\n"
401 "--\n"
402 "\n"
403 "Return the highest index in B where subsection \'sub\' is found, such that \'sub\' is contained within B[start,end].\n"
404 "\n"
405 " start\n"
406 " Optional start position. Default: start of the bytes.\n"
407 " end\n"
408 " Optional stop position. Default: end of the bytes.\n"
409 "\n"
410 "Return -1 on failure.");
411
412 #define BYTES_RFIND_METHODDEF \
413 {"rfind", _PyCFunction_CAST(bytes_rfind), METH_FASTCALL, bytes_rfind__doc__},
414
415 static PyObject *
416 bytes_rfind_impl(PyBytesObject *self, PyObject *sub, Py_ssize_t start,
417 Py_ssize_t end);
418
419 static PyObject *
420 bytes_rfind(PyBytesObject *self, PyObject *const *args, Py_ssize_t nargs)
421 {
422 PyObject *return_value = NULL;
423 PyObject *sub;
424 Py_ssize_t start = 0;
425 Py_ssize_t end = PY_SSIZE_T_MAX;
426
427 if (!_PyArg_CheckPositional("rfind", nargs, 1, 3)) {
428 goto exit;
429 }
430 sub = args[0];
431 if (nargs < 2) {
432 goto skip_optional;
433 }
434 if (!_PyEval_SliceIndex(args[1], &start)) {
435 goto exit;
436 }
437 if (nargs < 3) {
438 goto skip_optional;
439 }
440 if (!_PyEval_SliceIndex(args[2], &end)) {
441 goto exit;
442 }
443 skip_optional:
444 return_value = bytes_rfind_impl(self, sub, start, end);
445
446 exit:
447 return return_value;
448 }
449
450 PyDoc_STRVAR(bytes_rindex__doc__,
451 "rindex($self, sub[, start[, end]], /)\n"
452 "--\n"
453 "\n"
454 "Return the highest index in B where subsection \'sub\' is found, such that \'sub\' is contained within B[start,end].\n"
455 "\n"
456 " start\n"
457 " Optional start position. Default: start of the bytes.\n"
458 " end\n"
459 " Optional stop position. Default: end of the bytes.\n"
460 "\n"
461 "Raise ValueError if the subsection is not found.");
462
463 #define BYTES_RINDEX_METHODDEF \
464 {"rindex", _PyCFunction_CAST(bytes_rindex), METH_FASTCALL, bytes_rindex__doc__},
465
466 static PyObject *
467 bytes_rindex_impl(PyBytesObject *self, PyObject *sub, Py_ssize_t start,
468 Py_ssize_t end);
469
470 static PyObject *
471 bytes_rindex(PyBytesObject *self, PyObject *const *args, Py_ssize_t nargs)
472 {
473 PyObject *return_value = NULL;
474 PyObject *sub;
475 Py_ssize_t start = 0;
476 Py_ssize_t end = PY_SSIZE_T_MAX;
477
478 if (!_PyArg_CheckPositional("rindex", nargs, 1, 3)) {
479 goto exit;
480 }
481 sub = args[0];
482 if (nargs < 2) {
483 goto skip_optional;
484 }
485 if (!_PyEval_SliceIndex(args[1], &start)) {
486 goto exit;
487 }
488 if (nargs < 3) {
489 goto skip_optional;
490 }
491 if (!_PyEval_SliceIndex(args[2], &end)) {
492 goto exit;
493 }
494 skip_optional:
495 return_value = bytes_rindex_impl(self, sub, start, end);
496
497 exit:
498 return return_value;
499 }
500
501 PyDoc_STRVAR(bytes_strip__doc__,
502 "strip($self, bytes=None, /)\n"
503 "--\n"
504 "\n"
505 "Strip leading and trailing bytes contained in the argument.\n"
506 "\n"
507 "If the argument is omitted or None, strip leading and trailing ASCII whitespace.");
508
509 #define BYTES_STRIP_METHODDEF \
510 {"strip", _PyCFunction_CAST(bytes_strip), METH_FASTCALL, bytes_strip__doc__},
511
512 static PyObject *
513 bytes_strip_impl(PyBytesObject *self, PyObject *bytes);
514
515 static PyObject *
516 bytes_strip(PyBytesObject *self, PyObject *const *args, Py_ssize_t nargs)
517 {
518 PyObject *return_value = NULL;
519 PyObject *bytes = Py_None;
520
521 if (!_PyArg_CheckPositional("strip", nargs, 0, 1)) {
522 goto exit;
523 }
524 if (nargs < 1) {
525 goto skip_optional;
526 }
527 bytes = args[0];
528 skip_optional:
529 return_value = bytes_strip_impl(self, bytes);
530
531 exit:
532 return return_value;
533 }
534
535 PyDoc_STRVAR(bytes_lstrip__doc__,
536 "lstrip($self, bytes=None, /)\n"
537 "--\n"
538 "\n"
539 "Strip leading bytes contained in the argument.\n"
540 "\n"
541 "If the argument is omitted or None, strip leading ASCII whitespace.");
542
543 #define BYTES_LSTRIP_METHODDEF \
544 {"lstrip", _PyCFunction_CAST(bytes_lstrip), METH_FASTCALL, bytes_lstrip__doc__},
545
546 static PyObject *
547 bytes_lstrip_impl(PyBytesObject *self, PyObject *bytes);
548
549 static PyObject *
550 bytes_lstrip(PyBytesObject *self, PyObject *const *args, Py_ssize_t nargs)
551 {
552 PyObject *return_value = NULL;
553 PyObject *bytes = Py_None;
554
555 if (!_PyArg_CheckPositional("lstrip", nargs, 0, 1)) {
556 goto exit;
557 }
558 if (nargs < 1) {
559 goto skip_optional;
560 }
561 bytes = args[0];
562 skip_optional:
563 return_value = bytes_lstrip_impl(self, bytes);
564
565 exit:
566 return return_value;
567 }
568
569 PyDoc_STRVAR(bytes_rstrip__doc__,
570 "rstrip($self, bytes=None, /)\n"
571 "--\n"
572 "\n"
573 "Strip trailing bytes contained in the argument.\n"
574 "\n"
575 "If the argument is omitted or None, strip trailing ASCII whitespace.");
576
577 #define BYTES_RSTRIP_METHODDEF \
578 {"rstrip", _PyCFunction_CAST(bytes_rstrip), METH_FASTCALL, bytes_rstrip__doc__},
579
580 static PyObject *
581 bytes_rstrip_impl(PyBytesObject *self, PyObject *bytes);
582
583 static PyObject *
584 bytes_rstrip(PyBytesObject *self, PyObject *const *args, Py_ssize_t nargs)
585 {
586 PyObject *return_value = NULL;
587 PyObject *bytes = Py_None;
588
589 if (!_PyArg_CheckPositional("rstrip", nargs, 0, 1)) {
590 goto exit;
591 }
592 if (nargs < 1) {
593 goto skip_optional;
594 }
595 bytes = args[0];
596 skip_optional:
597 return_value = bytes_rstrip_impl(self, bytes);
598
599 exit:
600 return return_value;
601 }
602
603 PyDoc_STRVAR(bytes_count__doc__,
604 "count($self, sub[, start[, end]], /)\n"
605 "--\n"
606 "\n"
607 "Return the number of non-overlapping occurrences of subsection \'sub\' in bytes B[start:end].\n"
608 "\n"
609 " start\n"
610 " Optional start position. Default: start of the bytes.\n"
611 " end\n"
612 " Optional stop position. Default: end of the bytes.");
613
614 #define BYTES_COUNT_METHODDEF \
615 {"count", _PyCFunction_CAST(bytes_count), METH_FASTCALL, bytes_count__doc__},
616
617 static PyObject *
618 bytes_count_impl(PyBytesObject *self, PyObject *sub, Py_ssize_t start,
619 Py_ssize_t end);
620
621 static PyObject *
622 bytes_count(PyBytesObject *self, PyObject *const *args, Py_ssize_t nargs)
623 {
624 PyObject *return_value = NULL;
625 PyObject *sub;
626 Py_ssize_t start = 0;
627 Py_ssize_t end = PY_SSIZE_T_MAX;
628
629 if (!_PyArg_CheckPositional("count", nargs, 1, 3)) {
630 goto exit;
631 }
632 sub = args[0];
633 if (nargs < 2) {
634 goto skip_optional;
635 }
636 if (!_PyEval_SliceIndex(args[1], &start)) {
637 goto exit;
638 }
639 if (nargs < 3) {
640 goto skip_optional;
641 }
642 if (!_PyEval_SliceIndex(args[2], &end)) {
643 goto exit;
644 }
645 skip_optional:
646 return_value = bytes_count_impl(self, sub, start, end);
647
648 exit:
649 return return_value;
650 }
651
652 PyDoc_STRVAR(bytes_translate__doc__,
653 "translate($self, table, /, delete=b\'\')\n"
654 "--\n"
655 "\n"
656 "Return a copy with each character mapped by the given translation table.\n"
657 "\n"
658 " table\n"
659 " Translation table, which must be a bytes object of length 256.\n"
660 "\n"
661 "All characters occurring in the optional argument delete are removed.\n"
662 "The remaining characters are mapped through the given translation table.");
663
664 #define BYTES_TRANSLATE_METHODDEF \
665 {"translate", _PyCFunction_CAST(bytes_translate), METH_FASTCALL|METH_KEYWORDS, bytes_translate__doc__},
666
667 static PyObject *
668 bytes_translate_impl(PyBytesObject *self, PyObject *table,
669 PyObject *deletechars);
670
671 static PyObject *
672 bytes_translate(PyBytesObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
673 {
674 PyObject *return_value = NULL;
675 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
676
677 #define NUM_KEYWORDS 1
678 static struct {
679 PyGC_Head _this_is_not_used;
680 PyObject_VAR_HEAD
681 PyObject *ob_item[NUM_KEYWORDS];
682 } _kwtuple = {
683 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
684 .ob_item = { &_Py_ID(delete), },
685 };
686 #undef NUM_KEYWORDS
687 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
688
689 #else // !Py_BUILD_CORE
690 # define KWTUPLE NULL
691 #endif // !Py_BUILD_CORE
692
693 static const char * const _keywords[] = {"", "delete", NULL};
694 static _PyArg_Parser _parser = {
695 .keywords = _keywords,
696 .fname = "translate",
697 .kwtuple = KWTUPLE,
698 };
699 #undef KWTUPLE
700 PyObject *argsbuf[2];
701 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
702 PyObject *table;
703 PyObject *deletechars = NULL;
704
705 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf);
706 if (!args) {
707 goto exit;
708 }
709 table = args[0];
710 if (!noptargs) {
711 goto skip_optional_pos;
712 }
713 deletechars = args[1];
714 skip_optional_pos:
715 return_value = bytes_translate_impl(self, table, deletechars);
716
717 exit:
718 return return_value;
719 }
720
721 PyDoc_STRVAR(bytes_maketrans__doc__,
722 "maketrans(frm, to, /)\n"
723 "--\n"
724 "\n"
725 "Return a translation table usable for the bytes or bytearray translate method.\n"
726 "\n"
727 "The returned table will be one where each byte in frm is mapped to the byte at\n"
728 "the same position in to.\n"
729 "\n"
730 "The bytes objects frm and to must be of the same length.");
731
732 #define BYTES_MAKETRANS_METHODDEF \
733 {"maketrans", _PyCFunction_CAST(bytes_maketrans), METH_FASTCALL|METH_STATIC, bytes_maketrans__doc__},
734
735 static PyObject *
736 bytes_maketrans_impl(Py_buffer *frm, Py_buffer *to);
737
738 static PyObject *
739 bytes_maketrans(void *null, PyObject *const *args, Py_ssize_t nargs)
740 {
741 PyObject *return_value = NULL;
742 Py_buffer frm = {NULL, NULL};
743 Py_buffer to = {NULL, NULL};
744
745 if (!_PyArg_CheckPositional("maketrans", nargs, 2, 2)) {
746 goto exit;
747 }
748 if (PyObject_GetBuffer(args[0], &frm, PyBUF_SIMPLE) != 0) {
749 goto exit;
750 }
751 if (PyObject_GetBuffer(args[1], &to, PyBUF_SIMPLE) != 0) {
752 goto exit;
753 }
754 return_value = bytes_maketrans_impl(&frm, &to);
755
756 exit:
757 /* Cleanup for frm */
758 if (frm.obj) {
759 PyBuffer_Release(&frm);
760 }
761 /* Cleanup for to */
762 if (to.obj) {
763 PyBuffer_Release(&to);
764 }
765
766 return return_value;
767 }
768
769 PyDoc_STRVAR(bytes_replace__doc__,
770 "replace($self, old, new, count=-1, /)\n"
771 "--\n"
772 "\n"
773 "Return a copy with all occurrences of substring old replaced by new.\n"
774 "\n"
775 " count\n"
776 " Maximum number of occurrences to replace.\n"
777 " -1 (the default value) means replace all occurrences.\n"
778 "\n"
779 "If the optional argument count is given, only the first count occurrences are\n"
780 "replaced.");
781
782 #define BYTES_REPLACE_METHODDEF \
783 {"replace", _PyCFunction_CAST(bytes_replace), METH_FASTCALL, bytes_replace__doc__},
784
785 static PyObject *
786 bytes_replace_impl(PyBytesObject *self, Py_buffer *old, Py_buffer *new,
787 Py_ssize_t count);
788
789 static PyObject *
790 bytes_replace(PyBytesObject *self, PyObject *const *args, Py_ssize_t nargs)
791 {
792 PyObject *return_value = NULL;
793 Py_buffer old = {NULL, NULL};
794 Py_buffer new = {NULL, NULL};
795 Py_ssize_t count = -1;
796
797 if (!_PyArg_CheckPositional("replace", nargs, 2, 3)) {
798 goto exit;
799 }
800 if (PyObject_GetBuffer(args[0], &old, PyBUF_SIMPLE) != 0) {
801 goto exit;
802 }
803 if (PyObject_GetBuffer(args[1], &new, PyBUF_SIMPLE) != 0) {
804 goto exit;
805 }
806 if (nargs < 3) {
807 goto skip_optional;
808 }
809 {
810 Py_ssize_t ival = -1;
811 PyObject *iobj = _PyNumber_Index(args[2]);
812 if (iobj != NULL) {
813 ival = PyLong_AsSsize_t(iobj);
814 Py_DECREF(iobj);
815 }
816 if (ival == -1 && PyErr_Occurred()) {
817 goto exit;
818 }
819 count = ival;
820 }
821 skip_optional:
822 return_value = bytes_replace_impl(self, &old, &new, count);
823
824 exit:
825 /* Cleanup for old */
826 if (old.obj) {
827 PyBuffer_Release(&old);
828 }
829 /* Cleanup for new */
830 if (new.obj) {
831 PyBuffer_Release(&new);
832 }
833
834 return return_value;
835 }
836
837 PyDoc_STRVAR(bytes_removeprefix__doc__,
838 "removeprefix($self, prefix, /)\n"
839 "--\n"
840 "\n"
841 "Return a bytes object with the given prefix string removed if present.\n"
842 "\n"
843 "If the bytes starts with the prefix string, return bytes[len(prefix):].\n"
844 "Otherwise, return a copy of the original bytes.");
845
846 #define BYTES_REMOVEPREFIX_METHODDEF \
847 {"removeprefix", (PyCFunction)bytes_removeprefix, METH_O, bytes_removeprefix__doc__},
848
849 static PyObject *
850 bytes_removeprefix_impl(PyBytesObject *self, Py_buffer *prefix);
851
852 static PyObject *
853 bytes_removeprefix(PyBytesObject *self, PyObject *arg)
854 {
855 PyObject *return_value = NULL;
856 Py_buffer prefix = {NULL, NULL};
857
858 if (PyObject_GetBuffer(arg, &prefix, PyBUF_SIMPLE) != 0) {
859 goto exit;
860 }
861 return_value = bytes_removeprefix_impl(self, &prefix);
862
863 exit:
864 /* Cleanup for prefix */
865 if (prefix.obj) {
866 PyBuffer_Release(&prefix);
867 }
868
869 return return_value;
870 }
871
872 PyDoc_STRVAR(bytes_removesuffix__doc__,
873 "removesuffix($self, suffix, /)\n"
874 "--\n"
875 "\n"
876 "Return a bytes object with the given suffix string removed if present.\n"
877 "\n"
878 "If the bytes ends with the suffix string and that suffix is not empty,\n"
879 "return bytes[:-len(prefix)]. Otherwise, return a copy of the original\n"
880 "bytes.");
881
882 #define BYTES_REMOVESUFFIX_METHODDEF \
883 {"removesuffix", (PyCFunction)bytes_removesuffix, METH_O, bytes_removesuffix__doc__},
884
885 static PyObject *
886 bytes_removesuffix_impl(PyBytesObject *self, Py_buffer *suffix);
887
888 static PyObject *
889 bytes_removesuffix(PyBytesObject *self, PyObject *arg)
890 {
891 PyObject *return_value = NULL;
892 Py_buffer suffix = {NULL, NULL};
893
894 if (PyObject_GetBuffer(arg, &suffix, PyBUF_SIMPLE) != 0) {
895 goto exit;
896 }
897 return_value = bytes_removesuffix_impl(self, &suffix);
898
899 exit:
900 /* Cleanup for suffix */
901 if (suffix.obj) {
902 PyBuffer_Release(&suffix);
903 }
904
905 return return_value;
906 }
907
908 PyDoc_STRVAR(bytes_startswith__doc__,
909 "startswith($self, prefix[, start[, end]], /)\n"
910 "--\n"
911 "\n"
912 "Return True if the bytes starts with the specified prefix, False otherwise.\n"
913 "\n"
914 " prefix\n"
915 " A bytes or a tuple of bytes to try.\n"
916 " start\n"
917 " Optional start position. Default: start of the bytes.\n"
918 " end\n"
919 " Optional stop position. Default: end of the bytes.");
920
921 #define BYTES_STARTSWITH_METHODDEF \
922 {"startswith", _PyCFunction_CAST(bytes_startswith), METH_FASTCALL, bytes_startswith__doc__},
923
924 static PyObject *
925 bytes_startswith_impl(PyBytesObject *self, PyObject *subobj,
926 Py_ssize_t start, Py_ssize_t end);
927
928 static PyObject *
929 bytes_startswith(PyBytesObject *self, PyObject *const *args, Py_ssize_t nargs)
930 {
931 PyObject *return_value = NULL;
932 PyObject *subobj;
933 Py_ssize_t start = 0;
934 Py_ssize_t end = PY_SSIZE_T_MAX;
935
936 if (!_PyArg_CheckPositional("startswith", nargs, 1, 3)) {
937 goto exit;
938 }
939 subobj = args[0];
940 if (nargs < 2) {
941 goto skip_optional;
942 }
943 if (!_PyEval_SliceIndex(args[1], &start)) {
944 goto exit;
945 }
946 if (nargs < 3) {
947 goto skip_optional;
948 }
949 if (!_PyEval_SliceIndex(args[2], &end)) {
950 goto exit;
951 }
952 skip_optional:
953 return_value = bytes_startswith_impl(self, subobj, start, end);
954
955 exit:
956 return return_value;
957 }
958
959 PyDoc_STRVAR(bytes_endswith__doc__,
960 "endswith($self, suffix[, start[, end]], /)\n"
961 "--\n"
962 "\n"
963 "Return True if the bytes ends with the specified suffix, False otherwise.\n"
964 "\n"
965 " suffix\n"
966 " A bytes or a tuple of bytes to try.\n"
967 " start\n"
968 " Optional start position. Default: start of the bytes.\n"
969 " end\n"
970 " Optional stop position. Default: end of the bytes.");
971
972 #define BYTES_ENDSWITH_METHODDEF \
973 {"endswith", _PyCFunction_CAST(bytes_endswith), METH_FASTCALL, bytes_endswith__doc__},
974
975 static PyObject *
976 bytes_endswith_impl(PyBytesObject *self, PyObject *subobj, Py_ssize_t start,
977 Py_ssize_t end);
978
979 static PyObject *
980 bytes_endswith(PyBytesObject *self, PyObject *const *args, Py_ssize_t nargs)
981 {
982 PyObject *return_value = NULL;
983 PyObject *subobj;
984 Py_ssize_t start = 0;
985 Py_ssize_t end = PY_SSIZE_T_MAX;
986
987 if (!_PyArg_CheckPositional("endswith", nargs, 1, 3)) {
988 goto exit;
989 }
990 subobj = args[0];
991 if (nargs < 2) {
992 goto skip_optional;
993 }
994 if (!_PyEval_SliceIndex(args[1], &start)) {
995 goto exit;
996 }
997 if (nargs < 3) {
998 goto skip_optional;
999 }
1000 if (!_PyEval_SliceIndex(args[2], &end)) {
1001 goto exit;
1002 }
1003 skip_optional:
1004 return_value = bytes_endswith_impl(self, subobj, start, end);
1005
1006 exit:
1007 return return_value;
1008 }
1009
1010 PyDoc_STRVAR(bytes_decode__doc__,
1011 "decode($self, /, encoding=\'utf-8\', errors=\'strict\')\n"
1012 "--\n"
1013 "\n"
1014 "Decode the bytes using the codec registered for encoding.\n"
1015 "\n"
1016 " encoding\n"
1017 " The encoding with which to decode the bytes.\n"
1018 " errors\n"
1019 " The error handling scheme to use for the handling of decoding errors.\n"
1020 " The default is \'strict\' meaning that decoding errors raise a\n"
1021 " UnicodeDecodeError. Other possible values are \'ignore\' and \'replace\'\n"
1022 " as well as any other name registered with codecs.register_error that\n"
1023 " can handle UnicodeDecodeErrors.");
1024
1025 #define BYTES_DECODE_METHODDEF \
1026 {"decode", _PyCFunction_CAST(bytes_decode), METH_FASTCALL|METH_KEYWORDS, bytes_decode__doc__},
1027
1028 static PyObject *
1029 bytes_decode_impl(PyBytesObject *self, const char *encoding,
1030 const char *errors);
1031
1032 static PyObject *
1033 bytes_decode(PyBytesObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1034 {
1035 PyObject *return_value = NULL;
1036 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1037
1038 #define NUM_KEYWORDS 2
1039 static struct {
1040 PyGC_Head _this_is_not_used;
1041 PyObject_VAR_HEAD
1042 PyObject *ob_item[NUM_KEYWORDS];
1043 } _kwtuple = {
1044 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1045 .ob_item = { &_Py_ID(encoding), &_Py_ID(errors), },
1046 };
1047 #undef NUM_KEYWORDS
1048 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1049
1050 #else // !Py_BUILD_CORE
1051 # define KWTUPLE NULL
1052 #endif // !Py_BUILD_CORE
1053
1054 static const char * const _keywords[] = {"encoding", "errors", NULL};
1055 static _PyArg_Parser _parser = {
1056 .keywords = _keywords,
1057 .fname = "decode",
1058 .kwtuple = KWTUPLE,
1059 };
1060 #undef KWTUPLE
1061 PyObject *argsbuf[2];
1062 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
1063 const char *encoding = NULL;
1064 const char *errors = NULL;
1065
1066 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 2, 0, argsbuf);
1067 if (!args) {
1068 goto exit;
1069 }
1070 if (!noptargs) {
1071 goto skip_optional_pos;
1072 }
1073 if (args[0]) {
1074 if (!PyUnicode_Check(args[0])) {
1075 _PyArg_BadArgument("decode", "argument 'encoding'", "str", args[0]);
1076 goto exit;
1077 }
1078 Py_ssize_t encoding_length;
1079 encoding = PyUnicode_AsUTF8AndSize(args[0], &encoding_length);
1080 if (encoding == NULL) {
1081 goto exit;
1082 }
1083 if (strlen(encoding) != (size_t)encoding_length) {
1084 PyErr_SetString(PyExc_ValueError, "embedded null character");
1085 goto exit;
1086 }
1087 if (!--noptargs) {
1088 goto skip_optional_pos;
1089 }
1090 }
1091 if (!PyUnicode_Check(args[1])) {
1092 _PyArg_BadArgument("decode", "argument 'errors'", "str", args[1]);
1093 goto exit;
1094 }
1095 Py_ssize_t errors_length;
1096 errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
1097 if (errors == NULL) {
1098 goto exit;
1099 }
1100 if (strlen(errors) != (size_t)errors_length) {
1101 PyErr_SetString(PyExc_ValueError, "embedded null character");
1102 goto exit;
1103 }
1104 skip_optional_pos:
1105 return_value = bytes_decode_impl(self, encoding, errors);
1106
1107 exit:
1108 return return_value;
1109 }
1110
1111 PyDoc_STRVAR(bytes_splitlines__doc__,
1112 "splitlines($self, /, keepends=False)\n"
1113 "--\n"
1114 "\n"
1115 "Return a list of the lines in the bytes, breaking at line boundaries.\n"
1116 "\n"
1117 "Line breaks are not included in the resulting list unless keepends is given and\n"
1118 "true.");
1119
1120 #define BYTES_SPLITLINES_METHODDEF \
1121 {"splitlines", _PyCFunction_CAST(bytes_splitlines), METH_FASTCALL|METH_KEYWORDS, bytes_splitlines__doc__},
1122
1123 static PyObject *
1124 bytes_splitlines_impl(PyBytesObject *self, int keepends);
1125
1126 static PyObject *
1127 bytes_splitlines(PyBytesObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1128 {
1129 PyObject *return_value = NULL;
1130 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1131
1132 #define NUM_KEYWORDS 1
1133 static struct {
1134 PyGC_Head _this_is_not_used;
1135 PyObject_VAR_HEAD
1136 PyObject *ob_item[NUM_KEYWORDS];
1137 } _kwtuple = {
1138 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1139 .ob_item = { &_Py_ID(keepends), },
1140 };
1141 #undef NUM_KEYWORDS
1142 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1143
1144 #else // !Py_BUILD_CORE
1145 # define KWTUPLE NULL
1146 #endif // !Py_BUILD_CORE
1147
1148 static const char * const _keywords[] = {"keepends", NULL};
1149 static _PyArg_Parser _parser = {
1150 .keywords = _keywords,
1151 .fname = "splitlines",
1152 .kwtuple = KWTUPLE,
1153 };
1154 #undef KWTUPLE
1155 PyObject *argsbuf[1];
1156 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
1157 int keepends = 0;
1158
1159 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
1160 if (!args) {
1161 goto exit;
1162 }
1163 if (!noptargs) {
1164 goto skip_optional_pos;
1165 }
1166 keepends = PyObject_IsTrue(args[0]);
1167 if (keepends < 0) {
1168 goto exit;
1169 }
1170 skip_optional_pos:
1171 return_value = bytes_splitlines_impl(self, keepends);
1172
1173 exit:
1174 return return_value;
1175 }
1176
1177 PyDoc_STRVAR(bytes_fromhex__doc__,
1178 "fromhex($type, string, /)\n"
1179 "--\n"
1180 "\n"
1181 "Create a bytes object from a string of hexadecimal numbers.\n"
1182 "\n"
1183 "Spaces between two numbers are accepted.\n"
1184 "Example: bytes.fromhex(\'B9 01EF\') -> b\'\\\\xb9\\\\x01\\\\xef\'.");
1185
1186 #define BYTES_FROMHEX_METHODDEF \
1187 {"fromhex", (PyCFunction)bytes_fromhex, METH_O|METH_CLASS, bytes_fromhex__doc__},
1188
1189 static PyObject *
1190 bytes_fromhex_impl(PyTypeObject *type, PyObject *string);
1191
1192 static PyObject *
1193 bytes_fromhex(PyTypeObject *type, PyObject *arg)
1194 {
1195 PyObject *return_value = NULL;
1196 PyObject *string;
1197
1198 if (!PyUnicode_Check(arg)) {
1199 _PyArg_BadArgument("fromhex", "argument", "str", arg);
1200 goto exit;
1201 }
1202 string = arg;
1203 return_value = bytes_fromhex_impl(type, string);
1204
1205 exit:
1206 return return_value;
1207 }
1208
1209 PyDoc_STRVAR(bytes_hex__doc__,
1210 "hex($self, /, sep=<unrepresentable>, bytes_per_sep=1)\n"
1211 "--\n"
1212 "\n"
1213 "Create a string of hexadecimal numbers from a bytes object.\n"
1214 "\n"
1215 " sep\n"
1216 " An optional single character or byte to separate hex bytes.\n"
1217 " bytes_per_sep\n"
1218 " How many bytes between separators. Positive values count from the\n"
1219 " right, negative values count from the left.\n"
1220 "\n"
1221 "Example:\n"
1222 ">>> value = b\'\\xb9\\x01\\xef\'\n"
1223 ">>> value.hex()\n"
1224 "\'b901ef\'\n"
1225 ">>> value.hex(\':\')\n"
1226 "\'b9:01:ef\'\n"
1227 ">>> value.hex(\':\', 2)\n"
1228 "\'b9:01ef\'\n"
1229 ">>> value.hex(\':\', -2)\n"
1230 "\'b901:ef\'");
1231
1232 #define BYTES_HEX_METHODDEF \
1233 {"hex", _PyCFunction_CAST(bytes_hex), METH_FASTCALL|METH_KEYWORDS, bytes_hex__doc__},
1234
1235 static PyObject *
1236 bytes_hex_impl(PyBytesObject *self, PyObject *sep, int bytes_per_sep);
1237
1238 static PyObject *
1239 bytes_hex(PyBytesObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1240 {
1241 PyObject *return_value = NULL;
1242 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1243
1244 #define NUM_KEYWORDS 2
1245 static struct {
1246 PyGC_Head _this_is_not_used;
1247 PyObject_VAR_HEAD
1248 PyObject *ob_item[NUM_KEYWORDS];
1249 } _kwtuple = {
1250 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1251 .ob_item = { &_Py_ID(sep), &_Py_ID(bytes_per_sep), },
1252 };
1253 #undef NUM_KEYWORDS
1254 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1255
1256 #else // !Py_BUILD_CORE
1257 # define KWTUPLE NULL
1258 #endif // !Py_BUILD_CORE
1259
1260 static const char * const _keywords[] = {"sep", "bytes_per_sep", NULL};
1261 static _PyArg_Parser _parser = {
1262 .keywords = _keywords,
1263 .fname = "hex",
1264 .kwtuple = KWTUPLE,
1265 };
1266 #undef KWTUPLE
1267 PyObject *argsbuf[2];
1268 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
1269 PyObject *sep = NULL;
1270 int bytes_per_sep = 1;
1271
1272 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 2, 0, argsbuf);
1273 if (!args) {
1274 goto exit;
1275 }
1276 if (!noptargs) {
1277 goto skip_optional_pos;
1278 }
1279 if (args[0]) {
1280 sep = args[0];
1281 if (!--noptargs) {
1282 goto skip_optional_pos;
1283 }
1284 }
1285 bytes_per_sep = PyLong_AsInt(args[1]);
1286 if (bytes_per_sep == -1 && PyErr_Occurred()) {
1287 goto exit;
1288 }
1289 skip_optional_pos:
1290 return_value = bytes_hex_impl(self, sep, bytes_per_sep);
1291
1292 exit:
1293 return return_value;
1294 }
1295
1296 static PyObject *
1297 bytes_new_impl(PyTypeObject *type, PyObject *x, const char *encoding,
1298 const char *errors);
1299
1300 static PyObject *
1301 bytes_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
1302 {
1303 PyObject *return_value = NULL;
1304 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1305
1306 #define NUM_KEYWORDS 3
1307 static struct {
1308 PyGC_Head _this_is_not_used;
1309 PyObject_VAR_HEAD
1310 PyObject *ob_item[NUM_KEYWORDS];
1311 } _kwtuple = {
1312 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1313 .ob_item = { &_Py_ID(source), &_Py_ID(encoding), &_Py_ID(errors), },
1314 };
1315 #undef NUM_KEYWORDS
1316 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1317
1318 #else // !Py_BUILD_CORE
1319 # define KWTUPLE NULL
1320 #endif // !Py_BUILD_CORE
1321
1322 static const char * const _keywords[] = {"source", "encoding", "errors", NULL};
1323 static _PyArg_Parser _parser = {
1324 .keywords = _keywords,
1325 .fname = "bytes",
1326 .kwtuple = KWTUPLE,
1327 };
1328 #undef KWTUPLE
1329 PyObject *argsbuf[3];
1330 PyObject * const *fastargs;
1331 Py_ssize_t nargs = PyTuple_GET_SIZE(args);
1332 Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 0;
1333 PyObject *x = NULL;
1334 const char *encoding = NULL;
1335 const char *errors = NULL;
1336
1337 fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 0, 3, 0, argsbuf);
1338 if (!fastargs) {
1339 goto exit;
1340 }
1341 if (!noptargs) {
1342 goto skip_optional_pos;
1343 }
1344 if (fastargs[0]) {
1345 x = fastargs[0];
1346 if (!--noptargs) {
1347 goto skip_optional_pos;
1348 }
1349 }
1350 if (fastargs[1]) {
1351 if (!PyUnicode_Check(fastargs[1])) {
1352 _PyArg_BadArgument("bytes", "argument 'encoding'", "str", fastargs[1]);
1353 goto exit;
1354 }
1355 Py_ssize_t encoding_length;
1356 encoding = PyUnicode_AsUTF8AndSize(fastargs[1], &encoding_length);
1357 if (encoding == NULL) {
1358 goto exit;
1359 }
1360 if (strlen(encoding) != (size_t)encoding_length) {
1361 PyErr_SetString(PyExc_ValueError, "embedded null character");
1362 goto exit;
1363 }
1364 if (!--noptargs) {
1365 goto skip_optional_pos;
1366 }
1367 }
1368 if (!PyUnicode_Check(fastargs[2])) {
1369 _PyArg_BadArgument("bytes", "argument 'errors'", "str", fastargs[2]);
1370 goto exit;
1371 }
1372 Py_ssize_t errors_length;
1373 errors = PyUnicode_AsUTF8AndSize(fastargs[2], &errors_length);
1374 if (errors == NULL) {
1375 goto exit;
1376 }
1377 if (strlen(errors) != (size_t)errors_length) {
1378 PyErr_SetString(PyExc_ValueError, "embedded null character");
1379 goto exit;
1380 }
1381 skip_optional_pos:
1382 return_value = bytes_new_impl(type, x, encoding, errors);
1383
1384 exit:
1385 return return_value;
1386 }
1387 /*[clinic end generated code: output=d6801c6001e57f91 input=a9049054013a1b77]*/