blob: e1cf03bbc28318fc6cd88e6b9a984d9d9bb9c4a3 [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;
203 static char *_keywords[] = {"sep", "maxsplit", NULL};
204 PyObject *sep = Py_None;
205 Py_ssize_t maxsplit = -1;
206
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300207 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|On:split", _keywords,
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 \
266 {"rsplit", (PyCFunction)bytearray_rsplit, METH_VARARGS|METH_KEYWORDS, bytearray_rsplit__doc__},
267
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 *
273bytearray_rsplit(PyByteArrayObject *self, PyObject *args, PyObject *kwargs)
274{
275 PyObject *return_value = NULL;
276 static char *_keywords[] = {"sep", "maxsplit", NULL};
277 PyObject *sep = Py_None;
278 Py_ssize_t maxsplit = -1;
279
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300280 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|On:rsplit", _keywords,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300281 &sep, &maxsplit)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300282 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300283 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300284 return_value = bytearray_rsplit_impl(self, sep, maxsplit);
285
286exit:
287 return return_value;
288}
289
290PyDoc_STRVAR(bytearray_reverse__doc__,
291"reverse($self, /)\n"
292"--\n"
293"\n"
294"Reverse the order of the values in B in place.");
295
296#define BYTEARRAY_REVERSE_METHODDEF \
297 {"reverse", (PyCFunction)bytearray_reverse, METH_NOARGS, bytearray_reverse__doc__},
298
299static PyObject *
300bytearray_reverse_impl(PyByteArrayObject *self);
301
302static PyObject *
303bytearray_reverse(PyByteArrayObject *self, PyObject *Py_UNUSED(ignored))
304{
305 return bytearray_reverse_impl(self);
306}
307
308PyDoc_STRVAR(bytearray_insert__doc__,
309"insert($self, index, item, /)\n"
310"--\n"
311"\n"
312"Insert a single item into the bytearray before the given index.\n"
313"\n"
314" index\n"
315" The index where the value is to be inserted.\n"
316" item\n"
317" The item to be inserted.");
318
319#define BYTEARRAY_INSERT_METHODDEF \
320 {"insert", (PyCFunction)bytearray_insert, METH_VARARGS, bytearray_insert__doc__},
321
322static PyObject *
323bytearray_insert_impl(PyByteArrayObject *self, Py_ssize_t index, int item);
324
325static PyObject *
326bytearray_insert(PyByteArrayObject *self, PyObject *args)
327{
328 PyObject *return_value = NULL;
329 Py_ssize_t index;
330 int item;
331
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300332 if (!PyArg_ParseTuple(args, "nO&:insert",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300333 &index, _getbytevalue, &item)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300334 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300335 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300336 return_value = bytearray_insert_impl(self, index, item);
337
338exit:
339 return return_value;
340}
341
342PyDoc_STRVAR(bytearray_append__doc__,
343"append($self, item, /)\n"
344"--\n"
345"\n"
346"Append a single item to the end of the bytearray.\n"
347"\n"
348" item\n"
349" The item to be appended.");
350
351#define BYTEARRAY_APPEND_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300352 {"append", (PyCFunction)bytearray_append, METH_O, bytearray_append__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300353
354static PyObject *
355bytearray_append_impl(PyByteArrayObject *self, int item);
356
357static PyObject *
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300358bytearray_append(PyByteArrayObject *self, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300359{
360 PyObject *return_value = NULL;
361 int item;
362
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300363 if (!PyArg_Parse(arg, "O&:append", _getbytevalue, &item)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300364 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300365 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300366 return_value = bytearray_append_impl(self, item);
367
368exit:
369 return return_value;
370}
371
372PyDoc_STRVAR(bytearray_extend__doc__,
373"extend($self, iterable_of_ints, /)\n"
374"--\n"
375"\n"
376"Append all the items from the iterator or sequence to the end of the bytearray.\n"
377"\n"
378" iterable_of_ints\n"
379" The iterable of items to append.");
380
381#define BYTEARRAY_EXTEND_METHODDEF \
382 {"extend", (PyCFunction)bytearray_extend, METH_O, bytearray_extend__doc__},
383
384PyDoc_STRVAR(bytearray_pop__doc__,
385"pop($self, index=-1, /)\n"
386"--\n"
387"\n"
388"Remove and return a single item from B.\n"
389"\n"
390" index\n"
391" The index from where to remove the item.\n"
392" -1 (the default value) means remove the last item.\n"
393"\n"
394"If no index argument is given, will pop the last item.");
395
396#define BYTEARRAY_POP_METHODDEF \
397 {"pop", (PyCFunction)bytearray_pop, METH_VARARGS, bytearray_pop__doc__},
398
399static PyObject *
400bytearray_pop_impl(PyByteArrayObject *self, Py_ssize_t index);
401
402static PyObject *
403bytearray_pop(PyByteArrayObject *self, PyObject *args)
404{
405 PyObject *return_value = NULL;
406 Py_ssize_t index = -1;
407
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300408 if (!PyArg_ParseTuple(args, "|n:pop",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300409 &index)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300410 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300411 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300412 return_value = bytearray_pop_impl(self, index);
413
414exit:
415 return return_value;
416}
417
418PyDoc_STRVAR(bytearray_remove__doc__,
419"remove($self, value, /)\n"
420"--\n"
421"\n"
422"Remove the first occurrence of a value in the bytearray.\n"
423"\n"
424" value\n"
425" The value to remove.");
426
427#define BYTEARRAY_REMOVE_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300428 {"remove", (PyCFunction)bytearray_remove, METH_O, bytearray_remove__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300429
430static PyObject *
431bytearray_remove_impl(PyByteArrayObject *self, int value);
432
433static PyObject *
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300434bytearray_remove(PyByteArrayObject *self, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300435{
436 PyObject *return_value = NULL;
437 int value;
438
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300439 if (!PyArg_Parse(arg, "O&:remove", _getbytevalue, &value)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300440 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300441 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300442 return_value = bytearray_remove_impl(self, value);
443
444exit:
445 return return_value;
446}
447
448PyDoc_STRVAR(bytearray_strip__doc__,
449"strip($self, bytes=None, /)\n"
450"--\n"
451"\n"
452"Strip leading and trailing bytes contained in the argument.\n"
453"\n"
454"If the argument is omitted or None, strip leading and trailing ASCII whitespace.");
455
456#define BYTEARRAY_STRIP_METHODDEF \
457 {"strip", (PyCFunction)bytearray_strip, METH_VARARGS, bytearray_strip__doc__},
458
459static PyObject *
460bytearray_strip_impl(PyByteArrayObject *self, PyObject *bytes);
461
462static PyObject *
463bytearray_strip(PyByteArrayObject *self, PyObject *args)
464{
465 PyObject *return_value = NULL;
466 PyObject *bytes = Py_None;
467
468 if (!PyArg_UnpackTuple(args, "strip",
469 0, 1,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300470 &bytes)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300471 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300472 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300473 return_value = bytearray_strip_impl(self, bytes);
474
475exit:
476 return return_value;
477}
478
479PyDoc_STRVAR(bytearray_lstrip__doc__,
480"lstrip($self, bytes=None, /)\n"
481"--\n"
482"\n"
483"Strip leading bytes contained in the argument.\n"
484"\n"
485"If the argument is omitted or None, strip leading ASCII whitespace.");
486
487#define BYTEARRAY_LSTRIP_METHODDEF \
488 {"lstrip", (PyCFunction)bytearray_lstrip, METH_VARARGS, bytearray_lstrip__doc__},
489
490static PyObject *
491bytearray_lstrip_impl(PyByteArrayObject *self, PyObject *bytes);
492
493static PyObject *
494bytearray_lstrip(PyByteArrayObject *self, PyObject *args)
495{
496 PyObject *return_value = NULL;
497 PyObject *bytes = Py_None;
498
499 if (!PyArg_UnpackTuple(args, "lstrip",
500 0, 1,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300501 &bytes)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300502 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300503 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300504 return_value = bytearray_lstrip_impl(self, bytes);
505
506exit:
507 return return_value;
508}
509
510PyDoc_STRVAR(bytearray_rstrip__doc__,
511"rstrip($self, bytes=None, /)\n"
512"--\n"
513"\n"
514"Strip trailing bytes contained in the argument.\n"
515"\n"
516"If the argument is omitted or None, strip trailing ASCII whitespace.");
517
518#define BYTEARRAY_RSTRIP_METHODDEF \
519 {"rstrip", (PyCFunction)bytearray_rstrip, METH_VARARGS, bytearray_rstrip__doc__},
520
521static PyObject *
522bytearray_rstrip_impl(PyByteArrayObject *self, PyObject *bytes);
523
524static PyObject *
525bytearray_rstrip(PyByteArrayObject *self, PyObject *args)
526{
527 PyObject *return_value = NULL;
528 PyObject *bytes = Py_None;
529
530 if (!PyArg_UnpackTuple(args, "rstrip",
531 0, 1,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300532 &bytes)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300533 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300534 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300535 return_value = bytearray_rstrip_impl(self, bytes);
536
537exit:
538 return return_value;
539}
540
541PyDoc_STRVAR(bytearray_decode__doc__,
542"decode($self, /, encoding=\'utf-8\', errors=\'strict\')\n"
543"--\n"
544"\n"
545"Decode the bytearray using the codec registered for encoding.\n"
546"\n"
547" encoding\n"
548" The encoding with which to decode the bytearray.\n"
549" errors\n"
550" The error handling scheme to use for the handling of decoding errors.\n"
551" The default is \'strict\' meaning that decoding errors raise a\n"
552" UnicodeDecodeError. Other possible values are \'ignore\' and \'replace\'\n"
553" as well as any other name registered with codecs.register_error that\n"
554" can handle UnicodeDecodeErrors.");
555
556#define BYTEARRAY_DECODE_METHODDEF \
557 {"decode", (PyCFunction)bytearray_decode, METH_VARARGS|METH_KEYWORDS, bytearray_decode__doc__},
558
559static PyObject *
Larry Hastings89964c42015-04-14 18:07:59 -0400560bytearray_decode_impl(PyByteArrayObject *self, const char *encoding,
561 const char *errors);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300562
563static PyObject *
564bytearray_decode(PyByteArrayObject *self, PyObject *args, PyObject *kwargs)
565{
566 PyObject *return_value = NULL;
567 static char *_keywords[] = {"encoding", "errors", NULL};
568 const char *encoding = NULL;
569 const char *errors = NULL;
570
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300571 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|ss:decode", _keywords,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300572 &encoding, &errors)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300573 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300574 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300575 return_value = bytearray_decode_impl(self, encoding, errors);
576
577exit:
578 return return_value;
579}
580
581PyDoc_STRVAR(bytearray_join__doc__,
582"join($self, iterable_of_bytes, /)\n"
583"--\n"
584"\n"
585"Concatenate any number of bytes/bytearray objects.\n"
586"\n"
587"The bytearray whose method is called is inserted in between each pair.\n"
588"\n"
589"The result is returned as a new bytearray object.");
590
591#define BYTEARRAY_JOIN_METHODDEF \
592 {"join", (PyCFunction)bytearray_join, METH_O, bytearray_join__doc__},
593
594PyDoc_STRVAR(bytearray_splitlines__doc__,
595"splitlines($self, /, keepends=False)\n"
596"--\n"
597"\n"
598"Return a list of the lines in the bytearray, breaking at line boundaries.\n"
599"\n"
600"Line breaks are not included in the resulting list unless keepends is given and\n"
601"true.");
602
603#define BYTEARRAY_SPLITLINES_METHODDEF \
604 {"splitlines", (PyCFunction)bytearray_splitlines, METH_VARARGS|METH_KEYWORDS, bytearray_splitlines__doc__},
605
606static PyObject *
607bytearray_splitlines_impl(PyByteArrayObject *self, int keepends);
608
609static PyObject *
610bytearray_splitlines(PyByteArrayObject *self, PyObject *args, PyObject *kwargs)
611{
612 PyObject *return_value = NULL;
613 static char *_keywords[] = {"keepends", NULL};
614 int keepends = 0;
615
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300616 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|i:splitlines", _keywords,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300617 &keepends)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300618 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300619 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300620 return_value = bytearray_splitlines_impl(self, keepends);
621
622exit:
623 return return_value;
624}
625
626PyDoc_STRVAR(bytearray_fromhex__doc__,
627"fromhex($type, string, /)\n"
628"--\n"
629"\n"
630"Create a bytearray object from a string of hexadecimal numbers.\n"
631"\n"
632"Spaces between two numbers are accepted.\n"
633"Example: bytearray.fromhex(\'B9 01EF\') -> bytearray(b\'\\\\xb9\\\\x01\\\\xef\')");
634
635#define BYTEARRAY_FROMHEX_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300636 {"fromhex", (PyCFunction)bytearray_fromhex, METH_O|METH_CLASS, bytearray_fromhex__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300637
638static PyObject *
Serhiy Storchaka0855e702016-07-01 17:22:31 +0300639bytearray_fromhex_impl(PyTypeObject *type, PyObject *string);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300640
641static PyObject *
Serhiy Storchaka0855e702016-07-01 17:22:31 +0300642bytearray_fromhex(PyTypeObject *type, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300643{
644 PyObject *return_value = NULL;
645 PyObject *string;
646
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300647 if (!PyArg_Parse(arg, "U:fromhex", &string)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300648 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300649 }
Serhiy Storchaka0855e702016-07-01 17:22:31 +0300650 return_value = bytearray_fromhex_impl(type, string);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300651
652exit:
653 return return_value;
654}
655
656PyDoc_STRVAR(bytearray_reduce__doc__,
657"__reduce__($self, /)\n"
658"--\n"
659"\n"
660"Return state information for pickling.");
661
662#define BYTEARRAY_REDUCE_METHODDEF \
663 {"__reduce__", (PyCFunction)bytearray_reduce, METH_NOARGS, bytearray_reduce__doc__},
664
665static PyObject *
666bytearray_reduce_impl(PyByteArrayObject *self);
667
668static PyObject *
669bytearray_reduce(PyByteArrayObject *self, PyObject *Py_UNUSED(ignored))
670{
671 return bytearray_reduce_impl(self);
672}
673
674PyDoc_STRVAR(bytearray_reduce_ex__doc__,
675"__reduce_ex__($self, proto=0, /)\n"
676"--\n"
677"\n"
678"Return state information for pickling.");
679
680#define BYTEARRAY_REDUCE_EX_METHODDEF \
681 {"__reduce_ex__", (PyCFunction)bytearray_reduce_ex, METH_VARARGS, bytearray_reduce_ex__doc__},
682
683static PyObject *
684bytearray_reduce_ex_impl(PyByteArrayObject *self, int proto);
685
686static PyObject *
687bytearray_reduce_ex(PyByteArrayObject *self, PyObject *args)
688{
689 PyObject *return_value = NULL;
690 int proto = 0;
691
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300692 if (!PyArg_ParseTuple(args, "|i:__reduce_ex__",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300693 &proto)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300694 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300695 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300696 return_value = bytearray_reduce_ex_impl(self, proto);
697
698exit:
699 return return_value;
700}
701
702PyDoc_STRVAR(bytearray_sizeof__doc__,
703"__sizeof__($self, /)\n"
704"--\n"
705"\n"
706"Returns the size of the bytearray object in memory, in bytes.");
707
708#define BYTEARRAY_SIZEOF_METHODDEF \
709 {"__sizeof__", (PyCFunction)bytearray_sizeof, METH_NOARGS, bytearray_sizeof__doc__},
710
711static PyObject *
712bytearray_sizeof_impl(PyByteArrayObject *self);
713
714static PyObject *
715bytearray_sizeof(PyByteArrayObject *self, PyObject *Py_UNUSED(ignored))
716{
717 return bytearray_sizeof_impl(self);
718}
Serhiy Storchaka0855e702016-07-01 17:22:31 +0300719/*[clinic end generated code: output=a32f183ebef159cc input=a9049054013a1b77]*/