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