Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 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 | { |
| 20 | return bytearray_clear_impl(self); |
| 21 | } |
| 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 | { |
| 38 | return bytearray_copy_impl(self); |
| 39 | } |
| 40 | |
| 41 | PyDoc_STRVAR(bytearray_translate__doc__, |
| 42 | "translate(table, [deletechars])\n" |
| 43 | "Return a copy with each character mapped by the given translation table.\n" |
| 44 | "\n" |
| 45 | " table\n" |
| 46 | " Translation table, which must be a bytes object of length 256.\n" |
| 47 | "\n" |
| 48 | "All characters occurring in the optional argument deletechars are removed.\n" |
| 49 | "The remaining characters are mapped through the given translation table."); |
| 50 | |
| 51 | #define BYTEARRAY_TRANSLATE_METHODDEF \ |
| 52 | {"translate", (PyCFunction)bytearray_translate, METH_VARARGS, bytearray_translate__doc__}, |
| 53 | |
| 54 | static PyObject * |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 55 | bytearray_translate_impl(PyByteArrayObject *self, PyObject *table, |
| 56 | int group_right_1, PyObject *deletechars); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 57 | |
| 58 | static PyObject * |
| 59 | bytearray_translate(PyByteArrayObject *self, PyObject *args) |
| 60 | { |
| 61 | PyObject *return_value = NULL; |
| 62 | PyObject *table; |
| 63 | int group_right_1 = 0; |
| 64 | PyObject *deletechars = NULL; |
| 65 | |
| 66 | switch (PyTuple_GET_SIZE(args)) { |
| 67 | case 1: |
| 68 | if (!PyArg_ParseTuple(args, "O:translate", &table)) |
| 69 | goto exit; |
| 70 | break; |
| 71 | case 2: |
| 72 | if (!PyArg_ParseTuple(args, "OO:translate", &table, &deletechars)) |
| 73 | goto exit; |
| 74 | group_right_1 = 1; |
| 75 | break; |
| 76 | default: |
| 77 | PyErr_SetString(PyExc_TypeError, "bytearray.translate requires 1 to 2 arguments"); |
| 78 | goto exit; |
| 79 | } |
| 80 | return_value = bytearray_translate_impl(self, table, group_right_1, deletechars); |
| 81 | |
| 82 | exit: |
| 83 | return return_value; |
| 84 | } |
| 85 | |
| 86 | PyDoc_STRVAR(bytearray_maketrans__doc__, |
| 87 | "maketrans(frm, to, /)\n" |
| 88 | "--\n" |
| 89 | "\n" |
| 90 | "Return a translation table useable for the bytes or bytearray translate method.\n" |
| 91 | "\n" |
| 92 | "The returned table will be one where each byte in frm is mapped to the byte at\n" |
| 93 | "the same position in to.\n" |
| 94 | "\n" |
| 95 | "The bytes objects frm and to must be of the same length."); |
| 96 | |
| 97 | #define BYTEARRAY_MAKETRANS_METHODDEF \ |
| 98 | {"maketrans", (PyCFunction)bytearray_maketrans, METH_VARARGS|METH_STATIC, bytearray_maketrans__doc__}, |
| 99 | |
| 100 | static PyObject * |
| 101 | bytearray_maketrans_impl(Py_buffer *frm, Py_buffer *to); |
| 102 | |
| 103 | static PyObject * |
| 104 | bytearray_maketrans(void *null, PyObject *args) |
| 105 | { |
| 106 | PyObject *return_value = NULL; |
| 107 | Py_buffer frm = {NULL, NULL}; |
| 108 | Py_buffer to = {NULL, NULL}; |
| 109 | |
Serhiy Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 110 | if (!PyArg_ParseTuple(args, "y*y*:maketrans", |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 111 | &frm, &to)) |
| 112 | goto exit; |
| 113 | return_value = bytearray_maketrans_impl(&frm, &to); |
| 114 | |
| 115 | exit: |
| 116 | /* Cleanup for frm */ |
| 117 | if (frm.obj) |
| 118 | PyBuffer_Release(&frm); |
| 119 | /* Cleanup for to */ |
| 120 | if (to.obj) |
| 121 | PyBuffer_Release(&to); |
| 122 | |
| 123 | return return_value; |
| 124 | } |
| 125 | |
| 126 | PyDoc_STRVAR(bytearray_replace__doc__, |
| 127 | "replace($self, old, new, count=-1, /)\n" |
| 128 | "--\n" |
| 129 | "\n" |
| 130 | "Return a copy with all occurrences of substring old replaced by new.\n" |
| 131 | "\n" |
| 132 | " count\n" |
| 133 | " Maximum number of occurrences to replace.\n" |
| 134 | " -1 (the default value) means replace all occurrences.\n" |
| 135 | "\n" |
| 136 | "If the optional argument count is given, only the first count occurrences are\n" |
| 137 | "replaced."); |
| 138 | |
| 139 | #define BYTEARRAY_REPLACE_METHODDEF \ |
| 140 | {"replace", (PyCFunction)bytearray_replace, METH_VARARGS, bytearray_replace__doc__}, |
| 141 | |
| 142 | static PyObject * |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 143 | bytearray_replace_impl(PyByteArrayObject *self, Py_buffer *old, |
| 144 | Py_buffer *new, Py_ssize_t count); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 145 | |
| 146 | static PyObject * |
| 147 | bytearray_replace(PyByteArrayObject *self, PyObject *args) |
| 148 | { |
| 149 | PyObject *return_value = NULL; |
| 150 | Py_buffer old = {NULL, NULL}; |
| 151 | Py_buffer new = {NULL, NULL}; |
| 152 | Py_ssize_t count = -1; |
| 153 | |
Serhiy Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 154 | if (!PyArg_ParseTuple(args, "y*y*|n:replace", |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 155 | &old, &new, &count)) |
| 156 | goto exit; |
| 157 | return_value = bytearray_replace_impl(self, &old, &new, count); |
| 158 | |
| 159 | exit: |
| 160 | /* Cleanup for old */ |
| 161 | if (old.obj) |
| 162 | PyBuffer_Release(&old); |
| 163 | /* Cleanup for new */ |
| 164 | if (new.obj) |
| 165 | PyBuffer_Release(&new); |
| 166 | |
| 167 | return return_value; |
| 168 | } |
| 169 | |
| 170 | PyDoc_STRVAR(bytearray_split__doc__, |
| 171 | "split($self, /, sep=None, maxsplit=-1)\n" |
| 172 | "--\n" |
| 173 | "\n" |
| 174 | "Return a list of the sections in the bytearray, using sep as the delimiter.\n" |
| 175 | "\n" |
| 176 | " sep\n" |
| 177 | " The delimiter according which to split the bytearray.\n" |
| 178 | " None (the default value) means split on ASCII whitespace characters\n" |
| 179 | " (space, tab, return, newline, formfeed, vertical tab).\n" |
| 180 | " maxsplit\n" |
| 181 | " Maximum number of splits to do.\n" |
| 182 | " -1 (the default value) means no limit."); |
| 183 | |
| 184 | #define BYTEARRAY_SPLIT_METHODDEF \ |
| 185 | {"split", (PyCFunction)bytearray_split, METH_VARARGS|METH_KEYWORDS, bytearray_split__doc__}, |
| 186 | |
| 187 | static PyObject * |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 188 | bytearray_split_impl(PyByteArrayObject *self, PyObject *sep, |
| 189 | Py_ssize_t maxsplit); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 190 | |
| 191 | static PyObject * |
| 192 | bytearray_split(PyByteArrayObject *self, PyObject *args, PyObject *kwargs) |
| 193 | { |
| 194 | PyObject *return_value = NULL; |
| 195 | static char *_keywords[] = {"sep", "maxsplit", NULL}; |
| 196 | PyObject *sep = Py_None; |
| 197 | Py_ssize_t maxsplit = -1; |
| 198 | |
Serhiy Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 199 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|On:split", _keywords, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 200 | &sep, &maxsplit)) |
| 201 | goto exit; |
| 202 | return_value = bytearray_split_impl(self, sep, maxsplit); |
| 203 | |
| 204 | exit: |
| 205 | return return_value; |
| 206 | } |
| 207 | |
| 208 | PyDoc_STRVAR(bytearray_partition__doc__, |
| 209 | "partition($self, sep, /)\n" |
| 210 | "--\n" |
| 211 | "\n" |
| 212 | "Partition the bytearray into three parts using the given separator.\n" |
| 213 | "\n" |
| 214 | "This will search for the separator sep in the bytearray. If the separator is\n" |
| 215 | "found, returns a 3-tuple containing the part before the separator, the\n" |
| 216 | "separator itself, and the part after it.\n" |
| 217 | "\n" |
| 218 | "If the separator is not found, returns a 3-tuple containing the original\n" |
| 219 | "bytearray object and two empty bytearray objects."); |
| 220 | |
| 221 | #define BYTEARRAY_PARTITION_METHODDEF \ |
| 222 | {"partition", (PyCFunction)bytearray_partition, METH_O, bytearray_partition__doc__}, |
| 223 | |
| 224 | PyDoc_STRVAR(bytearray_rpartition__doc__, |
| 225 | "rpartition($self, sep, /)\n" |
| 226 | "--\n" |
| 227 | "\n" |
| 228 | "Partition the bytes into three parts using the given separator.\n" |
| 229 | "\n" |
| 230 | "This will search for the separator sep in the bytearray, starting and the end.\n" |
| 231 | "If the separator is found, returns a 3-tuple containing the part before the\n" |
| 232 | "separator, the separator itself, and the part after it.\n" |
| 233 | "\n" |
| 234 | "If the separator is not found, returns a 3-tuple containing two empty bytearray\n" |
| 235 | "objects and the original bytearray object."); |
| 236 | |
| 237 | #define BYTEARRAY_RPARTITION_METHODDEF \ |
| 238 | {"rpartition", (PyCFunction)bytearray_rpartition, METH_O, bytearray_rpartition__doc__}, |
| 239 | |
| 240 | PyDoc_STRVAR(bytearray_rsplit__doc__, |
| 241 | "rsplit($self, /, sep=None, maxsplit=-1)\n" |
| 242 | "--\n" |
| 243 | "\n" |
| 244 | "Return a list of the sections in the bytearray, using sep as the delimiter.\n" |
| 245 | "\n" |
| 246 | " sep\n" |
| 247 | " The delimiter according which to split the bytearray.\n" |
| 248 | " None (the default value) means split on ASCII whitespace characters\n" |
| 249 | " (space, tab, return, newline, formfeed, vertical tab).\n" |
| 250 | " maxsplit\n" |
| 251 | " Maximum number of splits to do.\n" |
| 252 | " -1 (the default value) means no limit.\n" |
| 253 | "\n" |
| 254 | "Splitting is done starting at the end of the bytearray and working to the front."); |
| 255 | |
| 256 | #define BYTEARRAY_RSPLIT_METHODDEF \ |
| 257 | {"rsplit", (PyCFunction)bytearray_rsplit, METH_VARARGS|METH_KEYWORDS, bytearray_rsplit__doc__}, |
| 258 | |
| 259 | static PyObject * |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 260 | bytearray_rsplit_impl(PyByteArrayObject *self, PyObject *sep, |
| 261 | Py_ssize_t maxsplit); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 262 | |
| 263 | static PyObject * |
| 264 | bytearray_rsplit(PyByteArrayObject *self, PyObject *args, PyObject *kwargs) |
| 265 | { |
| 266 | PyObject *return_value = NULL; |
| 267 | static char *_keywords[] = {"sep", "maxsplit", NULL}; |
| 268 | PyObject *sep = Py_None; |
| 269 | Py_ssize_t maxsplit = -1; |
| 270 | |
Serhiy Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 271 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|On:rsplit", _keywords, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 272 | &sep, &maxsplit)) |
| 273 | goto exit; |
| 274 | return_value = bytearray_rsplit_impl(self, sep, maxsplit); |
| 275 | |
| 276 | exit: |
| 277 | return return_value; |
| 278 | } |
| 279 | |
| 280 | PyDoc_STRVAR(bytearray_reverse__doc__, |
| 281 | "reverse($self, /)\n" |
| 282 | "--\n" |
| 283 | "\n" |
| 284 | "Reverse the order of the values in B in place."); |
| 285 | |
| 286 | #define BYTEARRAY_REVERSE_METHODDEF \ |
| 287 | {"reverse", (PyCFunction)bytearray_reverse, METH_NOARGS, bytearray_reverse__doc__}, |
| 288 | |
| 289 | static PyObject * |
| 290 | bytearray_reverse_impl(PyByteArrayObject *self); |
| 291 | |
| 292 | static PyObject * |
| 293 | bytearray_reverse(PyByteArrayObject *self, PyObject *Py_UNUSED(ignored)) |
| 294 | { |
| 295 | return bytearray_reverse_impl(self); |
| 296 | } |
| 297 | |
| 298 | PyDoc_STRVAR(bytearray_insert__doc__, |
| 299 | "insert($self, index, item, /)\n" |
| 300 | "--\n" |
| 301 | "\n" |
| 302 | "Insert a single item into the bytearray before the given index.\n" |
| 303 | "\n" |
| 304 | " index\n" |
| 305 | " The index where the value is to be inserted.\n" |
| 306 | " item\n" |
| 307 | " The item to be inserted."); |
| 308 | |
| 309 | #define BYTEARRAY_INSERT_METHODDEF \ |
| 310 | {"insert", (PyCFunction)bytearray_insert, METH_VARARGS, bytearray_insert__doc__}, |
| 311 | |
| 312 | static PyObject * |
| 313 | bytearray_insert_impl(PyByteArrayObject *self, Py_ssize_t index, int item); |
| 314 | |
| 315 | static PyObject * |
| 316 | bytearray_insert(PyByteArrayObject *self, PyObject *args) |
| 317 | { |
| 318 | PyObject *return_value = NULL; |
| 319 | Py_ssize_t index; |
| 320 | int item; |
| 321 | |
Serhiy Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 322 | if (!PyArg_ParseTuple(args, "nO&:insert", |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 323 | &index, _getbytevalue, &item)) |
| 324 | goto exit; |
| 325 | return_value = bytearray_insert_impl(self, index, item); |
| 326 | |
| 327 | exit: |
| 328 | return return_value; |
| 329 | } |
| 330 | |
| 331 | PyDoc_STRVAR(bytearray_append__doc__, |
| 332 | "append($self, item, /)\n" |
| 333 | "--\n" |
| 334 | "\n" |
| 335 | "Append a single item to the end of the bytearray.\n" |
| 336 | "\n" |
| 337 | " item\n" |
| 338 | " The item to be appended."); |
| 339 | |
| 340 | #define BYTEARRAY_APPEND_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 341 | {"append", (PyCFunction)bytearray_append, METH_O, bytearray_append__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 342 | |
| 343 | static PyObject * |
| 344 | bytearray_append_impl(PyByteArrayObject *self, int item); |
| 345 | |
| 346 | static PyObject * |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 347 | bytearray_append(PyByteArrayObject *self, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 348 | { |
| 349 | PyObject *return_value = NULL; |
| 350 | int item; |
| 351 | |
Serhiy Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 352 | if (!PyArg_Parse(arg, "O&:append", _getbytevalue, &item)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 353 | goto exit; |
| 354 | return_value = bytearray_append_impl(self, item); |
| 355 | |
| 356 | exit: |
| 357 | return return_value; |
| 358 | } |
| 359 | |
| 360 | PyDoc_STRVAR(bytearray_extend__doc__, |
| 361 | "extend($self, iterable_of_ints, /)\n" |
| 362 | "--\n" |
| 363 | "\n" |
| 364 | "Append all the items from the iterator or sequence to the end of the bytearray.\n" |
| 365 | "\n" |
| 366 | " iterable_of_ints\n" |
| 367 | " The iterable of items to append."); |
| 368 | |
| 369 | #define BYTEARRAY_EXTEND_METHODDEF \ |
| 370 | {"extend", (PyCFunction)bytearray_extend, METH_O, bytearray_extend__doc__}, |
| 371 | |
| 372 | PyDoc_STRVAR(bytearray_pop__doc__, |
| 373 | "pop($self, index=-1, /)\n" |
| 374 | "--\n" |
| 375 | "\n" |
| 376 | "Remove and return a single item from B.\n" |
| 377 | "\n" |
| 378 | " index\n" |
| 379 | " The index from where to remove the item.\n" |
| 380 | " -1 (the default value) means remove the last item.\n" |
| 381 | "\n" |
| 382 | "If no index argument is given, will pop the last item."); |
| 383 | |
| 384 | #define BYTEARRAY_POP_METHODDEF \ |
| 385 | {"pop", (PyCFunction)bytearray_pop, METH_VARARGS, bytearray_pop__doc__}, |
| 386 | |
| 387 | static PyObject * |
| 388 | bytearray_pop_impl(PyByteArrayObject *self, Py_ssize_t index); |
| 389 | |
| 390 | static PyObject * |
| 391 | bytearray_pop(PyByteArrayObject *self, PyObject *args) |
| 392 | { |
| 393 | PyObject *return_value = NULL; |
| 394 | Py_ssize_t index = -1; |
| 395 | |
Serhiy Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 396 | if (!PyArg_ParseTuple(args, "|n:pop", |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 397 | &index)) |
| 398 | goto exit; |
| 399 | return_value = bytearray_pop_impl(self, index); |
| 400 | |
| 401 | exit: |
| 402 | return return_value; |
| 403 | } |
| 404 | |
| 405 | PyDoc_STRVAR(bytearray_remove__doc__, |
| 406 | "remove($self, value, /)\n" |
| 407 | "--\n" |
| 408 | "\n" |
| 409 | "Remove the first occurrence of a value in the bytearray.\n" |
| 410 | "\n" |
| 411 | " value\n" |
| 412 | " The value to remove."); |
| 413 | |
| 414 | #define BYTEARRAY_REMOVE_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 415 | {"remove", (PyCFunction)bytearray_remove, METH_O, bytearray_remove__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 416 | |
| 417 | static PyObject * |
| 418 | bytearray_remove_impl(PyByteArrayObject *self, int value); |
| 419 | |
| 420 | static PyObject * |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 421 | bytearray_remove(PyByteArrayObject *self, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 422 | { |
| 423 | PyObject *return_value = NULL; |
| 424 | int value; |
| 425 | |
Serhiy Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 426 | if (!PyArg_Parse(arg, "O&:remove", _getbytevalue, &value)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 427 | goto exit; |
| 428 | return_value = bytearray_remove_impl(self, value); |
| 429 | |
| 430 | exit: |
| 431 | return return_value; |
| 432 | } |
| 433 | |
| 434 | PyDoc_STRVAR(bytearray_strip__doc__, |
| 435 | "strip($self, bytes=None, /)\n" |
| 436 | "--\n" |
| 437 | "\n" |
| 438 | "Strip leading and trailing bytes contained in the argument.\n" |
| 439 | "\n" |
| 440 | "If the argument is omitted or None, strip leading and trailing ASCII whitespace."); |
| 441 | |
| 442 | #define BYTEARRAY_STRIP_METHODDEF \ |
| 443 | {"strip", (PyCFunction)bytearray_strip, METH_VARARGS, bytearray_strip__doc__}, |
| 444 | |
| 445 | static PyObject * |
| 446 | bytearray_strip_impl(PyByteArrayObject *self, PyObject *bytes); |
| 447 | |
| 448 | static PyObject * |
| 449 | bytearray_strip(PyByteArrayObject *self, PyObject *args) |
| 450 | { |
| 451 | PyObject *return_value = NULL; |
| 452 | PyObject *bytes = Py_None; |
| 453 | |
| 454 | if (!PyArg_UnpackTuple(args, "strip", |
| 455 | 0, 1, |
| 456 | &bytes)) |
| 457 | goto exit; |
| 458 | return_value = bytearray_strip_impl(self, bytes); |
| 459 | |
| 460 | exit: |
| 461 | return return_value; |
| 462 | } |
| 463 | |
| 464 | PyDoc_STRVAR(bytearray_lstrip__doc__, |
| 465 | "lstrip($self, bytes=None, /)\n" |
| 466 | "--\n" |
| 467 | "\n" |
| 468 | "Strip leading bytes contained in the argument.\n" |
| 469 | "\n" |
| 470 | "If the argument is omitted or None, strip leading ASCII whitespace."); |
| 471 | |
| 472 | #define BYTEARRAY_LSTRIP_METHODDEF \ |
| 473 | {"lstrip", (PyCFunction)bytearray_lstrip, METH_VARARGS, bytearray_lstrip__doc__}, |
| 474 | |
| 475 | static PyObject * |
| 476 | bytearray_lstrip_impl(PyByteArrayObject *self, PyObject *bytes); |
| 477 | |
| 478 | static PyObject * |
| 479 | bytearray_lstrip(PyByteArrayObject *self, PyObject *args) |
| 480 | { |
| 481 | PyObject *return_value = NULL; |
| 482 | PyObject *bytes = Py_None; |
| 483 | |
| 484 | if (!PyArg_UnpackTuple(args, "lstrip", |
| 485 | 0, 1, |
| 486 | &bytes)) |
| 487 | goto exit; |
| 488 | return_value = bytearray_lstrip_impl(self, bytes); |
| 489 | |
| 490 | exit: |
| 491 | return return_value; |
| 492 | } |
| 493 | |
| 494 | PyDoc_STRVAR(bytearray_rstrip__doc__, |
| 495 | "rstrip($self, bytes=None, /)\n" |
| 496 | "--\n" |
| 497 | "\n" |
| 498 | "Strip trailing bytes contained in the argument.\n" |
| 499 | "\n" |
| 500 | "If the argument is omitted or None, strip trailing ASCII whitespace."); |
| 501 | |
| 502 | #define BYTEARRAY_RSTRIP_METHODDEF \ |
| 503 | {"rstrip", (PyCFunction)bytearray_rstrip, METH_VARARGS, bytearray_rstrip__doc__}, |
| 504 | |
| 505 | static PyObject * |
| 506 | bytearray_rstrip_impl(PyByteArrayObject *self, PyObject *bytes); |
| 507 | |
| 508 | static PyObject * |
| 509 | bytearray_rstrip(PyByteArrayObject *self, PyObject *args) |
| 510 | { |
| 511 | PyObject *return_value = NULL; |
| 512 | PyObject *bytes = Py_None; |
| 513 | |
| 514 | if (!PyArg_UnpackTuple(args, "rstrip", |
| 515 | 0, 1, |
| 516 | &bytes)) |
| 517 | goto exit; |
| 518 | return_value = bytearray_rstrip_impl(self, bytes); |
| 519 | |
| 520 | exit: |
| 521 | return return_value; |
| 522 | } |
| 523 | |
| 524 | PyDoc_STRVAR(bytearray_decode__doc__, |
| 525 | "decode($self, /, encoding=\'utf-8\', errors=\'strict\')\n" |
| 526 | "--\n" |
| 527 | "\n" |
| 528 | "Decode the bytearray using the codec registered for encoding.\n" |
| 529 | "\n" |
| 530 | " encoding\n" |
| 531 | " The encoding with which to decode the bytearray.\n" |
| 532 | " errors\n" |
| 533 | " The error handling scheme to use for the handling of decoding errors.\n" |
| 534 | " The default is \'strict\' meaning that decoding errors raise a\n" |
| 535 | " UnicodeDecodeError. Other possible values are \'ignore\' and \'replace\'\n" |
| 536 | " as well as any other name registered with codecs.register_error that\n" |
| 537 | " can handle UnicodeDecodeErrors."); |
| 538 | |
| 539 | #define BYTEARRAY_DECODE_METHODDEF \ |
| 540 | {"decode", (PyCFunction)bytearray_decode, METH_VARARGS|METH_KEYWORDS, bytearray_decode__doc__}, |
| 541 | |
| 542 | static PyObject * |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 543 | bytearray_decode_impl(PyByteArrayObject *self, const char *encoding, |
| 544 | const char *errors); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 545 | |
| 546 | static PyObject * |
| 547 | bytearray_decode(PyByteArrayObject *self, PyObject *args, PyObject *kwargs) |
| 548 | { |
| 549 | PyObject *return_value = NULL; |
| 550 | static char *_keywords[] = {"encoding", "errors", NULL}; |
| 551 | const char *encoding = NULL; |
| 552 | const char *errors = NULL; |
| 553 | |
Serhiy Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 554 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|ss:decode", _keywords, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 555 | &encoding, &errors)) |
| 556 | goto exit; |
| 557 | return_value = bytearray_decode_impl(self, encoding, errors); |
| 558 | |
| 559 | exit: |
| 560 | return return_value; |
| 561 | } |
| 562 | |
| 563 | PyDoc_STRVAR(bytearray_join__doc__, |
| 564 | "join($self, iterable_of_bytes, /)\n" |
| 565 | "--\n" |
| 566 | "\n" |
| 567 | "Concatenate any number of bytes/bytearray objects.\n" |
| 568 | "\n" |
| 569 | "The bytearray whose method is called is inserted in between each pair.\n" |
| 570 | "\n" |
| 571 | "The result is returned as a new bytearray object."); |
| 572 | |
| 573 | #define BYTEARRAY_JOIN_METHODDEF \ |
| 574 | {"join", (PyCFunction)bytearray_join, METH_O, bytearray_join__doc__}, |
| 575 | |
| 576 | PyDoc_STRVAR(bytearray_splitlines__doc__, |
| 577 | "splitlines($self, /, keepends=False)\n" |
| 578 | "--\n" |
| 579 | "\n" |
| 580 | "Return a list of the lines in the bytearray, breaking at line boundaries.\n" |
| 581 | "\n" |
| 582 | "Line breaks are not included in the resulting list unless keepends is given and\n" |
| 583 | "true."); |
| 584 | |
| 585 | #define BYTEARRAY_SPLITLINES_METHODDEF \ |
| 586 | {"splitlines", (PyCFunction)bytearray_splitlines, METH_VARARGS|METH_KEYWORDS, bytearray_splitlines__doc__}, |
| 587 | |
| 588 | static PyObject * |
| 589 | bytearray_splitlines_impl(PyByteArrayObject *self, int keepends); |
| 590 | |
| 591 | static PyObject * |
| 592 | bytearray_splitlines(PyByteArrayObject *self, PyObject *args, PyObject *kwargs) |
| 593 | { |
| 594 | PyObject *return_value = NULL; |
| 595 | static char *_keywords[] = {"keepends", NULL}; |
| 596 | int keepends = 0; |
| 597 | |
Serhiy Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 598 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|i:splitlines", _keywords, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 599 | &keepends)) |
| 600 | goto exit; |
| 601 | return_value = bytearray_splitlines_impl(self, keepends); |
| 602 | |
| 603 | exit: |
| 604 | return return_value; |
| 605 | } |
| 606 | |
| 607 | PyDoc_STRVAR(bytearray_fromhex__doc__, |
| 608 | "fromhex($type, string, /)\n" |
| 609 | "--\n" |
| 610 | "\n" |
| 611 | "Create a bytearray object from a string of hexadecimal numbers.\n" |
| 612 | "\n" |
| 613 | "Spaces between two numbers are accepted.\n" |
| 614 | "Example: bytearray.fromhex(\'B9 01EF\') -> bytearray(b\'\\\\xb9\\\\x01\\\\xef\')"); |
| 615 | |
| 616 | #define BYTEARRAY_FROMHEX_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 617 | {"fromhex", (PyCFunction)bytearray_fromhex, METH_O|METH_CLASS, bytearray_fromhex__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 618 | |
| 619 | static PyObject * |
| 620 | bytearray_fromhex_impl(PyObject*cls, PyObject *string); |
| 621 | |
| 622 | static PyObject * |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 623 | bytearray_fromhex(PyTypeObject *cls, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 624 | { |
| 625 | PyObject *return_value = NULL; |
| 626 | PyObject *string; |
| 627 | |
Serhiy Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 628 | if (!PyArg_Parse(arg, "U:fromhex", &string)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 629 | goto exit; |
| 630 | return_value = bytearray_fromhex_impl((PyObject*)cls, string); |
| 631 | |
| 632 | exit: |
| 633 | return return_value; |
| 634 | } |
| 635 | |
| 636 | PyDoc_STRVAR(bytearray_reduce__doc__, |
| 637 | "__reduce__($self, /)\n" |
| 638 | "--\n" |
| 639 | "\n" |
| 640 | "Return state information for pickling."); |
| 641 | |
| 642 | #define BYTEARRAY_REDUCE_METHODDEF \ |
| 643 | {"__reduce__", (PyCFunction)bytearray_reduce, METH_NOARGS, bytearray_reduce__doc__}, |
| 644 | |
| 645 | static PyObject * |
| 646 | bytearray_reduce_impl(PyByteArrayObject *self); |
| 647 | |
| 648 | static PyObject * |
| 649 | bytearray_reduce(PyByteArrayObject *self, PyObject *Py_UNUSED(ignored)) |
| 650 | { |
| 651 | return bytearray_reduce_impl(self); |
| 652 | } |
| 653 | |
| 654 | PyDoc_STRVAR(bytearray_reduce_ex__doc__, |
| 655 | "__reduce_ex__($self, proto=0, /)\n" |
| 656 | "--\n" |
| 657 | "\n" |
| 658 | "Return state information for pickling."); |
| 659 | |
| 660 | #define BYTEARRAY_REDUCE_EX_METHODDEF \ |
| 661 | {"__reduce_ex__", (PyCFunction)bytearray_reduce_ex, METH_VARARGS, bytearray_reduce_ex__doc__}, |
| 662 | |
| 663 | static PyObject * |
| 664 | bytearray_reduce_ex_impl(PyByteArrayObject *self, int proto); |
| 665 | |
| 666 | static PyObject * |
| 667 | bytearray_reduce_ex(PyByteArrayObject *self, PyObject *args) |
| 668 | { |
| 669 | PyObject *return_value = NULL; |
| 670 | int proto = 0; |
| 671 | |
Serhiy Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 672 | if (!PyArg_ParseTuple(args, "|i:__reduce_ex__", |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 673 | &proto)) |
| 674 | goto exit; |
| 675 | return_value = bytearray_reduce_ex_impl(self, proto); |
| 676 | |
| 677 | exit: |
| 678 | return return_value; |
| 679 | } |
| 680 | |
| 681 | PyDoc_STRVAR(bytearray_sizeof__doc__, |
| 682 | "__sizeof__($self, /)\n" |
| 683 | "--\n" |
| 684 | "\n" |
| 685 | "Returns the size of the bytearray object in memory, in bytes."); |
| 686 | |
| 687 | #define BYTEARRAY_SIZEOF_METHODDEF \ |
| 688 | {"__sizeof__", (PyCFunction)bytearray_sizeof, METH_NOARGS, bytearray_sizeof__doc__}, |
| 689 | |
| 690 | static PyObject * |
| 691 | bytearray_sizeof_impl(PyByteArrayObject *self); |
| 692 | |
| 693 | static PyObject * |
| 694 | bytearray_sizeof(PyByteArrayObject *self, PyObject *Py_UNUSED(ignored)) |
| 695 | { |
| 696 | return bytearray_sizeof_impl(self); |
| 697 | } |
Serhiy Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 698 | /*[clinic end generated code: output=966c15ff22c5e243 input=a9049054013a1b77]*/ |