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