blob: c75acb75cf8225fad8f62c8c2e44a3564ebc348c [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 Stinner37e4ef72016-09-09 20:00:13 -070069 if (!_PyArg_ParseStack(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 \
91 {"maketrans", (PyCFunction)bytearray_maketrans, METH_VARARGS|METH_STATIC, bytearray_maketrans__doc__},
92
93static PyObject *
94bytearray_maketrans_impl(Py_buffer *frm, Py_buffer *to);
95
96static PyObject *
97bytearray_maketrans(void *null, PyObject *args)
98{
99 PyObject *return_value = NULL;
100 Py_buffer frm = {NULL, NULL};
101 Py_buffer to = {NULL, NULL};
102
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300103 if (!PyArg_ParseTuple(args, "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 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300107 return_value = bytearray_maketrans_impl(&frm, &to);
108
109exit:
110 /* Cleanup for frm */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300111 if (frm.obj) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300112 PyBuffer_Release(&frm);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300113 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300114 /* Cleanup for to */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300115 if (to.obj) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300116 PyBuffer_Release(&to);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300117 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300118
119 return return_value;
120}
121
122PyDoc_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 \
136 {"replace", (PyCFunction)bytearray_replace, METH_VARARGS, bytearray_replace__doc__},
137
138static PyObject *
Larry Hastings89964c42015-04-14 18:07:59 -0400139bytearray_replace_impl(PyByteArrayObject *self, Py_buffer *old,
140 Py_buffer *new, Py_ssize_t count);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300141
142static PyObject *
143bytearray_replace(PyByteArrayObject *self, PyObject *args)
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
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300150 if (!PyArg_ParseTuple(args, "y*y*|n:replace",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300151 &old, &new, &count)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300152 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300153 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300154 return_value = bytearray_replace_impl(self, &old, &new, count);
155
156exit:
157 /* Cleanup for old */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300158 if (old.obj) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300159 PyBuffer_Release(&old);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300160 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300161 /* Cleanup for new */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300162 if (new.obj) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300163 PyBuffer_Release(&new);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300164 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300165
166 return return_value;
167}
168
169PyDoc_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 \
Victor Stinner37e4ef72016-09-09 20:00:13 -0700184 {"split", (PyCFunction)bytearray_split, METH_FASTCALL, bytearray_split__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300185
186static PyObject *
Larry Hastings89964c42015-04-14 18:07:59 -0400187bytearray_split_impl(PyByteArrayObject *self, PyObject *sep,
188 Py_ssize_t maxsplit);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300189
190static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700191bytearray_split(PyByteArrayObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300192{
193 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300194 static const char * const _keywords[] = {"sep", "maxsplit", NULL};
195 static _PyArg_Parser _parser = {"|On:split", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300196 PyObject *sep = Py_None;
197 Py_ssize_t maxsplit = -1;
198
Victor Stinner37e4ef72016-09-09 20:00:13 -0700199 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300200 &sep, &maxsplit)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300201 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300202 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300203 return_value = bytearray_split_impl(self, sep, maxsplit);
204
205exit:
206 return return_value;
207}
208
209PyDoc_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"
217"separator itself, and the part after it.\n"
218"\n"
219"If the separator is not found, returns a 3-tuple containing the original\n"
220"bytearray object and two empty bytearray objects.");
221
222#define BYTEARRAY_PARTITION_METHODDEF \
223 {"partition", (PyCFunction)bytearray_partition, METH_O, bytearray_partition__doc__},
224
225PyDoc_STRVAR(bytearray_rpartition__doc__,
226"rpartition($self, sep, /)\n"
227"--\n"
228"\n"
229"Partition the bytes into three parts using the given separator.\n"
230"\n"
231"This will search for the separator sep in the bytearray, starting and the end.\n"
232"If the separator is found, returns a 3-tuple containing the part before the\n"
233"separator, the separator itself, and the part after it.\n"
234"\n"
235"If the separator is not found, returns a 3-tuple containing two empty bytearray\n"
236"objects and the original bytearray object.");
237
238#define BYTEARRAY_RPARTITION_METHODDEF \
239 {"rpartition", (PyCFunction)bytearray_rpartition, METH_O, bytearray_rpartition__doc__},
240
241PyDoc_STRVAR(bytearray_rsplit__doc__,
242"rsplit($self, /, sep=None, maxsplit=-1)\n"
243"--\n"
244"\n"
245"Return a list of the sections in the bytearray, using sep as the delimiter.\n"
246"\n"
247" sep\n"
248" The delimiter according which to split the bytearray.\n"
249" None (the default value) means split on ASCII whitespace characters\n"
250" (space, tab, return, newline, formfeed, vertical tab).\n"
251" maxsplit\n"
252" Maximum number of splits to do.\n"
253" -1 (the default value) means no limit.\n"
254"\n"
255"Splitting is done starting at the end of the bytearray and working to the front.");
256
257#define BYTEARRAY_RSPLIT_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -0700258 {"rsplit", (PyCFunction)bytearray_rsplit, METH_FASTCALL, bytearray_rsplit__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300259
260static PyObject *
Larry Hastings89964c42015-04-14 18:07:59 -0400261bytearray_rsplit_impl(PyByteArrayObject *self, PyObject *sep,
262 Py_ssize_t maxsplit);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300263
264static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700265bytearray_rsplit(PyByteArrayObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300266{
267 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300268 static const char * const _keywords[] = {"sep", "maxsplit", NULL};
269 static _PyArg_Parser _parser = {"|On:rsplit", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300270 PyObject *sep = Py_None;
271 Py_ssize_t maxsplit = -1;
272
Victor Stinner37e4ef72016-09-09 20:00:13 -0700273 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300274 &sep, &maxsplit)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300275 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300276 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300277 return_value = bytearray_rsplit_impl(self, sep, maxsplit);
278
279exit:
280 return return_value;
281}
282
283PyDoc_STRVAR(bytearray_reverse__doc__,
284"reverse($self, /)\n"
285"--\n"
286"\n"
287"Reverse the order of the values in B in place.");
288
289#define BYTEARRAY_REVERSE_METHODDEF \
290 {"reverse", (PyCFunction)bytearray_reverse, METH_NOARGS, bytearray_reverse__doc__},
291
292static PyObject *
293bytearray_reverse_impl(PyByteArrayObject *self);
294
295static PyObject *
296bytearray_reverse(PyByteArrayObject *self, PyObject *Py_UNUSED(ignored))
297{
298 return bytearray_reverse_impl(self);
299}
300
301PyDoc_STRVAR(bytearray_insert__doc__,
302"insert($self, index, item, /)\n"
303"--\n"
304"\n"
305"Insert a single item into the bytearray before the given index.\n"
306"\n"
307" index\n"
308" The index where the value is to be inserted.\n"
309" item\n"
310" The item to be inserted.");
311
312#define BYTEARRAY_INSERT_METHODDEF \
313 {"insert", (PyCFunction)bytearray_insert, METH_VARARGS, bytearray_insert__doc__},
314
315static PyObject *
316bytearray_insert_impl(PyByteArrayObject *self, Py_ssize_t index, int item);
317
318static PyObject *
319bytearray_insert(PyByteArrayObject *self, PyObject *args)
320{
321 PyObject *return_value = NULL;
322 Py_ssize_t index;
323 int item;
324
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300325 if (!PyArg_ParseTuple(args, "nO&:insert",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300326 &index, _getbytevalue, &item)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300327 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300328 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300329 return_value = bytearray_insert_impl(self, index, item);
330
331exit:
332 return return_value;
333}
334
335PyDoc_STRVAR(bytearray_append__doc__,
336"append($self, item, /)\n"
337"--\n"
338"\n"
339"Append a single item to the end of the bytearray.\n"
340"\n"
341" item\n"
342" The item to be appended.");
343
344#define BYTEARRAY_APPEND_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300345 {"append", (PyCFunction)bytearray_append, METH_O, bytearray_append__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300346
347static PyObject *
348bytearray_append_impl(PyByteArrayObject *self, int item);
349
350static PyObject *
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300351bytearray_append(PyByteArrayObject *self, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300352{
353 PyObject *return_value = NULL;
354 int item;
355
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300356 if (!PyArg_Parse(arg, "O&:append", _getbytevalue, &item)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300357 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300358 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300359 return_value = bytearray_append_impl(self, item);
360
361exit:
362 return return_value;
363}
364
365PyDoc_STRVAR(bytearray_extend__doc__,
366"extend($self, iterable_of_ints, /)\n"
367"--\n"
368"\n"
369"Append all the items from the iterator or sequence to the end of the bytearray.\n"
370"\n"
371" iterable_of_ints\n"
372" The iterable of items to append.");
373
374#define BYTEARRAY_EXTEND_METHODDEF \
375 {"extend", (PyCFunction)bytearray_extend, METH_O, bytearray_extend__doc__},
376
377PyDoc_STRVAR(bytearray_pop__doc__,
378"pop($self, index=-1, /)\n"
379"--\n"
380"\n"
381"Remove and return a single item from B.\n"
382"\n"
383" index\n"
384" The index from where to remove the item.\n"
385" -1 (the default value) means remove the last item.\n"
386"\n"
387"If no index argument is given, will pop the last item.");
388
389#define BYTEARRAY_POP_METHODDEF \
390 {"pop", (PyCFunction)bytearray_pop, METH_VARARGS, bytearray_pop__doc__},
391
392static PyObject *
393bytearray_pop_impl(PyByteArrayObject *self, Py_ssize_t index);
394
395static PyObject *
396bytearray_pop(PyByteArrayObject *self, PyObject *args)
397{
398 PyObject *return_value = NULL;
399 Py_ssize_t index = -1;
400
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300401 if (!PyArg_ParseTuple(args, "|n:pop",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300402 &index)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300403 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300404 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300405 return_value = bytearray_pop_impl(self, index);
406
407exit:
408 return return_value;
409}
410
411PyDoc_STRVAR(bytearray_remove__doc__,
412"remove($self, value, /)\n"
413"--\n"
414"\n"
415"Remove the first occurrence of a value in the bytearray.\n"
416"\n"
417" value\n"
418" The value to remove.");
419
420#define BYTEARRAY_REMOVE_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300421 {"remove", (PyCFunction)bytearray_remove, METH_O, bytearray_remove__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300422
423static PyObject *
424bytearray_remove_impl(PyByteArrayObject *self, int value);
425
426static PyObject *
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300427bytearray_remove(PyByteArrayObject *self, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300428{
429 PyObject *return_value = NULL;
430 int value;
431
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300432 if (!PyArg_Parse(arg, "O&:remove", _getbytevalue, &value)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300433 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300434 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300435 return_value = bytearray_remove_impl(self, value);
436
437exit:
438 return return_value;
439}
440
441PyDoc_STRVAR(bytearray_strip__doc__,
442"strip($self, bytes=None, /)\n"
443"--\n"
444"\n"
445"Strip leading and trailing bytes contained in the argument.\n"
446"\n"
447"If the argument is omitted or None, strip leading and trailing ASCII whitespace.");
448
449#define BYTEARRAY_STRIP_METHODDEF \
450 {"strip", (PyCFunction)bytearray_strip, METH_VARARGS, bytearray_strip__doc__},
451
452static PyObject *
453bytearray_strip_impl(PyByteArrayObject *self, PyObject *bytes);
454
455static PyObject *
456bytearray_strip(PyByteArrayObject *self, PyObject *args)
457{
458 PyObject *return_value = NULL;
459 PyObject *bytes = Py_None;
460
461 if (!PyArg_UnpackTuple(args, "strip",
462 0, 1,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300463 &bytes)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300464 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300465 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300466 return_value = bytearray_strip_impl(self, bytes);
467
468exit:
469 return return_value;
470}
471
472PyDoc_STRVAR(bytearray_lstrip__doc__,
473"lstrip($self, bytes=None, /)\n"
474"--\n"
475"\n"
476"Strip leading bytes contained in the argument.\n"
477"\n"
478"If the argument is omitted or None, strip leading ASCII whitespace.");
479
480#define BYTEARRAY_LSTRIP_METHODDEF \
481 {"lstrip", (PyCFunction)bytearray_lstrip, METH_VARARGS, bytearray_lstrip__doc__},
482
483static PyObject *
484bytearray_lstrip_impl(PyByteArrayObject *self, PyObject *bytes);
485
486static PyObject *
487bytearray_lstrip(PyByteArrayObject *self, PyObject *args)
488{
489 PyObject *return_value = NULL;
490 PyObject *bytes = Py_None;
491
492 if (!PyArg_UnpackTuple(args, "lstrip",
493 0, 1,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300494 &bytes)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300495 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300496 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300497 return_value = bytearray_lstrip_impl(self, bytes);
498
499exit:
500 return return_value;
501}
502
503PyDoc_STRVAR(bytearray_rstrip__doc__,
504"rstrip($self, bytes=None, /)\n"
505"--\n"
506"\n"
507"Strip trailing bytes contained in the argument.\n"
508"\n"
509"If the argument is omitted or None, strip trailing ASCII whitespace.");
510
511#define BYTEARRAY_RSTRIP_METHODDEF \
512 {"rstrip", (PyCFunction)bytearray_rstrip, METH_VARARGS, bytearray_rstrip__doc__},
513
514static PyObject *
515bytearray_rstrip_impl(PyByteArrayObject *self, PyObject *bytes);
516
517static PyObject *
518bytearray_rstrip(PyByteArrayObject *self, PyObject *args)
519{
520 PyObject *return_value = NULL;
521 PyObject *bytes = Py_None;
522
523 if (!PyArg_UnpackTuple(args, "rstrip",
524 0, 1,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300525 &bytes)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300526 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300527 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300528 return_value = bytearray_rstrip_impl(self, bytes);
529
530exit:
531 return return_value;
532}
533
534PyDoc_STRVAR(bytearray_decode__doc__,
535"decode($self, /, encoding=\'utf-8\', errors=\'strict\')\n"
536"--\n"
537"\n"
538"Decode the bytearray using the codec registered for encoding.\n"
539"\n"
540" encoding\n"
541" The encoding with which to decode the bytearray.\n"
542" errors\n"
543" The error handling scheme to use for the handling of decoding errors.\n"
544" The default is \'strict\' meaning that decoding errors raise a\n"
545" UnicodeDecodeError. Other possible values are \'ignore\' and \'replace\'\n"
546" as well as any other name registered with codecs.register_error that\n"
547" can handle UnicodeDecodeErrors.");
548
549#define BYTEARRAY_DECODE_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -0700550 {"decode", (PyCFunction)bytearray_decode, METH_FASTCALL, bytearray_decode__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300551
552static PyObject *
Larry Hastings89964c42015-04-14 18:07:59 -0400553bytearray_decode_impl(PyByteArrayObject *self, const char *encoding,
554 const char *errors);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300555
556static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700557bytearray_decode(PyByteArrayObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300558{
559 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300560 static const char * const _keywords[] = {"encoding", "errors", NULL};
561 static _PyArg_Parser _parser = {"|ss:decode", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300562 const char *encoding = NULL;
563 const char *errors = NULL;
564
Victor Stinner37e4ef72016-09-09 20:00:13 -0700565 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300566 &encoding, &errors)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300567 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300568 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300569 return_value = bytearray_decode_impl(self, encoding, errors);
570
571exit:
572 return return_value;
573}
574
575PyDoc_STRVAR(bytearray_join__doc__,
576"join($self, iterable_of_bytes, /)\n"
577"--\n"
578"\n"
579"Concatenate any number of bytes/bytearray objects.\n"
580"\n"
581"The bytearray whose method is called is inserted in between each pair.\n"
582"\n"
583"The result is returned as a new bytearray object.");
584
585#define BYTEARRAY_JOIN_METHODDEF \
586 {"join", (PyCFunction)bytearray_join, METH_O, bytearray_join__doc__},
587
588PyDoc_STRVAR(bytearray_splitlines__doc__,
589"splitlines($self, /, keepends=False)\n"
590"--\n"
591"\n"
592"Return a list of the lines in the bytearray, breaking at line boundaries.\n"
593"\n"
594"Line breaks are not included in the resulting list unless keepends is given and\n"
595"true.");
596
597#define BYTEARRAY_SPLITLINES_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -0700598 {"splitlines", (PyCFunction)bytearray_splitlines, METH_FASTCALL, bytearray_splitlines__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300599
600static PyObject *
601bytearray_splitlines_impl(PyByteArrayObject *self, int keepends);
602
603static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700604bytearray_splitlines(PyByteArrayObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300605{
606 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300607 static const char * const _keywords[] = {"keepends", NULL};
608 static _PyArg_Parser _parser = {"|i:splitlines", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300609 int keepends = 0;
610
Victor Stinner37e4ef72016-09-09 20:00:13 -0700611 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300612 &keepends)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300613 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300614 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300615 return_value = bytearray_splitlines_impl(self, keepends);
616
617exit:
618 return return_value;
619}
620
621PyDoc_STRVAR(bytearray_fromhex__doc__,
622"fromhex($type, string, /)\n"
623"--\n"
624"\n"
625"Create a bytearray object from a string of hexadecimal numbers.\n"
626"\n"
627"Spaces between two numbers are accepted.\n"
628"Example: bytearray.fromhex(\'B9 01EF\') -> bytearray(b\'\\\\xb9\\\\x01\\\\xef\')");
629
630#define BYTEARRAY_FROMHEX_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300631 {"fromhex", (PyCFunction)bytearray_fromhex, METH_O|METH_CLASS, bytearray_fromhex__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300632
633static PyObject *
Serhiy Storchaka0855e702016-07-01 17:22:31 +0300634bytearray_fromhex_impl(PyTypeObject *type, PyObject *string);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300635
636static PyObject *
Serhiy Storchaka0855e702016-07-01 17:22:31 +0300637bytearray_fromhex(PyTypeObject *type, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300638{
639 PyObject *return_value = NULL;
640 PyObject *string;
641
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300642 if (!PyArg_Parse(arg, "U:fromhex", &string)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300643 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300644 }
Serhiy Storchaka0855e702016-07-01 17:22:31 +0300645 return_value = bytearray_fromhex_impl(type, string);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300646
647exit:
648 return return_value;
649}
650
651PyDoc_STRVAR(bytearray_reduce__doc__,
652"__reduce__($self, /)\n"
653"--\n"
654"\n"
655"Return state information for pickling.");
656
657#define BYTEARRAY_REDUCE_METHODDEF \
658 {"__reduce__", (PyCFunction)bytearray_reduce, METH_NOARGS, bytearray_reduce__doc__},
659
660static PyObject *
661bytearray_reduce_impl(PyByteArrayObject *self);
662
663static PyObject *
664bytearray_reduce(PyByteArrayObject *self, PyObject *Py_UNUSED(ignored))
665{
666 return bytearray_reduce_impl(self);
667}
668
669PyDoc_STRVAR(bytearray_reduce_ex__doc__,
670"__reduce_ex__($self, proto=0, /)\n"
671"--\n"
672"\n"
673"Return state information for pickling.");
674
675#define BYTEARRAY_REDUCE_EX_METHODDEF \
676 {"__reduce_ex__", (PyCFunction)bytearray_reduce_ex, METH_VARARGS, bytearray_reduce_ex__doc__},
677
678static PyObject *
679bytearray_reduce_ex_impl(PyByteArrayObject *self, int proto);
680
681static PyObject *
682bytearray_reduce_ex(PyByteArrayObject *self, PyObject *args)
683{
684 PyObject *return_value = NULL;
685 int proto = 0;
686
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300687 if (!PyArg_ParseTuple(args, "|i:__reduce_ex__",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300688 &proto)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300689 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300690 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300691 return_value = bytearray_reduce_ex_impl(self, proto);
692
693exit:
694 return return_value;
695}
696
697PyDoc_STRVAR(bytearray_sizeof__doc__,
698"__sizeof__($self, /)\n"
699"--\n"
700"\n"
701"Returns the size of the bytearray object in memory, in bytes.");
702
703#define BYTEARRAY_SIZEOF_METHODDEF \
704 {"__sizeof__", (PyCFunction)bytearray_sizeof, METH_NOARGS, bytearray_sizeof__doc__},
705
706static PyObject *
707bytearray_sizeof_impl(PyByteArrayObject *self);
708
709static PyObject *
710bytearray_sizeof(PyByteArrayObject *self, PyObject *Py_UNUSED(ignored))
711{
712 return bytearray_sizeof_impl(self);
713}
Victor Stinner37e4ef72016-09-09 20:00:13 -0700714/*[clinic end generated code: output=225342a680391b9c input=a9049054013a1b77]*/