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__, |
Martin Panter | 1b6c6da | 2016-08-27 08:35:02 +0000 | [diff] [blame] | 42 | "translate($self, table, /, delete=b\'\')\n" |
| 43 | "--\n" |
| 44 | "\n" |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 45 | "Return a copy with each character mapped by the given translation table.\n" |
| 46 | "\n" |
| 47 | " table\n" |
| 48 | " Translation table, which must be a bytes object of length 256.\n" |
| 49 | "\n" |
Martin Panter | 1b6c6da | 2016-08-27 08:35:02 +0000 | [diff] [blame] | 50 | "All characters occurring in the optional argument delete are removed.\n" |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 51 | "The remaining characters are mapped through the given translation table."); |
| 52 | |
| 53 | #define BYTEARRAY_TRANSLATE_METHODDEF \ |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 54 | {"translate", (PyCFunction)bytearray_translate, METH_FASTCALL, bytearray_translate__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 55 | |
| 56 | static PyObject * |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 57 | bytearray_translate_impl(PyByteArrayObject *self, PyObject *table, |
Martin Panter | 1b6c6da | 2016-08-27 08:35:02 +0000 | [diff] [blame] | 58 | PyObject *deletechars); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 59 | |
| 60 | static PyObject * |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 61 | bytearray_translate(PyByteArrayObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 62 | { |
| 63 | PyObject *return_value = NULL; |
Martin Panter | 1b6c6da | 2016-08-27 08:35:02 +0000 | [diff] [blame] | 64 | static const char * const _keywords[] = {"", "delete", NULL}; |
| 65 | static _PyArg_Parser _parser = {"O|O:translate", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 66 | PyObject *table; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 67 | PyObject *deletechars = NULL; |
| 68 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 69 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Martin Panter | 1b6c6da | 2016-08-27 08:35:02 +0000 | [diff] [blame] | 70 | &table, &deletechars)) { |
| 71 | goto exit; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 72 | } |
Martin Panter | 1b6c6da | 2016-08-27 08:35:02 +0000 | [diff] [blame] | 73 | return_value = bytearray_translate_impl(self, table, deletechars); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 74 | |
| 75 | exit: |
| 76 | return return_value; |
| 77 | } |
| 78 | |
| 79 | PyDoc_STRVAR(bytearray_maketrans__doc__, |
| 80 | "maketrans(frm, to, /)\n" |
| 81 | "--\n" |
| 82 | "\n" |
| 83 | "Return a translation table useable for the bytes or bytearray translate method.\n" |
| 84 | "\n" |
| 85 | "The returned table will be one where each byte in frm is mapped to the byte at\n" |
| 86 | "the same position in to.\n" |
| 87 | "\n" |
| 88 | "The bytes objects frm and to must be of the same length."); |
| 89 | |
| 90 | #define BYTEARRAY_MAKETRANS_METHODDEF \ |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 91 | {"maketrans", (PyCFunction)bytearray_maketrans, METH_FASTCALL|METH_STATIC, bytearray_maketrans__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 92 | |
| 93 | static PyObject * |
| 94 | bytearray_maketrans_impl(Py_buffer *frm, Py_buffer *to); |
| 95 | |
| 96 | static PyObject * |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 97 | bytearray_maketrans(void *null, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 98 | { |
| 99 | PyObject *return_value = NULL; |
| 100 | Py_buffer frm = {NULL, NULL}; |
| 101 | Py_buffer to = {NULL, NULL}; |
| 102 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame^] | 103 | if (!_PyArg_NoStackKeywords("maketrans", kwnames)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 104 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 105 | } |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 106 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame^] | 107 | if (!_PyArg_ParseStack(args, nargs, "y*y*:maketrans", |
| 108 | &frm, &to)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 109 | goto exit; |
| 110 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 111 | return_value = bytearray_maketrans_impl(&frm, &to); |
| 112 | |
| 113 | exit: |
| 114 | /* Cleanup for frm */ |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 115 | if (frm.obj) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 116 | PyBuffer_Release(&frm); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 117 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 118 | /* Cleanup for to */ |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 119 | if (to.obj) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 120 | PyBuffer_Release(&to); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 121 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 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 \ |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 140 | {"replace", (PyCFunction)bytearray_replace, METH_FASTCALL, bytearray_replace__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 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 * |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 147 | bytearray_replace(PyByteArrayObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 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 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame^] | 154 | if (!_PyArg_NoStackKeywords("replace", kwnames)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 155 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 156 | } |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 157 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame^] | 158 | if (!_PyArg_ParseStack(args, nargs, "y*y*|n:replace", |
| 159 | &old, &new, &count)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 160 | goto exit; |
| 161 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 162 | return_value = bytearray_replace_impl(self, &old, &new, count); |
| 163 | |
| 164 | exit: |
| 165 | /* Cleanup for old */ |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 166 | if (old.obj) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 167 | PyBuffer_Release(&old); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 168 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 169 | /* Cleanup for new */ |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 170 | if (new.obj) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 171 | PyBuffer_Release(&new); |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 172 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 173 | |
| 174 | return return_value; |
| 175 | } |
| 176 | |
| 177 | PyDoc_STRVAR(bytearray_split__doc__, |
| 178 | "split($self, /, sep=None, maxsplit=-1)\n" |
| 179 | "--\n" |
| 180 | "\n" |
| 181 | "Return a list of the sections in the bytearray, using sep as the delimiter.\n" |
| 182 | "\n" |
| 183 | " sep\n" |
| 184 | " The delimiter according which to split the bytearray.\n" |
| 185 | " None (the default value) means split on ASCII whitespace characters\n" |
| 186 | " (space, tab, return, newline, formfeed, vertical tab).\n" |
| 187 | " maxsplit\n" |
| 188 | " Maximum number of splits to do.\n" |
| 189 | " -1 (the default value) means no limit."); |
| 190 | |
| 191 | #define BYTEARRAY_SPLIT_METHODDEF \ |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 192 | {"split", (PyCFunction)bytearray_split, METH_FASTCALL, bytearray_split__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 193 | |
| 194 | static PyObject * |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 195 | bytearray_split_impl(PyByteArrayObject *self, PyObject *sep, |
| 196 | Py_ssize_t maxsplit); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 197 | |
| 198 | static PyObject * |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 199 | bytearray_split(PyByteArrayObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 200 | { |
| 201 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 202 | static const char * const _keywords[] = {"sep", "maxsplit", NULL}; |
| 203 | static _PyArg_Parser _parser = {"|On:split", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 204 | PyObject *sep = Py_None; |
| 205 | Py_ssize_t maxsplit = -1; |
| 206 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 207 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
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 \ |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 266 | {"rsplit", (PyCFunction)bytearray_rsplit, METH_FASTCALL, bytearray_rsplit__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 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 * |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 273 | bytearray_rsplit(PyByteArrayObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 274 | { |
| 275 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 276 | static const char * const _keywords[] = {"sep", "maxsplit", NULL}; |
| 277 | static _PyArg_Parser _parser = {"|On:rsplit", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 278 | PyObject *sep = Py_None; |
| 279 | Py_ssize_t maxsplit = -1; |
| 280 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 281 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 282 | &sep, &maxsplit)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 283 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 284 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 285 | return_value = bytearray_rsplit_impl(self, sep, maxsplit); |
| 286 | |
| 287 | exit: |
| 288 | return return_value; |
| 289 | } |
| 290 | |
| 291 | PyDoc_STRVAR(bytearray_reverse__doc__, |
| 292 | "reverse($self, /)\n" |
| 293 | "--\n" |
| 294 | "\n" |
| 295 | "Reverse the order of the values in B in place."); |
| 296 | |
| 297 | #define BYTEARRAY_REVERSE_METHODDEF \ |
| 298 | {"reverse", (PyCFunction)bytearray_reverse, METH_NOARGS, bytearray_reverse__doc__}, |
| 299 | |
| 300 | static PyObject * |
| 301 | bytearray_reverse_impl(PyByteArrayObject *self); |
| 302 | |
| 303 | static PyObject * |
| 304 | bytearray_reverse(PyByteArrayObject *self, PyObject *Py_UNUSED(ignored)) |
| 305 | { |
| 306 | return bytearray_reverse_impl(self); |
| 307 | } |
| 308 | |
| 309 | PyDoc_STRVAR(bytearray_insert__doc__, |
| 310 | "insert($self, index, item, /)\n" |
| 311 | "--\n" |
| 312 | "\n" |
| 313 | "Insert a single item into the bytearray before the given index.\n" |
| 314 | "\n" |
| 315 | " index\n" |
| 316 | " The index where the value is to be inserted.\n" |
| 317 | " item\n" |
| 318 | " The item to be inserted."); |
| 319 | |
| 320 | #define BYTEARRAY_INSERT_METHODDEF \ |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 321 | {"insert", (PyCFunction)bytearray_insert, METH_FASTCALL, bytearray_insert__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 322 | |
| 323 | static PyObject * |
| 324 | bytearray_insert_impl(PyByteArrayObject *self, Py_ssize_t index, int item); |
| 325 | |
| 326 | static PyObject * |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 327 | bytearray_insert(PyByteArrayObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 328 | { |
| 329 | PyObject *return_value = NULL; |
| 330 | Py_ssize_t index; |
| 331 | int item; |
| 332 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame^] | 333 | if (!_PyArg_NoStackKeywords("insert", kwnames)) { |
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 | } |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 336 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame^] | 337 | if (!_PyArg_ParseStack(args, nargs, "nO&:insert", |
| 338 | &index, _getbytevalue, &item)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 339 | goto exit; |
| 340 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 341 | return_value = bytearray_insert_impl(self, index, item); |
| 342 | |
| 343 | exit: |
| 344 | return return_value; |
| 345 | } |
| 346 | |
| 347 | PyDoc_STRVAR(bytearray_append__doc__, |
| 348 | "append($self, item, /)\n" |
| 349 | "--\n" |
| 350 | "\n" |
| 351 | "Append a single item to the end of the bytearray.\n" |
| 352 | "\n" |
| 353 | " item\n" |
| 354 | " The item to be appended."); |
| 355 | |
| 356 | #define BYTEARRAY_APPEND_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 357 | {"append", (PyCFunction)bytearray_append, METH_O, bytearray_append__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 358 | |
| 359 | static PyObject * |
| 360 | bytearray_append_impl(PyByteArrayObject *self, int item); |
| 361 | |
| 362 | static PyObject * |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 363 | bytearray_append(PyByteArrayObject *self, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 364 | { |
| 365 | PyObject *return_value = NULL; |
| 366 | int item; |
| 367 | |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 368 | if (!PyArg_Parse(arg, "O&:append", _getbytevalue, &item)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 369 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 370 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 371 | return_value = bytearray_append_impl(self, item); |
| 372 | |
| 373 | exit: |
| 374 | return return_value; |
| 375 | } |
| 376 | |
| 377 | PyDoc_STRVAR(bytearray_extend__doc__, |
| 378 | "extend($self, iterable_of_ints, /)\n" |
| 379 | "--\n" |
| 380 | "\n" |
| 381 | "Append all the items from the iterator or sequence to the end of the bytearray.\n" |
| 382 | "\n" |
| 383 | " iterable_of_ints\n" |
| 384 | " The iterable of items to append."); |
| 385 | |
| 386 | #define BYTEARRAY_EXTEND_METHODDEF \ |
| 387 | {"extend", (PyCFunction)bytearray_extend, METH_O, bytearray_extend__doc__}, |
| 388 | |
| 389 | PyDoc_STRVAR(bytearray_pop__doc__, |
| 390 | "pop($self, index=-1, /)\n" |
| 391 | "--\n" |
| 392 | "\n" |
| 393 | "Remove and return a single item from B.\n" |
| 394 | "\n" |
| 395 | " index\n" |
| 396 | " The index from where to remove the item.\n" |
| 397 | " -1 (the default value) means remove the last item.\n" |
| 398 | "\n" |
| 399 | "If no index argument is given, will pop the last item."); |
| 400 | |
| 401 | #define BYTEARRAY_POP_METHODDEF \ |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 402 | {"pop", (PyCFunction)bytearray_pop, METH_FASTCALL, bytearray_pop__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 403 | |
| 404 | static PyObject * |
| 405 | bytearray_pop_impl(PyByteArrayObject *self, Py_ssize_t index); |
| 406 | |
| 407 | static PyObject * |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 408 | bytearray_pop(PyByteArrayObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 409 | { |
| 410 | PyObject *return_value = NULL; |
| 411 | Py_ssize_t index = -1; |
| 412 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame^] | 413 | if (!_PyArg_NoStackKeywords("pop", kwnames)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 414 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 415 | } |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 416 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame^] | 417 | if (!_PyArg_ParseStack(args, nargs, "|n:pop", |
| 418 | &index)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 419 | goto exit; |
| 420 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 421 | return_value = bytearray_pop_impl(self, index); |
| 422 | |
| 423 | exit: |
| 424 | return return_value; |
| 425 | } |
| 426 | |
| 427 | PyDoc_STRVAR(bytearray_remove__doc__, |
| 428 | "remove($self, value, /)\n" |
| 429 | "--\n" |
| 430 | "\n" |
| 431 | "Remove the first occurrence of a value in the bytearray.\n" |
| 432 | "\n" |
| 433 | " value\n" |
| 434 | " The value to remove."); |
| 435 | |
| 436 | #define BYTEARRAY_REMOVE_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 437 | {"remove", (PyCFunction)bytearray_remove, METH_O, bytearray_remove__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 438 | |
| 439 | static PyObject * |
| 440 | bytearray_remove_impl(PyByteArrayObject *self, int value); |
| 441 | |
| 442 | static PyObject * |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 443 | bytearray_remove(PyByteArrayObject *self, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 444 | { |
| 445 | PyObject *return_value = NULL; |
| 446 | int value; |
| 447 | |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 448 | if (!PyArg_Parse(arg, "O&:remove", _getbytevalue, &value)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 449 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 450 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 451 | return_value = bytearray_remove_impl(self, value); |
| 452 | |
| 453 | exit: |
| 454 | return return_value; |
| 455 | } |
| 456 | |
| 457 | PyDoc_STRVAR(bytearray_strip__doc__, |
| 458 | "strip($self, bytes=None, /)\n" |
| 459 | "--\n" |
| 460 | "\n" |
| 461 | "Strip leading and trailing bytes contained in the argument.\n" |
| 462 | "\n" |
| 463 | "If the argument is omitted or None, strip leading and trailing ASCII whitespace."); |
| 464 | |
| 465 | #define BYTEARRAY_STRIP_METHODDEF \ |
Victor Stinner | 0c4a828 | 2017-01-17 02:21:47 +0100 | [diff] [blame] | 466 | {"strip", (PyCFunction)bytearray_strip, METH_FASTCALL, bytearray_strip__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 467 | |
| 468 | static PyObject * |
| 469 | bytearray_strip_impl(PyByteArrayObject *self, PyObject *bytes); |
| 470 | |
| 471 | static PyObject * |
Victor Stinner | 0c4a828 | 2017-01-17 02:21:47 +0100 | [diff] [blame] | 472 | bytearray_strip(PyByteArrayObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 473 | { |
| 474 | PyObject *return_value = NULL; |
| 475 | PyObject *bytes = Py_None; |
| 476 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame^] | 477 | if (!_PyArg_NoStackKeywords("strip", kwnames)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 478 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 479 | } |
Victor Stinner | 0c4a828 | 2017-01-17 02:21:47 +0100 | [diff] [blame] | 480 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame^] | 481 | if (!_PyArg_UnpackStack(args, nargs, "strip", |
| 482 | 0, 1, |
| 483 | &bytes)) { |
Victor Stinner | 0c4a828 | 2017-01-17 02:21:47 +0100 | [diff] [blame] | 484 | goto exit; |
| 485 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 486 | return_value = bytearray_strip_impl(self, bytes); |
| 487 | |
| 488 | exit: |
| 489 | return return_value; |
| 490 | } |
| 491 | |
| 492 | PyDoc_STRVAR(bytearray_lstrip__doc__, |
| 493 | "lstrip($self, bytes=None, /)\n" |
| 494 | "--\n" |
| 495 | "\n" |
| 496 | "Strip leading bytes contained in the argument.\n" |
| 497 | "\n" |
| 498 | "If the argument is omitted or None, strip leading ASCII whitespace."); |
| 499 | |
| 500 | #define BYTEARRAY_LSTRIP_METHODDEF \ |
Victor Stinner | 0c4a828 | 2017-01-17 02:21:47 +0100 | [diff] [blame] | 501 | {"lstrip", (PyCFunction)bytearray_lstrip, METH_FASTCALL, bytearray_lstrip__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 502 | |
| 503 | static PyObject * |
| 504 | bytearray_lstrip_impl(PyByteArrayObject *self, PyObject *bytes); |
| 505 | |
| 506 | static PyObject * |
Victor Stinner | 0c4a828 | 2017-01-17 02:21:47 +0100 | [diff] [blame] | 507 | bytearray_lstrip(PyByteArrayObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 508 | { |
| 509 | PyObject *return_value = NULL; |
| 510 | PyObject *bytes = Py_None; |
| 511 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame^] | 512 | if (!_PyArg_NoStackKeywords("lstrip", kwnames)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 513 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 514 | } |
Victor Stinner | 0c4a828 | 2017-01-17 02:21:47 +0100 | [diff] [blame] | 515 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame^] | 516 | if (!_PyArg_UnpackStack(args, nargs, "lstrip", |
| 517 | 0, 1, |
| 518 | &bytes)) { |
Victor Stinner | 0c4a828 | 2017-01-17 02:21:47 +0100 | [diff] [blame] | 519 | goto exit; |
| 520 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 521 | return_value = bytearray_lstrip_impl(self, bytes); |
| 522 | |
| 523 | exit: |
| 524 | return return_value; |
| 525 | } |
| 526 | |
| 527 | PyDoc_STRVAR(bytearray_rstrip__doc__, |
| 528 | "rstrip($self, bytes=None, /)\n" |
| 529 | "--\n" |
| 530 | "\n" |
| 531 | "Strip trailing bytes contained in the argument.\n" |
| 532 | "\n" |
| 533 | "If the argument is omitted or None, strip trailing ASCII whitespace."); |
| 534 | |
| 535 | #define BYTEARRAY_RSTRIP_METHODDEF \ |
Victor Stinner | 0c4a828 | 2017-01-17 02:21:47 +0100 | [diff] [blame] | 536 | {"rstrip", (PyCFunction)bytearray_rstrip, METH_FASTCALL, bytearray_rstrip__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 537 | |
| 538 | static PyObject * |
| 539 | bytearray_rstrip_impl(PyByteArrayObject *self, PyObject *bytes); |
| 540 | |
| 541 | static PyObject * |
Victor Stinner | 0c4a828 | 2017-01-17 02:21:47 +0100 | [diff] [blame] | 542 | bytearray_rstrip(PyByteArrayObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 543 | { |
| 544 | PyObject *return_value = NULL; |
| 545 | PyObject *bytes = Py_None; |
| 546 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame^] | 547 | if (!_PyArg_NoStackKeywords("rstrip", kwnames)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 548 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 549 | } |
Victor Stinner | 0c4a828 | 2017-01-17 02:21:47 +0100 | [diff] [blame] | 550 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame^] | 551 | if (!_PyArg_UnpackStack(args, nargs, "rstrip", |
| 552 | 0, 1, |
| 553 | &bytes)) { |
Victor Stinner | 0c4a828 | 2017-01-17 02:21:47 +0100 | [diff] [blame] | 554 | goto exit; |
| 555 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 556 | return_value = bytearray_rstrip_impl(self, bytes); |
| 557 | |
| 558 | exit: |
| 559 | return return_value; |
| 560 | } |
| 561 | |
| 562 | PyDoc_STRVAR(bytearray_decode__doc__, |
| 563 | "decode($self, /, encoding=\'utf-8\', errors=\'strict\')\n" |
| 564 | "--\n" |
| 565 | "\n" |
| 566 | "Decode the bytearray using the codec registered for encoding.\n" |
| 567 | "\n" |
| 568 | " encoding\n" |
| 569 | " The encoding with which to decode the bytearray.\n" |
| 570 | " errors\n" |
| 571 | " The error handling scheme to use for the handling of decoding errors.\n" |
| 572 | " The default is \'strict\' meaning that decoding errors raise a\n" |
| 573 | " UnicodeDecodeError. Other possible values are \'ignore\' and \'replace\'\n" |
| 574 | " as well as any other name registered with codecs.register_error that\n" |
| 575 | " can handle UnicodeDecodeErrors."); |
| 576 | |
| 577 | #define BYTEARRAY_DECODE_METHODDEF \ |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 578 | {"decode", (PyCFunction)bytearray_decode, METH_FASTCALL, bytearray_decode__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 579 | |
| 580 | static PyObject * |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 581 | bytearray_decode_impl(PyByteArrayObject *self, const char *encoding, |
| 582 | const char *errors); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 583 | |
| 584 | static PyObject * |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 585 | bytearray_decode(PyByteArrayObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 586 | { |
| 587 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 588 | static const char * const _keywords[] = {"encoding", "errors", NULL}; |
| 589 | static _PyArg_Parser _parser = {"|ss:decode", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 590 | const char *encoding = NULL; |
| 591 | const char *errors = NULL; |
| 592 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 593 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 594 | &encoding, &errors)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 595 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 596 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 597 | return_value = bytearray_decode_impl(self, encoding, errors); |
| 598 | |
| 599 | exit: |
| 600 | return return_value; |
| 601 | } |
| 602 | |
| 603 | PyDoc_STRVAR(bytearray_join__doc__, |
| 604 | "join($self, iterable_of_bytes, /)\n" |
| 605 | "--\n" |
| 606 | "\n" |
| 607 | "Concatenate any number of bytes/bytearray objects.\n" |
| 608 | "\n" |
| 609 | "The bytearray whose method is called is inserted in between each pair.\n" |
| 610 | "\n" |
| 611 | "The result is returned as a new bytearray object."); |
| 612 | |
| 613 | #define BYTEARRAY_JOIN_METHODDEF \ |
| 614 | {"join", (PyCFunction)bytearray_join, METH_O, bytearray_join__doc__}, |
| 615 | |
| 616 | PyDoc_STRVAR(bytearray_splitlines__doc__, |
| 617 | "splitlines($self, /, keepends=False)\n" |
| 618 | "--\n" |
| 619 | "\n" |
| 620 | "Return a list of the lines in the bytearray, breaking at line boundaries.\n" |
| 621 | "\n" |
| 622 | "Line breaks are not included in the resulting list unless keepends is given and\n" |
| 623 | "true."); |
| 624 | |
| 625 | #define BYTEARRAY_SPLITLINES_METHODDEF \ |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 626 | {"splitlines", (PyCFunction)bytearray_splitlines, METH_FASTCALL, bytearray_splitlines__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 627 | |
| 628 | static PyObject * |
| 629 | bytearray_splitlines_impl(PyByteArrayObject *self, int keepends); |
| 630 | |
| 631 | static PyObject * |
Victor Stinner | 37e4ef7 | 2016-09-09 20:00:13 -0700 | [diff] [blame] | 632 | bytearray_splitlines(PyByteArrayObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 633 | { |
| 634 | PyObject *return_value = NULL; |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 635 | static const char * const _keywords[] = {"keepends", NULL}; |
| 636 | static _PyArg_Parser _parser = {"|i:splitlines", _keywords, 0}; |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 637 | int keepends = 0; |
| 638 | |
Victor Stinner | 3e1fad6 | 2017-01-17 01:29:01 +0100 | [diff] [blame] | 639 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 640 | &keepends)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 641 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 642 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 643 | return_value = bytearray_splitlines_impl(self, keepends); |
| 644 | |
| 645 | exit: |
| 646 | return return_value; |
| 647 | } |
| 648 | |
| 649 | PyDoc_STRVAR(bytearray_fromhex__doc__, |
| 650 | "fromhex($type, string, /)\n" |
| 651 | "--\n" |
| 652 | "\n" |
| 653 | "Create a bytearray object from a string of hexadecimal numbers.\n" |
| 654 | "\n" |
| 655 | "Spaces between two numbers are accepted.\n" |
| 656 | "Example: bytearray.fromhex(\'B9 01EF\') -> bytearray(b\'\\\\xb9\\\\x01\\\\xef\')"); |
| 657 | |
| 658 | #define BYTEARRAY_FROMHEX_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 659 | {"fromhex", (PyCFunction)bytearray_fromhex, METH_O|METH_CLASS, bytearray_fromhex__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 660 | |
| 661 | static PyObject * |
Serhiy Storchaka | 0855e70 | 2016-07-01 17:22:31 +0300 | [diff] [blame] | 662 | bytearray_fromhex_impl(PyTypeObject *type, PyObject *string); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 663 | |
| 664 | static PyObject * |
Serhiy Storchaka | 0855e70 | 2016-07-01 17:22:31 +0300 | [diff] [blame] | 665 | bytearray_fromhex(PyTypeObject *type, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 666 | { |
| 667 | PyObject *return_value = NULL; |
| 668 | PyObject *string; |
| 669 | |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 670 | if (!PyArg_Parse(arg, "U:fromhex", &string)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 671 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 672 | } |
Serhiy Storchaka | 0855e70 | 2016-07-01 17:22:31 +0300 | [diff] [blame] | 673 | return_value = bytearray_fromhex_impl(type, string); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 674 | |
| 675 | exit: |
| 676 | return return_value; |
| 677 | } |
| 678 | |
| 679 | PyDoc_STRVAR(bytearray_reduce__doc__, |
| 680 | "__reduce__($self, /)\n" |
| 681 | "--\n" |
| 682 | "\n" |
| 683 | "Return state information for pickling."); |
| 684 | |
| 685 | #define BYTEARRAY_REDUCE_METHODDEF \ |
| 686 | {"__reduce__", (PyCFunction)bytearray_reduce, METH_NOARGS, bytearray_reduce__doc__}, |
| 687 | |
| 688 | static PyObject * |
| 689 | bytearray_reduce_impl(PyByteArrayObject *self); |
| 690 | |
| 691 | static PyObject * |
| 692 | bytearray_reduce(PyByteArrayObject *self, PyObject *Py_UNUSED(ignored)) |
| 693 | { |
| 694 | return bytearray_reduce_impl(self); |
| 695 | } |
| 696 | |
| 697 | PyDoc_STRVAR(bytearray_reduce_ex__doc__, |
| 698 | "__reduce_ex__($self, proto=0, /)\n" |
| 699 | "--\n" |
| 700 | "\n" |
| 701 | "Return state information for pickling."); |
| 702 | |
| 703 | #define BYTEARRAY_REDUCE_EX_METHODDEF \ |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 704 | {"__reduce_ex__", (PyCFunction)bytearray_reduce_ex, METH_FASTCALL, bytearray_reduce_ex__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 705 | |
| 706 | static PyObject * |
| 707 | bytearray_reduce_ex_impl(PyByteArrayObject *self, int proto); |
| 708 | |
| 709 | static PyObject * |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 710 | bytearray_reduce_ex(PyByteArrayObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 711 | { |
| 712 | PyObject *return_value = NULL; |
| 713 | int proto = 0; |
| 714 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame^] | 715 | if (!_PyArg_NoStackKeywords("__reduce_ex__", kwnames)) { |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 716 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 717 | } |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 718 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame^] | 719 | if (!_PyArg_ParseStack(args, nargs, "|i:__reduce_ex__", |
| 720 | &proto)) { |
Victor Stinner | 259f0e4 | 2017-01-17 01:35:17 +0100 | [diff] [blame] | 721 | goto exit; |
| 722 | } |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 723 | return_value = bytearray_reduce_ex_impl(self, proto); |
| 724 | |
| 725 | exit: |
| 726 | return return_value; |
| 727 | } |
| 728 | |
| 729 | PyDoc_STRVAR(bytearray_sizeof__doc__, |
| 730 | "__sizeof__($self, /)\n" |
| 731 | "--\n" |
| 732 | "\n" |
| 733 | "Returns the size of the bytearray object in memory, in bytes."); |
| 734 | |
| 735 | #define BYTEARRAY_SIZEOF_METHODDEF \ |
| 736 | {"__sizeof__", (PyCFunction)bytearray_sizeof, METH_NOARGS, bytearray_sizeof__doc__}, |
| 737 | |
| 738 | static PyObject * |
| 739 | bytearray_sizeof_impl(PyByteArrayObject *self); |
| 740 | |
| 741 | static PyObject * |
| 742 | bytearray_sizeof(PyByteArrayObject *self, PyObject *Py_UNUSED(ignored)) |
| 743 | { |
| 744 | return bytearray_sizeof_impl(self); |
| 745 | } |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame^] | 746 | /*[clinic end generated code: output=f0079d8ee82614f7 input=a9049054013a1b77]*/ |