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