blob: 3e39e9a7bd13318591dd4d55b2e56d77210d0795 [file] [log] [blame]
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001/*[clinic input]
2preserve
3[clinic start generated code]*/
4
5PyDoc_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
14static PyObject *
15bytearray_clear_impl(PyByteArrayObject *self);
16
17static PyObject *
18bytearray_clear(PyByteArrayObject *self, PyObject *Py_UNUSED(ignored))
19{
20 return bytearray_clear_impl(self);
21}
22
23PyDoc_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
32static PyObject *
33bytearray_copy_impl(PyByteArrayObject *self);
34
35static PyObject *
36bytearray_copy(PyByteArrayObject *self, PyObject *Py_UNUSED(ignored))
37{
38 return bytearray_copy_impl(self);
39}
40
41PyDoc_STRVAR(bytearray_translate__doc__,
Martin Panter1b6c6da2016-08-27 08:35:02 +000042"translate($self, table, /, delete=b\'\')\n"
43"--\n"
44"\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030045"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 Panter1b6c6da2016-08-27 08:35:02 +000050"All characters occurring in the optional argument delete are removed.\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030051"The remaining characters are mapped through the given translation table.");
52
53#define BYTEARRAY_TRANSLATE_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -070054 {"translate", (PyCFunction)bytearray_translate, METH_FASTCALL, bytearray_translate__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030055
56static PyObject *
Larry Hastings89964c42015-04-14 18:07:59 -040057bytearray_translate_impl(PyByteArrayObject *self, PyObject *table,
Martin Panter1b6c6da2016-08-27 08:35:02 +000058 PyObject *deletechars);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030059
60static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -070061bytearray_translate(PyByteArrayObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030062{
63 PyObject *return_value = NULL;
Martin Panter1b6c6da2016-08-27 08:35:02 +000064 static const char * const _keywords[] = {"", "delete", NULL};
65 static _PyArg_Parser _parser = {"O|O:translate", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030066 PyObject *table;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030067 PyObject *deletechars = NULL;
68
Victor Stinner3e1fad62017-01-17 01:29:01 +010069 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Martin Panter1b6c6da2016-08-27 08:35:02 +000070 &table, &deletechars)) {
71 goto exit;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030072 }
Martin Panter1b6c6da2016-08-27 08:35:02 +000073 return_value = bytearray_translate_impl(self, table, deletechars);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030074
75exit:
76 return return_value;
77}
78
79PyDoc_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 Stinner259f0e42017-01-17 01:35:17 +010091 {"maketrans", (PyCFunction)bytearray_maketrans, METH_FASTCALL|METH_STATIC, bytearray_maketrans__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030092
93static PyObject *
94bytearray_maketrans_impl(Py_buffer *frm, Py_buffer *to);
95
96static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +010097bytearray_maketrans(void *null, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030098{
99 PyObject *return_value = NULL;
100 Py_buffer frm = {NULL, NULL};
101 Py_buffer to = {NULL, NULL};
102
Victor Stinner259f0e42017-01-17 01:35:17 +0100103 if (!_PyArg_ParseStack(args, nargs, "y*y*:maketrans",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300104 &frm, &to)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300105 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300106 }
Victor Stinner259f0e42017-01-17 01:35:17 +0100107
108 if (!_PyArg_NoStackKeywords("maketrans", kwnames)) {
109 goto exit;
110 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300111 return_value = bytearray_maketrans_impl(&frm, &to);
112
113exit:
114 /* Cleanup for frm */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300115 if (frm.obj) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300116 PyBuffer_Release(&frm);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300117 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300118 /* Cleanup for to */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300119 if (to.obj) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300120 PyBuffer_Release(&to);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300121 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300122
123 return return_value;
124}
125
126PyDoc_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 Stinner259f0e42017-01-17 01:35:17 +0100140 {"replace", (PyCFunction)bytearray_replace, METH_FASTCALL, bytearray_replace__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300141
142static PyObject *
Larry Hastings89964c42015-04-14 18:07:59 -0400143bytearray_replace_impl(PyByteArrayObject *self, Py_buffer *old,
144 Py_buffer *new, Py_ssize_t count);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300145
146static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +0100147bytearray_replace(PyByteArrayObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300148{
149 PyObject *return_value = NULL;
150 Py_buffer old = {NULL, NULL};
151 Py_buffer new = {NULL, NULL};
152 Py_ssize_t count = -1;
153
Victor Stinner259f0e42017-01-17 01:35:17 +0100154 if (!_PyArg_ParseStack(args, nargs, "y*y*|n:replace",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300155 &old, &new, &count)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300156 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300157 }
Victor Stinner259f0e42017-01-17 01:35:17 +0100158
159 if (!_PyArg_NoStackKeywords("replace", kwnames)) {
160 goto exit;
161 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300162 return_value = bytearray_replace_impl(self, &old, &new, count);
163
164exit:
165 /* Cleanup for old */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300166 if (old.obj) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300167 PyBuffer_Release(&old);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300168 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300169 /* Cleanup for new */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300170 if (new.obj) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300171 PyBuffer_Release(&new);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300172 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300173
174 return return_value;
175}
176
177PyDoc_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 Stinner37e4ef72016-09-09 20:00:13 -0700192 {"split", (PyCFunction)bytearray_split, METH_FASTCALL, bytearray_split__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300193
194static PyObject *
Larry Hastings89964c42015-04-14 18:07:59 -0400195bytearray_split_impl(PyByteArrayObject *self, PyObject *sep,
196 Py_ssize_t maxsplit);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300197
198static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700199bytearray_split(PyByteArrayObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300200{
201 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300202 static const char * const _keywords[] = {"sep", "maxsplit", NULL};
203 static _PyArg_Parser _parser = {"|On:split", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300204 PyObject *sep = Py_None;
205 Py_ssize_t maxsplit = -1;
206
Victor Stinner3e1fad62017-01-17 01:29:01 +0100207 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300208 &sep, &maxsplit)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300209 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300210 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300211 return_value = bytearray_split_impl(self, sep, maxsplit);
212
213exit:
214 return return_value;
215}
216
217PyDoc_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
233PyDoc_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
249PyDoc_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 Stinner37e4ef72016-09-09 20:00:13 -0700266 {"rsplit", (PyCFunction)bytearray_rsplit, METH_FASTCALL, bytearray_rsplit__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300267
268static PyObject *
Larry Hastings89964c42015-04-14 18:07:59 -0400269bytearray_rsplit_impl(PyByteArrayObject *self, PyObject *sep,
270 Py_ssize_t maxsplit);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300271
272static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700273bytearray_rsplit(PyByteArrayObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300274{
275 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300276 static const char * const _keywords[] = {"sep", "maxsplit", NULL};
277 static _PyArg_Parser _parser = {"|On:rsplit", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300278 PyObject *sep = Py_None;
279 Py_ssize_t maxsplit = -1;
280
Victor Stinner3e1fad62017-01-17 01:29:01 +0100281 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300282 &sep, &maxsplit)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300283 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300284 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300285 return_value = bytearray_rsplit_impl(self, sep, maxsplit);
286
287exit:
288 return return_value;
289}
290
291PyDoc_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
300static PyObject *
301bytearray_reverse_impl(PyByteArrayObject *self);
302
303static PyObject *
304bytearray_reverse(PyByteArrayObject *self, PyObject *Py_UNUSED(ignored))
305{
306 return bytearray_reverse_impl(self);
307}
308
309PyDoc_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 Stinner259f0e42017-01-17 01:35:17 +0100321 {"insert", (PyCFunction)bytearray_insert, METH_FASTCALL, bytearray_insert__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300322
323static PyObject *
324bytearray_insert_impl(PyByteArrayObject *self, Py_ssize_t index, int item);
325
326static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +0100327bytearray_insert(PyByteArrayObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300328{
329 PyObject *return_value = NULL;
330 Py_ssize_t index;
331 int item;
332
Victor Stinner259f0e42017-01-17 01:35:17 +0100333 if (!_PyArg_ParseStack(args, nargs, "nO&:insert",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300334 &index, _getbytevalue, &item)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300335 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300336 }
Victor Stinner259f0e42017-01-17 01:35:17 +0100337
338 if (!_PyArg_NoStackKeywords("insert", kwnames)) {
339 goto exit;
340 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300341 return_value = bytearray_insert_impl(self, index, item);
342
343exit:
344 return return_value;
345}
346
347PyDoc_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 Storchaka92e8af62015-04-04 00:12:11 +0300357 {"append", (PyCFunction)bytearray_append, METH_O, bytearray_append__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300358
359static PyObject *
360bytearray_append_impl(PyByteArrayObject *self, int item);
361
362static PyObject *
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300363bytearray_append(PyByteArrayObject *self, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300364{
365 PyObject *return_value = NULL;
366 int item;
367
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300368 if (!PyArg_Parse(arg, "O&:append", _getbytevalue, &item)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300369 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300370 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300371 return_value = bytearray_append_impl(self, item);
372
373exit:
374 return return_value;
375}
376
377PyDoc_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
389PyDoc_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 Stinner259f0e42017-01-17 01:35:17 +0100402 {"pop", (PyCFunction)bytearray_pop, METH_FASTCALL, bytearray_pop__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300403
404static PyObject *
405bytearray_pop_impl(PyByteArrayObject *self, Py_ssize_t index);
406
407static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +0100408bytearray_pop(PyByteArrayObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300409{
410 PyObject *return_value = NULL;
411 Py_ssize_t index = -1;
412
Victor Stinner259f0e42017-01-17 01:35:17 +0100413 if (!_PyArg_ParseStack(args, nargs, "|n:pop",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300414 &index)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300415 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300416 }
Victor Stinner259f0e42017-01-17 01:35:17 +0100417
418 if (!_PyArg_NoStackKeywords("pop", kwnames)) {
419 goto exit;
420 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300421 return_value = bytearray_pop_impl(self, index);
422
423exit:
424 return return_value;
425}
426
427PyDoc_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 Storchaka92e8af62015-04-04 00:12:11 +0300437 {"remove", (PyCFunction)bytearray_remove, METH_O, bytearray_remove__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300438
439static PyObject *
440bytearray_remove_impl(PyByteArrayObject *self, int value);
441
442static PyObject *
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300443bytearray_remove(PyByteArrayObject *self, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300444{
445 PyObject *return_value = NULL;
446 int value;
447
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300448 if (!PyArg_Parse(arg, "O&:remove", _getbytevalue, &value)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300449 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300450 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300451 return_value = bytearray_remove_impl(self, value);
452
453exit:
454 return return_value;
455}
456
457PyDoc_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 \
466 {"strip", (PyCFunction)bytearray_strip, METH_VARARGS, bytearray_strip__doc__},
467
468static PyObject *
469bytearray_strip_impl(PyByteArrayObject *self, PyObject *bytes);
470
471static PyObject *
472bytearray_strip(PyByteArrayObject *self, PyObject *args)
473{
474 PyObject *return_value = NULL;
475 PyObject *bytes = Py_None;
476
477 if (!PyArg_UnpackTuple(args, "strip",
478 0, 1,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300479 &bytes)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300480 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300481 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300482 return_value = bytearray_strip_impl(self, bytes);
483
484exit:
485 return return_value;
486}
487
488PyDoc_STRVAR(bytearray_lstrip__doc__,
489"lstrip($self, bytes=None, /)\n"
490"--\n"
491"\n"
492"Strip leading bytes contained in the argument.\n"
493"\n"
494"If the argument is omitted or None, strip leading ASCII whitespace.");
495
496#define BYTEARRAY_LSTRIP_METHODDEF \
497 {"lstrip", (PyCFunction)bytearray_lstrip, METH_VARARGS, bytearray_lstrip__doc__},
498
499static PyObject *
500bytearray_lstrip_impl(PyByteArrayObject *self, PyObject *bytes);
501
502static PyObject *
503bytearray_lstrip(PyByteArrayObject *self, PyObject *args)
504{
505 PyObject *return_value = NULL;
506 PyObject *bytes = Py_None;
507
508 if (!PyArg_UnpackTuple(args, "lstrip",
509 0, 1,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300510 &bytes)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300511 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300512 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300513 return_value = bytearray_lstrip_impl(self, bytes);
514
515exit:
516 return return_value;
517}
518
519PyDoc_STRVAR(bytearray_rstrip__doc__,
520"rstrip($self, bytes=None, /)\n"
521"--\n"
522"\n"
523"Strip trailing bytes contained in the argument.\n"
524"\n"
525"If the argument is omitted or None, strip trailing ASCII whitespace.");
526
527#define BYTEARRAY_RSTRIP_METHODDEF \
528 {"rstrip", (PyCFunction)bytearray_rstrip, METH_VARARGS, bytearray_rstrip__doc__},
529
530static PyObject *
531bytearray_rstrip_impl(PyByteArrayObject *self, PyObject *bytes);
532
533static PyObject *
534bytearray_rstrip(PyByteArrayObject *self, PyObject *args)
535{
536 PyObject *return_value = NULL;
537 PyObject *bytes = Py_None;
538
539 if (!PyArg_UnpackTuple(args, "rstrip",
540 0, 1,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300541 &bytes)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300542 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300543 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300544 return_value = bytearray_rstrip_impl(self, bytes);
545
546exit:
547 return return_value;
548}
549
550PyDoc_STRVAR(bytearray_decode__doc__,
551"decode($self, /, encoding=\'utf-8\', errors=\'strict\')\n"
552"--\n"
553"\n"
554"Decode the bytearray using the codec registered for encoding.\n"
555"\n"
556" encoding\n"
557" The encoding with which to decode the bytearray.\n"
558" errors\n"
559" The error handling scheme to use for the handling of decoding errors.\n"
560" The default is \'strict\' meaning that decoding errors raise a\n"
561" UnicodeDecodeError. Other possible values are \'ignore\' and \'replace\'\n"
562" as well as any other name registered with codecs.register_error that\n"
563" can handle UnicodeDecodeErrors.");
564
565#define BYTEARRAY_DECODE_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -0700566 {"decode", (PyCFunction)bytearray_decode, METH_FASTCALL, bytearray_decode__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300567
568static PyObject *
Larry Hastings89964c42015-04-14 18:07:59 -0400569bytearray_decode_impl(PyByteArrayObject *self, const char *encoding,
570 const char *errors);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300571
572static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700573bytearray_decode(PyByteArrayObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300574{
575 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300576 static const char * const _keywords[] = {"encoding", "errors", NULL};
577 static _PyArg_Parser _parser = {"|ss:decode", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300578 const char *encoding = NULL;
579 const char *errors = NULL;
580
Victor Stinner3e1fad62017-01-17 01:29:01 +0100581 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300582 &encoding, &errors)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300583 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300584 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300585 return_value = bytearray_decode_impl(self, encoding, errors);
586
587exit:
588 return return_value;
589}
590
591PyDoc_STRVAR(bytearray_join__doc__,
592"join($self, iterable_of_bytes, /)\n"
593"--\n"
594"\n"
595"Concatenate any number of bytes/bytearray objects.\n"
596"\n"
597"The bytearray whose method is called is inserted in between each pair.\n"
598"\n"
599"The result is returned as a new bytearray object.");
600
601#define BYTEARRAY_JOIN_METHODDEF \
602 {"join", (PyCFunction)bytearray_join, METH_O, bytearray_join__doc__},
603
604PyDoc_STRVAR(bytearray_splitlines__doc__,
605"splitlines($self, /, keepends=False)\n"
606"--\n"
607"\n"
608"Return a list of the lines in the bytearray, breaking at line boundaries.\n"
609"\n"
610"Line breaks are not included in the resulting list unless keepends is given and\n"
611"true.");
612
613#define BYTEARRAY_SPLITLINES_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -0700614 {"splitlines", (PyCFunction)bytearray_splitlines, METH_FASTCALL, bytearray_splitlines__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300615
616static PyObject *
617bytearray_splitlines_impl(PyByteArrayObject *self, int keepends);
618
619static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700620bytearray_splitlines(PyByteArrayObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300621{
622 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300623 static const char * const _keywords[] = {"keepends", NULL};
624 static _PyArg_Parser _parser = {"|i:splitlines", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300625 int keepends = 0;
626
Victor Stinner3e1fad62017-01-17 01:29:01 +0100627 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300628 &keepends)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300629 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300630 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300631 return_value = bytearray_splitlines_impl(self, keepends);
632
633exit:
634 return return_value;
635}
636
637PyDoc_STRVAR(bytearray_fromhex__doc__,
638"fromhex($type, string, /)\n"
639"--\n"
640"\n"
641"Create a bytearray object from a string of hexadecimal numbers.\n"
642"\n"
643"Spaces between two numbers are accepted.\n"
644"Example: bytearray.fromhex(\'B9 01EF\') -> bytearray(b\'\\\\xb9\\\\x01\\\\xef\')");
645
646#define BYTEARRAY_FROMHEX_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300647 {"fromhex", (PyCFunction)bytearray_fromhex, METH_O|METH_CLASS, bytearray_fromhex__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300648
649static PyObject *
Serhiy Storchaka0855e702016-07-01 17:22:31 +0300650bytearray_fromhex_impl(PyTypeObject *type, PyObject *string);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300651
652static PyObject *
Serhiy Storchaka0855e702016-07-01 17:22:31 +0300653bytearray_fromhex(PyTypeObject *type, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300654{
655 PyObject *return_value = NULL;
656 PyObject *string;
657
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300658 if (!PyArg_Parse(arg, "U:fromhex", &string)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300659 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300660 }
Serhiy Storchaka0855e702016-07-01 17:22:31 +0300661 return_value = bytearray_fromhex_impl(type, string);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300662
663exit:
664 return return_value;
665}
666
667PyDoc_STRVAR(bytearray_reduce__doc__,
668"__reduce__($self, /)\n"
669"--\n"
670"\n"
671"Return state information for pickling.");
672
673#define BYTEARRAY_REDUCE_METHODDEF \
674 {"__reduce__", (PyCFunction)bytearray_reduce, METH_NOARGS, bytearray_reduce__doc__},
675
676static PyObject *
677bytearray_reduce_impl(PyByteArrayObject *self);
678
679static PyObject *
680bytearray_reduce(PyByteArrayObject *self, PyObject *Py_UNUSED(ignored))
681{
682 return bytearray_reduce_impl(self);
683}
684
685PyDoc_STRVAR(bytearray_reduce_ex__doc__,
686"__reduce_ex__($self, proto=0, /)\n"
687"--\n"
688"\n"
689"Return state information for pickling.");
690
691#define BYTEARRAY_REDUCE_EX_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +0100692 {"__reduce_ex__", (PyCFunction)bytearray_reduce_ex, METH_FASTCALL, bytearray_reduce_ex__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300693
694static PyObject *
695bytearray_reduce_ex_impl(PyByteArrayObject *self, int proto);
696
697static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +0100698bytearray_reduce_ex(PyByteArrayObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300699{
700 PyObject *return_value = NULL;
701 int proto = 0;
702
Victor Stinner259f0e42017-01-17 01:35:17 +0100703 if (!_PyArg_ParseStack(args, nargs, "|i:__reduce_ex__",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300704 &proto)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300705 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300706 }
Victor Stinner259f0e42017-01-17 01:35:17 +0100707
708 if (!_PyArg_NoStackKeywords("__reduce_ex__", kwnames)) {
709 goto exit;
710 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300711 return_value = bytearray_reduce_ex_impl(self, proto);
712
713exit:
714 return return_value;
715}
716
717PyDoc_STRVAR(bytearray_sizeof__doc__,
718"__sizeof__($self, /)\n"
719"--\n"
720"\n"
721"Returns the size of the bytearray object in memory, in bytes.");
722
723#define BYTEARRAY_SIZEOF_METHODDEF \
724 {"__sizeof__", (PyCFunction)bytearray_sizeof, METH_NOARGS, bytearray_sizeof__doc__},
725
726static PyObject *
727bytearray_sizeof_impl(PyByteArrayObject *self);
728
729static PyObject *
730bytearray_sizeof(PyByteArrayObject *self, PyObject *Py_UNUSED(ignored))
731{
732 return bytearray_sizeof_impl(self);
733}
Victor Stinner259f0e42017-01-17 01:35:17 +0100734/*[clinic end generated code: output=e6c057d1cd7c2496 input=a9049054013a1b77]*/