blob: b49c26b0c45c8f45d1da9d3f75937b64d27fa913 [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__,
42"translate(table, [deletechars])\n"
43"Return a copy with each character mapped by the given translation table.\n"
44"\n"
45" table\n"
46" Translation table, which must be a bytes object of length 256.\n"
47"\n"
48"All characters occurring in the optional argument deletechars are removed.\n"
49"The remaining characters are mapped through the given translation table.");
50
51#define BYTEARRAY_TRANSLATE_METHODDEF \
52 {"translate", (PyCFunction)bytearray_translate, METH_VARARGS, bytearray_translate__doc__},
53
54static PyObject *
Larry Hastings89964c42015-04-14 18:07:59 -040055bytearray_translate_impl(PyByteArrayObject *self, PyObject *table,
56 int group_right_1, PyObject *deletechars);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030057
58static PyObject *
59bytearray_translate(PyByteArrayObject *self, PyObject *args)
60{
61 PyObject *return_value = NULL;
62 PyObject *table;
63 int group_right_1 = 0;
64 PyObject *deletechars = NULL;
65
66 switch (PyTuple_GET_SIZE(args)) {
67 case 1:
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030068 if (!PyArg_ParseTuple(args, "O:translate", &table)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030069 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030070 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030071 break;
72 case 2:
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030073 if (!PyArg_ParseTuple(args, "OO:translate", &table, &deletechars)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030074 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030075 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030076 group_right_1 = 1;
77 break;
78 default:
79 PyErr_SetString(PyExc_TypeError, "bytearray.translate requires 1 to 2 arguments");
80 goto exit;
81 }
82 return_value = bytearray_translate_impl(self, table, group_right_1, deletechars);
83
84exit:
85 return return_value;
86}
87
88PyDoc_STRVAR(bytearray_maketrans__doc__,
89"maketrans(frm, to, /)\n"
90"--\n"
91"\n"
92"Return a translation table useable for the bytes or bytearray translate method.\n"
93"\n"
94"The returned table will be one where each byte in frm is mapped to the byte at\n"
95"the same position in to.\n"
96"\n"
97"The bytes objects frm and to must be of the same length.");
98
99#define BYTEARRAY_MAKETRANS_METHODDEF \
100 {"maketrans", (PyCFunction)bytearray_maketrans, METH_VARARGS|METH_STATIC, bytearray_maketrans__doc__},
101
102static PyObject *
103bytearray_maketrans_impl(Py_buffer *frm, Py_buffer *to);
104
105static PyObject *
106bytearray_maketrans(void *null, PyObject *args)
107{
108 PyObject *return_value = NULL;
109 Py_buffer frm = {NULL, NULL};
110 Py_buffer to = {NULL, NULL};
111
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300112 if (!PyArg_ParseTuple(args, "y*y*:maketrans",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300113 &frm, &to)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300114 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300115 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300116 return_value = bytearray_maketrans_impl(&frm, &to);
117
118exit:
119 /* Cleanup for frm */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300120 if (frm.obj) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300121 PyBuffer_Release(&frm);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300122 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300123 /* Cleanup for to */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300124 if (to.obj) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300125 PyBuffer_Release(&to);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300126 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300127
128 return return_value;
129}
130
131PyDoc_STRVAR(bytearray_replace__doc__,
132"replace($self, old, new, count=-1, /)\n"
133"--\n"
134"\n"
135"Return a copy with all occurrences of substring old replaced by new.\n"
136"\n"
137" count\n"
138" Maximum number of occurrences to replace.\n"
139" -1 (the default value) means replace all occurrences.\n"
140"\n"
141"If the optional argument count is given, only the first count occurrences are\n"
142"replaced.");
143
144#define BYTEARRAY_REPLACE_METHODDEF \
145 {"replace", (PyCFunction)bytearray_replace, METH_VARARGS, bytearray_replace__doc__},
146
147static PyObject *
Larry Hastings89964c42015-04-14 18:07:59 -0400148bytearray_replace_impl(PyByteArrayObject *self, Py_buffer *old,
149 Py_buffer *new, Py_ssize_t count);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300150
151static PyObject *
152bytearray_replace(PyByteArrayObject *self, PyObject *args)
153{
154 PyObject *return_value = NULL;
155 Py_buffer old = {NULL, NULL};
156 Py_buffer new = {NULL, NULL};
157 Py_ssize_t count = -1;
158
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300159 if (!PyArg_ParseTuple(args, "y*y*|n:replace",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300160 &old, &new, &count)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300161 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300162 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300163 return_value = bytearray_replace_impl(self, &old, &new, count);
164
165exit:
166 /* Cleanup for old */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300167 if (old.obj) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300168 PyBuffer_Release(&old);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300169 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300170 /* Cleanup for new */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300171 if (new.obj) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300172 PyBuffer_Release(&new);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300173 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300174
175 return return_value;
176}
177
178PyDoc_STRVAR(bytearray_split__doc__,
179"split($self, /, sep=None, maxsplit=-1)\n"
180"--\n"
181"\n"
182"Return a list of the sections in the bytearray, using sep as the delimiter.\n"
183"\n"
184" sep\n"
185" The delimiter according which to split the bytearray.\n"
186" None (the default value) means split on ASCII whitespace characters\n"
187" (space, tab, return, newline, formfeed, vertical tab).\n"
188" maxsplit\n"
189" Maximum number of splits to do.\n"
190" -1 (the default value) means no limit.");
191
192#define BYTEARRAY_SPLIT_METHODDEF \
193 {"split", (PyCFunction)bytearray_split, METH_VARARGS|METH_KEYWORDS, bytearray_split__doc__},
194
195static PyObject *
Larry Hastings89964c42015-04-14 18:07:59 -0400196bytearray_split_impl(PyByteArrayObject *self, PyObject *sep,
197 Py_ssize_t maxsplit);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300198
199static PyObject *
200bytearray_split(PyByteArrayObject *self, PyObject *args, PyObject *kwargs)
201{
202 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300203 static const char * const _keywords[] = {"sep", "maxsplit", NULL};
204 static _PyArg_Parser _parser = {"|On:split", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300205 PyObject *sep = Py_None;
206 Py_ssize_t maxsplit = -1;
207
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300208 if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300209 &sep, &maxsplit)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300210 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300211 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300212 return_value = bytearray_split_impl(self, sep, maxsplit);
213
214exit:
215 return return_value;
216}
217
218PyDoc_STRVAR(bytearray_partition__doc__,
219"partition($self, sep, /)\n"
220"--\n"
221"\n"
222"Partition the bytearray into three parts using the given separator.\n"
223"\n"
224"This will search for the separator sep in the bytearray. If the separator is\n"
225"found, returns a 3-tuple containing the part before the separator, the\n"
226"separator itself, and the part after it.\n"
227"\n"
228"If the separator is not found, returns a 3-tuple containing the original\n"
229"bytearray object and two empty bytearray objects.");
230
231#define BYTEARRAY_PARTITION_METHODDEF \
232 {"partition", (PyCFunction)bytearray_partition, METH_O, bytearray_partition__doc__},
233
234PyDoc_STRVAR(bytearray_rpartition__doc__,
235"rpartition($self, sep, /)\n"
236"--\n"
237"\n"
238"Partition the bytes into three parts using the given separator.\n"
239"\n"
240"This will search for the separator sep in the bytearray, starting and the end.\n"
241"If the separator is found, returns a 3-tuple containing the part before the\n"
242"separator, the separator itself, and the part after it.\n"
243"\n"
244"If the separator is not found, returns a 3-tuple containing two empty bytearray\n"
245"objects and the original bytearray object.");
246
247#define BYTEARRAY_RPARTITION_METHODDEF \
248 {"rpartition", (PyCFunction)bytearray_rpartition, METH_O, bytearray_rpartition__doc__},
249
250PyDoc_STRVAR(bytearray_rsplit__doc__,
251"rsplit($self, /, sep=None, maxsplit=-1)\n"
252"--\n"
253"\n"
254"Return a list of the sections in the bytearray, using sep as the delimiter.\n"
255"\n"
256" sep\n"
257" The delimiter according which to split the bytearray.\n"
258" None (the default value) means split on ASCII whitespace characters\n"
259" (space, tab, return, newline, formfeed, vertical tab).\n"
260" maxsplit\n"
261" Maximum number of splits to do.\n"
262" -1 (the default value) means no limit.\n"
263"\n"
264"Splitting is done starting at the end of the bytearray and working to the front.");
265
266#define BYTEARRAY_RSPLIT_METHODDEF \
267 {"rsplit", (PyCFunction)bytearray_rsplit, METH_VARARGS|METH_KEYWORDS, bytearray_rsplit__doc__},
268
269static PyObject *
Larry Hastings89964c42015-04-14 18:07:59 -0400270bytearray_rsplit_impl(PyByteArrayObject *self, PyObject *sep,
271 Py_ssize_t maxsplit);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300272
273static PyObject *
274bytearray_rsplit(PyByteArrayObject *self, PyObject *args, PyObject *kwargs)
275{
276 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300277 static const char * const _keywords[] = {"sep", "maxsplit", NULL};
278 static _PyArg_Parser _parser = {"|On:rsplit", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300279 PyObject *sep = Py_None;
280 Py_ssize_t maxsplit = -1;
281
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300282 if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300283 &sep, &maxsplit)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300284 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300285 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300286 return_value = bytearray_rsplit_impl(self, sep, maxsplit);
287
288exit:
289 return return_value;
290}
291
292PyDoc_STRVAR(bytearray_reverse__doc__,
293"reverse($self, /)\n"
294"--\n"
295"\n"
296"Reverse the order of the values in B in place.");
297
298#define BYTEARRAY_REVERSE_METHODDEF \
299 {"reverse", (PyCFunction)bytearray_reverse, METH_NOARGS, bytearray_reverse__doc__},
300
301static PyObject *
302bytearray_reverse_impl(PyByteArrayObject *self);
303
304static PyObject *
305bytearray_reverse(PyByteArrayObject *self, PyObject *Py_UNUSED(ignored))
306{
307 return bytearray_reverse_impl(self);
308}
309
310PyDoc_STRVAR(bytearray_insert__doc__,
311"insert($self, index, item, /)\n"
312"--\n"
313"\n"
314"Insert a single item into the bytearray before the given index.\n"
315"\n"
316" index\n"
317" The index where the value is to be inserted.\n"
318" item\n"
319" The item to be inserted.");
320
321#define BYTEARRAY_INSERT_METHODDEF \
322 {"insert", (PyCFunction)bytearray_insert, METH_VARARGS, bytearray_insert__doc__},
323
324static PyObject *
325bytearray_insert_impl(PyByteArrayObject *self, Py_ssize_t index, int item);
326
327static PyObject *
328bytearray_insert(PyByteArrayObject *self, PyObject *args)
329{
330 PyObject *return_value = NULL;
331 Py_ssize_t index;
332 int item;
333
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300334 if (!PyArg_ParseTuple(args, "nO&:insert",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300335 &index, _getbytevalue, &item)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300336 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300337 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300338 return_value = bytearray_insert_impl(self, index, item);
339
340exit:
341 return return_value;
342}
343
344PyDoc_STRVAR(bytearray_append__doc__,
345"append($self, item, /)\n"
346"--\n"
347"\n"
348"Append a single item to the end of the bytearray.\n"
349"\n"
350" item\n"
351" The item to be appended.");
352
353#define BYTEARRAY_APPEND_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300354 {"append", (PyCFunction)bytearray_append, METH_O, bytearray_append__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300355
356static PyObject *
357bytearray_append_impl(PyByteArrayObject *self, int item);
358
359static PyObject *
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300360bytearray_append(PyByteArrayObject *self, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300361{
362 PyObject *return_value = NULL;
363 int item;
364
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300365 if (!PyArg_Parse(arg, "O&:append", _getbytevalue, &item)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300366 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300367 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300368 return_value = bytearray_append_impl(self, item);
369
370exit:
371 return return_value;
372}
373
374PyDoc_STRVAR(bytearray_extend__doc__,
375"extend($self, iterable_of_ints, /)\n"
376"--\n"
377"\n"
378"Append all the items from the iterator or sequence to the end of the bytearray.\n"
379"\n"
380" iterable_of_ints\n"
381" The iterable of items to append.");
382
383#define BYTEARRAY_EXTEND_METHODDEF \
384 {"extend", (PyCFunction)bytearray_extend, METH_O, bytearray_extend__doc__},
385
386PyDoc_STRVAR(bytearray_pop__doc__,
387"pop($self, index=-1, /)\n"
388"--\n"
389"\n"
390"Remove and return a single item from B.\n"
391"\n"
392" index\n"
393" The index from where to remove the item.\n"
394" -1 (the default value) means remove the last item.\n"
395"\n"
396"If no index argument is given, will pop the last item.");
397
398#define BYTEARRAY_POP_METHODDEF \
399 {"pop", (PyCFunction)bytearray_pop, METH_VARARGS, bytearray_pop__doc__},
400
401static PyObject *
402bytearray_pop_impl(PyByteArrayObject *self, Py_ssize_t index);
403
404static PyObject *
405bytearray_pop(PyByteArrayObject *self, PyObject *args)
406{
407 PyObject *return_value = NULL;
408 Py_ssize_t index = -1;
409
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300410 if (!PyArg_ParseTuple(args, "|n:pop",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300411 &index)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300412 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300413 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300414 return_value = bytearray_pop_impl(self, index);
415
416exit:
417 return return_value;
418}
419
420PyDoc_STRVAR(bytearray_remove__doc__,
421"remove($self, value, /)\n"
422"--\n"
423"\n"
424"Remove the first occurrence of a value in the bytearray.\n"
425"\n"
426" value\n"
427" The value to remove.");
428
429#define BYTEARRAY_REMOVE_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300430 {"remove", (PyCFunction)bytearray_remove, METH_O, bytearray_remove__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300431
432static PyObject *
433bytearray_remove_impl(PyByteArrayObject *self, int value);
434
435static PyObject *
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300436bytearray_remove(PyByteArrayObject *self, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300437{
438 PyObject *return_value = NULL;
439 int value;
440
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300441 if (!PyArg_Parse(arg, "O&:remove", _getbytevalue, &value)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300442 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300443 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300444 return_value = bytearray_remove_impl(self, value);
445
446exit:
447 return return_value;
448}
449
450PyDoc_STRVAR(bytearray_strip__doc__,
451"strip($self, bytes=None, /)\n"
452"--\n"
453"\n"
454"Strip leading and trailing bytes contained in the argument.\n"
455"\n"
456"If the argument is omitted or None, strip leading and trailing ASCII whitespace.");
457
458#define BYTEARRAY_STRIP_METHODDEF \
459 {"strip", (PyCFunction)bytearray_strip, METH_VARARGS, bytearray_strip__doc__},
460
461static PyObject *
462bytearray_strip_impl(PyByteArrayObject *self, PyObject *bytes);
463
464static PyObject *
465bytearray_strip(PyByteArrayObject *self, PyObject *args)
466{
467 PyObject *return_value = NULL;
468 PyObject *bytes = Py_None;
469
470 if (!PyArg_UnpackTuple(args, "strip",
471 0, 1,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300472 &bytes)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300473 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300474 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300475 return_value = bytearray_strip_impl(self, bytes);
476
477exit:
478 return return_value;
479}
480
481PyDoc_STRVAR(bytearray_lstrip__doc__,
482"lstrip($self, bytes=None, /)\n"
483"--\n"
484"\n"
485"Strip leading bytes contained in the argument.\n"
486"\n"
487"If the argument is omitted or None, strip leading ASCII whitespace.");
488
489#define BYTEARRAY_LSTRIP_METHODDEF \
490 {"lstrip", (PyCFunction)bytearray_lstrip, METH_VARARGS, bytearray_lstrip__doc__},
491
492static PyObject *
493bytearray_lstrip_impl(PyByteArrayObject *self, PyObject *bytes);
494
495static PyObject *
496bytearray_lstrip(PyByteArrayObject *self, PyObject *args)
497{
498 PyObject *return_value = NULL;
499 PyObject *bytes = Py_None;
500
501 if (!PyArg_UnpackTuple(args, "lstrip",
502 0, 1,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300503 &bytes)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300504 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300505 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300506 return_value = bytearray_lstrip_impl(self, bytes);
507
508exit:
509 return return_value;
510}
511
512PyDoc_STRVAR(bytearray_rstrip__doc__,
513"rstrip($self, bytes=None, /)\n"
514"--\n"
515"\n"
516"Strip trailing bytes contained in the argument.\n"
517"\n"
518"If the argument is omitted or None, strip trailing ASCII whitespace.");
519
520#define BYTEARRAY_RSTRIP_METHODDEF \
521 {"rstrip", (PyCFunction)bytearray_rstrip, METH_VARARGS, bytearray_rstrip__doc__},
522
523static PyObject *
524bytearray_rstrip_impl(PyByteArrayObject *self, PyObject *bytes);
525
526static PyObject *
527bytearray_rstrip(PyByteArrayObject *self, PyObject *args)
528{
529 PyObject *return_value = NULL;
530 PyObject *bytes = Py_None;
531
532 if (!PyArg_UnpackTuple(args, "rstrip",
533 0, 1,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300534 &bytes)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300535 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300536 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300537 return_value = bytearray_rstrip_impl(self, bytes);
538
539exit:
540 return return_value;
541}
542
543PyDoc_STRVAR(bytearray_decode__doc__,
544"decode($self, /, encoding=\'utf-8\', errors=\'strict\')\n"
545"--\n"
546"\n"
547"Decode the bytearray using the codec registered for encoding.\n"
548"\n"
549" encoding\n"
550" The encoding with which to decode the bytearray.\n"
551" errors\n"
552" The error handling scheme to use for the handling of decoding errors.\n"
553" The default is \'strict\' meaning that decoding errors raise a\n"
554" UnicodeDecodeError. Other possible values are \'ignore\' and \'replace\'\n"
555" as well as any other name registered with codecs.register_error that\n"
556" can handle UnicodeDecodeErrors.");
557
558#define BYTEARRAY_DECODE_METHODDEF \
559 {"decode", (PyCFunction)bytearray_decode, METH_VARARGS|METH_KEYWORDS, bytearray_decode__doc__},
560
561static PyObject *
Larry Hastings89964c42015-04-14 18:07:59 -0400562bytearray_decode_impl(PyByteArrayObject *self, const char *encoding,
563 const char *errors);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300564
565static PyObject *
566bytearray_decode(PyByteArrayObject *self, PyObject *args, PyObject *kwargs)
567{
568 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300569 static const char * const _keywords[] = {"encoding", "errors", NULL};
570 static _PyArg_Parser _parser = {"|ss:decode", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300571 const char *encoding = NULL;
572 const char *errors = NULL;
573
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300574 if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300575 &encoding, &errors)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300576 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300577 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300578 return_value = bytearray_decode_impl(self, encoding, errors);
579
580exit:
581 return return_value;
582}
583
584PyDoc_STRVAR(bytearray_join__doc__,
585"join($self, iterable_of_bytes, /)\n"
586"--\n"
587"\n"
588"Concatenate any number of bytes/bytearray objects.\n"
589"\n"
590"The bytearray whose method is called is inserted in between each pair.\n"
591"\n"
592"The result is returned as a new bytearray object.");
593
594#define BYTEARRAY_JOIN_METHODDEF \
595 {"join", (PyCFunction)bytearray_join, METH_O, bytearray_join__doc__},
596
597PyDoc_STRVAR(bytearray_splitlines__doc__,
598"splitlines($self, /, keepends=False)\n"
599"--\n"
600"\n"
601"Return a list of the lines in the bytearray, breaking at line boundaries.\n"
602"\n"
603"Line breaks are not included in the resulting list unless keepends is given and\n"
604"true.");
605
606#define BYTEARRAY_SPLITLINES_METHODDEF \
607 {"splitlines", (PyCFunction)bytearray_splitlines, METH_VARARGS|METH_KEYWORDS, bytearray_splitlines__doc__},
608
609static PyObject *
610bytearray_splitlines_impl(PyByteArrayObject *self, int keepends);
611
612static PyObject *
613bytearray_splitlines(PyByteArrayObject *self, PyObject *args, PyObject *kwargs)
614{
615 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300616 static const char * const _keywords[] = {"keepends", NULL};
617 static _PyArg_Parser _parser = {"|i:splitlines", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300618 int keepends = 0;
619
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300620 if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300621 &keepends)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300622 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300623 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300624 return_value = bytearray_splitlines_impl(self, keepends);
625
626exit:
627 return return_value;
628}
629
630PyDoc_STRVAR(bytearray_fromhex__doc__,
631"fromhex($type, string, /)\n"
632"--\n"
633"\n"
634"Create a bytearray object from a string of hexadecimal numbers.\n"
635"\n"
636"Spaces between two numbers are accepted.\n"
637"Example: bytearray.fromhex(\'B9 01EF\') -> bytearray(b\'\\\\xb9\\\\x01\\\\xef\')");
638
639#define BYTEARRAY_FROMHEX_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300640 {"fromhex", (PyCFunction)bytearray_fromhex, METH_O|METH_CLASS, bytearray_fromhex__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300641
642static PyObject *
Serhiy Storchaka0855e702016-07-01 17:22:31 +0300643bytearray_fromhex_impl(PyTypeObject *type, PyObject *string);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300644
645static PyObject *
Serhiy Storchaka0855e702016-07-01 17:22:31 +0300646bytearray_fromhex(PyTypeObject *type, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300647{
648 PyObject *return_value = NULL;
649 PyObject *string;
650
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300651 if (!PyArg_Parse(arg, "U:fromhex", &string)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300652 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300653 }
Serhiy Storchaka0855e702016-07-01 17:22:31 +0300654 return_value = bytearray_fromhex_impl(type, string);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300655
656exit:
657 return return_value;
658}
659
660PyDoc_STRVAR(bytearray_reduce__doc__,
661"__reduce__($self, /)\n"
662"--\n"
663"\n"
664"Return state information for pickling.");
665
666#define BYTEARRAY_REDUCE_METHODDEF \
667 {"__reduce__", (PyCFunction)bytearray_reduce, METH_NOARGS, bytearray_reduce__doc__},
668
669static PyObject *
670bytearray_reduce_impl(PyByteArrayObject *self);
671
672static PyObject *
673bytearray_reduce(PyByteArrayObject *self, PyObject *Py_UNUSED(ignored))
674{
675 return bytearray_reduce_impl(self);
676}
677
678PyDoc_STRVAR(bytearray_reduce_ex__doc__,
679"__reduce_ex__($self, proto=0, /)\n"
680"--\n"
681"\n"
682"Return state information for pickling.");
683
684#define BYTEARRAY_REDUCE_EX_METHODDEF \
685 {"__reduce_ex__", (PyCFunction)bytearray_reduce_ex, METH_VARARGS, bytearray_reduce_ex__doc__},
686
687static PyObject *
688bytearray_reduce_ex_impl(PyByteArrayObject *self, int proto);
689
690static PyObject *
691bytearray_reduce_ex(PyByteArrayObject *self, PyObject *args)
692{
693 PyObject *return_value = NULL;
694 int proto = 0;
695
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300696 if (!PyArg_ParseTuple(args, "|i:__reduce_ex__",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300697 &proto)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300698 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300699 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300700 return_value = bytearray_reduce_ex_impl(self, proto);
701
702exit:
703 return return_value;
704}
705
706PyDoc_STRVAR(bytearray_sizeof__doc__,
707"__sizeof__($self, /)\n"
708"--\n"
709"\n"
710"Returns the size of the bytearray object in memory, in bytes.");
711
712#define BYTEARRAY_SIZEOF_METHODDEF \
713 {"__sizeof__", (PyCFunction)bytearray_sizeof, METH_NOARGS, bytearray_sizeof__doc__},
714
715static PyObject *
716bytearray_sizeof_impl(PyByteArrayObject *self);
717
718static PyObject *
719bytearray_sizeof(PyByteArrayObject *self, PyObject *Py_UNUSED(ignored))
720{
721 return bytearray_sizeof_impl(self);
722}
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300723/*[clinic end generated code: output=0af30f8c0b1ecd76 input=a9049054013a1b77]*/