1 /*[clinic input] 2 preserve 3 [clinic start generated code]*/ 4 5 PyDoc_STRVAR(bytes_split__doc__, 6 "split($self, /, sep=None, maxsplit=-1)\n" 7 "--\n" 8 "\n" 9 "Return a list of the sections in the bytes, using sep as the delimiter.\n" 10 "\n" 11 " sep\n" 12 " The delimiter according which to split the bytes.\n" 13 " None (the default value) means split on ASCII whitespace characters\n" 14 " (space, tab, return, newline, formfeed, vertical tab).\n" 15 " maxsplit\n" 16 " Maximum number of splits to do.\n" 17 " -1 (the default value) means no limit."); 18 19 #define BYTES_SPLIT_METHODDEF \ 20 {"split", (PyCFunction)bytes_split, METH_FASTCALL, bytes_split__doc__}, 21 22 static PyObject * 23 bytes_split_impl(PyBytesObject *self, PyObject *sep, Py_ssize_t maxsplit); 24 25 static PyObject * 26 bytes_split(PyBytesObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) 27 { 28 PyObject *return_value = NULL; 29 static const char * const _keywords[] = {"sep", "maxsplit", NULL}; 30 static _PyArg_Parser _parser = {"|On:split", _keywords, 0}; 31 PyObject *sep = Py_None; 32 Py_ssize_t maxsplit = -1; 33 34 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser, 35 &sep, &maxsplit)) { 36 goto exit; 37 } 38 return_value = bytes_split_impl(self, sep, maxsplit); 39 40 exit: 41 return return_value; 42 } 43 44 PyDoc_STRVAR(bytes_partition__doc__, 45 "partition($self, sep, /)\n" 46 "--\n" 47 "\n" 48 "Partition the bytes into three parts using the given separator.\n" 49 "\n" 50 "This will search for the separator sep in the bytes. If the separator is found,\n" 51 "returns a 3-tuple containing the part before the separator, the separator\n" 52 "itself, and the part after it.\n" 53 "\n" 54 "If the separator is not found, returns a 3-tuple containing the original bytes\n" 55 "object and two empty bytes objects."); 56 57 #define BYTES_PARTITION_METHODDEF \ 58 {"partition", (PyCFunction)bytes_partition, METH_O, bytes_partition__doc__}, 59 60 static PyObject * 61 bytes_partition_impl(PyBytesObject *self, Py_buffer *sep); 62 63 static PyObject * 64 bytes_partition(PyBytesObject *self, PyObject *arg) 65 { 66 PyObject *return_value = NULL; 67 Py_buffer sep = {NULL, NULL}; 68 69 if (!PyArg_Parse(arg, "y*:partition", &sep)) { 70 goto exit; 71 } 72 return_value = bytes_partition_impl(self, &sep); 73 74 exit: 75 /* Cleanup for sep */ 76 if (sep.obj) { 77 PyBuffer_Release(&sep); 78 } 79 80 return return_value; 81 } 82 83 PyDoc_STRVAR(bytes_rpartition__doc__, 84 "rpartition($self, sep, /)\n" 85 "--\n" 86 "\n" 87 "Partition the bytes into three parts using the given separator.\n" 88 "\n" 89 "This will search for the separator sep in the bytes, starting and the end. If\n" 90 "the separator is found, returns a 3-tuple containing the part before the\n" 91 "separator, the separator itself, and the part after it.\n" 92 "\n" 93 "If the separator is not found, returns a 3-tuple containing two empty bytes\n" 94 "objects and the original bytes object."); 95 96 #define BYTES_RPARTITION_METHODDEF \ 97 {"rpartition", (PyCFunction)bytes_rpartition, METH_O, bytes_rpartition__doc__}, 98 99 static PyObject * 100 bytes_rpartition_impl(PyBytesObject *self, Py_buffer *sep); 101 102 static PyObject * 103 bytes_rpartition(PyBytesObject *self, PyObject *arg) 104 { 105 PyObject *return_value = NULL; 106 Py_buffer sep = {NULL, NULL}; 107 108 if (!PyArg_Parse(arg, "y*:rpartition", &sep)) { 109 goto exit; 110 } 111 return_value = bytes_rpartition_impl(self, &sep); 112 113 exit: 114 /* Cleanup for sep */ 115 if (sep.obj) { 116 PyBuffer_Release(&sep); 117 } 118 119 return return_value; 120 } 121 122 PyDoc_STRVAR(bytes_rsplit__doc__, 123 "rsplit($self, /, sep=None, maxsplit=-1)\n" 124 "--\n" 125 "\n" 126 "Return a list of the sections in the bytes, using sep as the delimiter.\n" 127 "\n" 128 " sep\n" 129 " The delimiter according which to split the bytes.\n" 130 " None (the default value) means split on ASCII whitespace characters\n" 131 " (space, tab, return, newline, formfeed, vertical tab).\n" 132 " maxsplit\n" 133 " Maximum number of splits to do.\n" 134 " -1 (the default value) means no limit.\n" 135 "\n" 136 "Splitting is done starting at the end of the bytes and working to the front."); 137 138 #define BYTES_RSPLIT_METHODDEF \ 139 {"rsplit", (PyCFunction)bytes_rsplit, METH_FASTCALL, bytes_rsplit__doc__}, 140 141 static PyObject * 142 bytes_rsplit_impl(PyBytesObject *self, PyObject *sep, Py_ssize_t maxsplit); 143 144 static PyObject * 145 bytes_rsplit(PyBytesObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) 146 { 147 PyObject *return_value = NULL; 148 static const char * const _keywords[] = {"sep", "maxsplit", NULL}; 149 static _PyArg_Parser _parser = {"|On:rsplit", _keywords, 0}; 150 PyObject *sep = Py_None; 151 Py_ssize_t maxsplit = -1; 152 153 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser, 154 &sep, &maxsplit)) { 155 goto exit; 156 } 157 return_value = bytes_rsplit_impl(self, sep, maxsplit); 158 159 exit: 160 return return_value; 161 } 162 163 PyDoc_STRVAR(bytes_join__doc__, 164 "join($self, iterable_of_bytes, /)\n" 165 "--\n" 166 "\n" 167 "Concatenate any number of bytes objects.\n" 168 "\n" 169 "The bytes whose method is called is inserted in between each pair.\n" 170 "\n" 171 "The result is returned as a new bytes object.\n" 172 "\n" 173 "Example: b\'.\'.join([b\'ab\', b\'pq\', b\'rs\']) -> b\'ab.pq.rs\'."); 174 175 #define BYTES_JOIN_METHODDEF \ 176 {"join", (PyCFunction)bytes_join, METH_O, bytes_join__doc__}, 177 178 PyDoc_STRVAR(bytes_strip__doc__, 179 "strip($self, bytes=None, /)\n" 180 "--\n" 181 "\n" 182 "Strip leading and trailing bytes contained in the argument.\n" 183 "\n" 184 "If the argument is omitted or None, strip leading and trailing ASCII whitespace."); 185 186 #define BYTES_STRIP_METHODDEF \ 187 {"strip", (PyCFunction)bytes_strip, METH_VARARGS, bytes_strip__doc__}, 188 189 static PyObject * 190 bytes_strip_impl(PyBytesObject *self, PyObject *bytes); 191 192 static PyObject * 193 bytes_strip(PyBytesObject *self, PyObject *args) 194 { 195 PyObject *return_value = NULL; 196 PyObject *bytes = Py_None; 197 198 if (!PyArg_UnpackTuple(args, "strip", 199 0, 1, 200 &bytes)) { 201 goto exit; 202 } 203 return_value = bytes_strip_impl(self, bytes); 204 205 exit: 206 return return_value; 207 } 208 209 PyDoc_STRVAR(bytes_lstrip__doc__, 210 "lstrip($self, bytes=None, /)\n" 211 "--\n" 212 "\n" 213 "Strip leading bytes contained in the argument.\n" 214 "\n" 215 "If the argument is omitted or None, strip leading ASCII whitespace."); 216 217 #define BYTES_LSTRIP_METHODDEF \ 218 {"lstrip", (PyCFunction)bytes_lstrip, METH_VARARGS, bytes_lstrip__doc__}, 219 220 static PyObject * 221 bytes_lstrip_impl(PyBytesObject *self, PyObject *bytes); 222 223 static PyObject * 224 bytes_lstrip(PyBytesObject *self, PyObject *args) 225 { 226 PyObject *return_value = NULL; 227 PyObject *bytes = Py_None; 228 229 if (!PyArg_UnpackTuple(args, "lstrip", 230 0, 1, 231 &bytes)) { 232 goto exit; 233 } 234 return_value = bytes_lstrip_impl(self, bytes); 235 236 exit: 237 return return_value; 238 } 239 240 PyDoc_STRVAR(bytes_rstrip__doc__, 241 "rstrip($self, bytes=None, /)\n" 242 "--\n" 243 "\n" 244 "Strip trailing bytes contained in the argument.\n" 245 "\n" 246 "If the argument is omitted or None, strip trailing ASCII whitespace."); 247 248 #define BYTES_RSTRIP_METHODDEF \ 249 {"rstrip", (PyCFunction)bytes_rstrip, METH_VARARGS, bytes_rstrip__doc__}, 250 251 static PyObject * 252 bytes_rstrip_impl(PyBytesObject *self, PyObject *bytes); 253 254 static PyObject * 255 bytes_rstrip(PyBytesObject *self, PyObject *args) 256 { 257 PyObject *return_value = NULL; 258 PyObject *bytes = Py_None; 259 260 if (!PyArg_UnpackTuple(args, "rstrip", 261 0, 1, 262 &bytes)) { 263 goto exit; 264 } 265 return_value = bytes_rstrip_impl(self, bytes); 266 267 exit: 268 return return_value; 269 } 270 271 PyDoc_STRVAR(bytes_translate__doc__, 272 "translate($self, table, /, delete=b\'\')\n" 273 "--\n" 274 "\n" 275 "Return a copy with each character mapped by the given translation table.\n" 276 "\n" 277 " table\n" 278 " Translation table, which must be a bytes object of length 256.\n" 279 "\n" 280 "All characters occurring in the optional argument delete are removed.\n" 281 "The remaining characters are mapped through the given translation table."); 282 283 #define BYTES_TRANSLATE_METHODDEF \ 284 {"translate", (PyCFunction)bytes_translate, METH_FASTCALL, bytes_translate__doc__}, 285 286 static PyObject * 287 bytes_translate_impl(PyBytesObject *self, PyObject *table, 288 PyObject *deletechars); 289 290 static PyObject * 291 bytes_translate(PyBytesObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) 292 { 293 PyObject *return_value = NULL; 294 static const char * const _keywords[] = {"", "delete", NULL}; 295 static _PyArg_Parser _parser = {"O|O:translate", _keywords, 0}; 296 PyObject *table; 297 PyObject *deletechars = NULL; 298 299 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser, 300 &table, &deletechars)) { 301 goto exit; 302 } 303 return_value = bytes_translate_impl(self, table, deletechars); 304 305 exit: 306 return return_value; 307 } 308 309 PyDoc_STRVAR(bytes_maketrans__doc__, 310 "maketrans(frm, to, /)\n" 311 "--\n" 312 "\n" 313 "Return a translation table useable for the bytes or bytearray translate method.\n" 314 "\n" 315 "The returned table will be one where each byte in frm is mapped to the byte at\n" 316 "the same position in to.\n" 317 "\n" 318 "The bytes objects frm and to must be of the same length."); 319 320 #define BYTES_MAKETRANS_METHODDEF \ 321 {"maketrans", (PyCFunction)bytes_maketrans, METH_VARARGS|METH_STATIC, bytes_maketrans__doc__}, 322 323 static PyObject * 324 bytes_maketrans_impl(Py_buffer *frm, Py_buffer *to); 325 326 static PyObject * 327 bytes_maketrans(void *null, PyObject *args) 328 { 329 PyObject *return_value = NULL; 330 Py_buffer frm = {NULL, NULL}; 331 Py_buffer to = {NULL, NULL}; 332 333 if (!PyArg_ParseTuple(args, "y*y*:maketrans", 334 &frm, &to)) { 335 goto exit; 336 } 337 return_value = bytes_maketrans_impl(&frm, &to); 338 339 exit: 340 /* Cleanup for frm */ 341 if (frm.obj) { 342 PyBuffer_Release(&frm); 343 } 344 /* Cleanup for to */ 345 if (to.obj) { 346 PyBuffer_Release(&to); 347 } 348 349 return return_value; 350 } 351 352 PyDoc_STRVAR(bytes_replace__doc__, 353 "replace($self, old, new, count=-1, /)\n" 354 "--\n" 355 "\n" 356 "Return a copy with all occurrences of substring old replaced by new.\n" 357 "\n" 358 " count\n" 359 " Maximum number of occurrences to replace.\n" 360 " -1 (the default value) means replace all occurrences.\n" 361 "\n" 362 "If the optional argument count is given, only the first count occurrences are\n" 363 "replaced."); 364 365 #define BYTES_REPLACE_METHODDEF \ 366 {"replace", (PyCFunction)bytes_replace, METH_VARARGS, bytes_replace__doc__}, 367 368 static PyObject * 369 bytes_replace_impl(PyBytesObject *self, Py_buffer *old, Py_buffer *new, 370 Py_ssize_t count); 371 372 static PyObject * 373 bytes_replace(PyBytesObject *self, PyObject *args) 374 { 375 PyObject *return_value = NULL; 376 Py_buffer old = {NULL, NULL}; 377 Py_buffer new = {NULL, NULL}; 378 Py_ssize_t count = -1; 379 380 if (!PyArg_ParseTuple(args, "y*y*|n:replace", 381 &old, &new, &count)) { 382 goto exit; 383 } 384 return_value = bytes_replace_impl(self, &old, &new, count); 385 386 exit: 387 /* Cleanup for old */ 388 if (old.obj) { 389 PyBuffer_Release(&old); 390 } 391 /* Cleanup for new */ 392 if (new.obj) { 393 PyBuffer_Release(&new); 394 } 395 396 return return_value; 397 } 398 399 PyDoc_STRVAR(bytes_decode__doc__, 400 "decode($self, /, encoding=\'utf-8\', errors=\'strict\')\n" 401 "--\n" 402 "\n" 403 "Decode the bytes using the codec registered for encoding.\n" 404 "\n" 405 " encoding\n" 406 " The encoding with which to decode the bytes.\n" 407 " errors\n" 408 " The error handling scheme to use for the handling of decoding errors.\n" 409 " The default is \'strict\' meaning that decoding errors raise a\n" 410 " UnicodeDecodeError. Other possible values are \'ignore\' and \'replace\'\n" 411 " as well as any other name registered with codecs.register_error that\n" 412 " can handle UnicodeDecodeErrors."); 413 414 #define BYTES_DECODE_METHODDEF \ 415 {"decode", (PyCFunction)bytes_decode, METH_FASTCALL, bytes_decode__doc__}, 416 417 static PyObject * 418 bytes_decode_impl(PyBytesObject *self, const char *encoding, 419 const char *errors); 420 421 static PyObject * 422 bytes_decode(PyBytesObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) 423 { 424 PyObject *return_value = NULL; 425 static const char * const _keywords[] = {"encoding", "errors", NULL}; 426 static _PyArg_Parser _parser = {"|ss:decode", _keywords, 0}; 427 const char *encoding = NULL; 428 const char *errors = NULL; 429 430 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser, 431 &encoding, &errors)) { 432 goto exit; 433 } 434 return_value = bytes_decode_impl(self, encoding, errors); 435 436 exit: 437 return return_value; 438 } 439 440 PyDoc_STRVAR(bytes_splitlines__doc__, 441 "splitlines($self, /, keepends=False)\n" 442 "--\n" 443 "\n" 444 "Return a list of the lines in the bytes, breaking at line boundaries.\n" 445 "\n" 446 "Line breaks are not included in the resulting list unless keepends is given and\n" 447 "true."); 448 449 #define BYTES_SPLITLINES_METHODDEF \ 450 {"splitlines", (PyCFunction)bytes_splitlines, METH_FASTCALL, bytes_splitlines__doc__}, 451 452 static PyObject * 453 bytes_splitlines_impl(PyBytesObject *self, int keepends); 454 455 static PyObject * 456 bytes_splitlines(PyBytesObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) 457 { 458 PyObject *return_value = NULL; 459 static const char * const _keywords[] = {"keepends", NULL}; 460 static _PyArg_Parser _parser = {"|i:splitlines", _keywords, 0}; 461 int keepends = 0; 462 463 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser, 464 &keepends)) { 465 goto exit; 466 } 467 return_value = bytes_splitlines_impl(self, keepends); 468 469 exit: 470 return return_value; 471 } 472 473 PyDoc_STRVAR(bytes_fromhex__doc__, 474 "fromhex($type, string, /)\n" 475 "--\n" 476 "\n" 477 "Create a bytes object from a string of hexadecimal numbers.\n" 478 "\n" 479 "Spaces between two numbers are accepted.\n" 480 "Example: bytes.fromhex(\'B9 01EF\') -> b\'\\\\xb9\\\\x01\\\\xef\'."); 481 482 #define BYTES_FROMHEX_METHODDEF \ 483 {"fromhex", (PyCFunction)bytes_fromhex, METH_O|METH_CLASS, bytes_fromhex__doc__}, 484 485 static PyObject * 486 bytes_fromhex_impl(PyTypeObject *type, PyObject *string); 487 488 static PyObject * 489 bytes_fromhex(PyTypeObject *type, PyObject *arg) 490 { 491 PyObject *return_value = NULL; 492 PyObject *string; 493 494 if (!PyArg_Parse(arg, "U:fromhex", &string)) { 495 goto exit; 496 } 497 return_value = bytes_fromhex_impl(type, string); 498 499 exit: 500 return return_value; 501 } 502 /*[clinic end generated code: output=2dc3c93cfd2dc440 input=a9049054013a1b77]*/ 503