blob: d45592be55952e758065170f9af1a6d7faa74020 [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 \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +030054 {"translate", (PyCFunction)bytearray_translate, METH_FASTCALL|METH_KEYWORDS, 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 *
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +030097bytearray_maketrans(void *null, PyObject **args, Py_ssize_t nargs)
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
Sylvain74453812017-06-10 06:51:48 +0200103 if (!_PyArg_ParseStack(args, nargs, "y*y*:maketrans",
104 &frm, &to)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100105 goto exit;
106 }
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 \
Victor Stinner259f0e42017-01-17 01:35:17 +0100136 {"replace", (PyCFunction)bytearray_replace, METH_FASTCALL, bytearray_replace__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300137
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 *
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +0300143bytearray_replace(PyByteArrayObject *self, PyObject **args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300144{
145 PyObject *return_value = NULL;
146 Py_buffer old = {NULL, NULL};
147 Py_buffer new = {NULL, NULL};
148 Py_ssize_t count = -1;
149
Sylvain74453812017-06-10 06:51:48 +0200150 if (!_PyArg_ParseStack(args, nargs, "y*y*|n:replace",
151 &old, &new, &count)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100152 goto exit;
153 }
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 \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +0300184 {"split", (PyCFunction)bytearray_split, METH_FASTCALL|METH_KEYWORDS, 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 Stinner3e1fad62017-01-17 01:29:01 +0100199 if (!_PyArg_ParseStackAndKeywords(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"
Serhiy Storchakaa2314282017-10-29 02:11:54 +0300217"separator itself, and the part after it as new bytearray objects.\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300218"\n"
Serhiy Storchakaa2314282017-10-29 02:11:54 +0300219"If the separator is not found, returns a 3-tuple containing the copy of the\n"
220"original bytearray object and two empty bytearray objects.");
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300221
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"
Serhiy Storchakaa2314282017-10-29 02:11:54 +0300229"Partition the bytearray into three parts using the given separator.\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300230"\n"
Serhiy Storchakaa2314282017-10-29 02:11:54 +0300231"This will search for the separator sep in the bytearray, starting at the end.\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300232"If the separator is found, returns a 3-tuple containing the part before the\n"
Serhiy Storchakaa2314282017-10-29 02:11:54 +0300233"separator, the separator itself, and the part after it as new bytearray\n"
234"objects.\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300235"\n"
236"If the separator is not found, returns a 3-tuple containing two empty bytearray\n"
Serhiy Storchakaa2314282017-10-29 02:11:54 +0300237"objects and the copy of the original bytearray object.");
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300238
239#define BYTEARRAY_RPARTITION_METHODDEF \
240 {"rpartition", (PyCFunction)bytearray_rpartition, METH_O, bytearray_rpartition__doc__},
241
242PyDoc_STRVAR(bytearray_rsplit__doc__,
243"rsplit($self, /, sep=None, maxsplit=-1)\n"
244"--\n"
245"\n"
246"Return a list of the sections in the bytearray, using sep as the delimiter.\n"
247"\n"
248" sep\n"
249" The delimiter according which to split the bytearray.\n"
250" None (the default value) means split on ASCII whitespace characters\n"
251" (space, tab, return, newline, formfeed, vertical tab).\n"
252" maxsplit\n"
253" Maximum number of splits to do.\n"
254" -1 (the default value) means no limit.\n"
255"\n"
256"Splitting is done starting at the end of the bytearray and working to the front.");
257
258#define BYTEARRAY_RSPLIT_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +0300259 {"rsplit", (PyCFunction)bytearray_rsplit, METH_FASTCALL|METH_KEYWORDS, bytearray_rsplit__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300260
261static PyObject *
Larry Hastings89964c42015-04-14 18:07:59 -0400262bytearray_rsplit_impl(PyByteArrayObject *self, PyObject *sep,
263 Py_ssize_t maxsplit);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300264
265static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700266bytearray_rsplit(PyByteArrayObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300267{
268 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300269 static const char * const _keywords[] = {"sep", "maxsplit", NULL};
270 static _PyArg_Parser _parser = {"|On:rsplit", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300271 PyObject *sep = Py_None;
272 Py_ssize_t maxsplit = -1;
273
Victor Stinner3e1fad62017-01-17 01:29:01 +0100274 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300275 &sep, &maxsplit)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300276 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300277 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300278 return_value = bytearray_rsplit_impl(self, sep, maxsplit);
279
280exit:
281 return return_value;
282}
283
284PyDoc_STRVAR(bytearray_reverse__doc__,
285"reverse($self, /)\n"
286"--\n"
287"\n"
288"Reverse the order of the values in B in place.");
289
290#define BYTEARRAY_REVERSE_METHODDEF \
291 {"reverse", (PyCFunction)bytearray_reverse, METH_NOARGS, bytearray_reverse__doc__},
292
293static PyObject *
294bytearray_reverse_impl(PyByteArrayObject *self);
295
296static PyObject *
297bytearray_reverse(PyByteArrayObject *self, PyObject *Py_UNUSED(ignored))
298{
299 return bytearray_reverse_impl(self);
300}
301
302PyDoc_STRVAR(bytearray_insert__doc__,
303"insert($self, index, item, /)\n"
304"--\n"
305"\n"
306"Insert a single item into the bytearray before the given index.\n"
307"\n"
308" index\n"
309" The index where the value is to be inserted.\n"
310" item\n"
311" The item to be inserted.");
312
313#define BYTEARRAY_INSERT_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +0100314 {"insert", (PyCFunction)bytearray_insert, METH_FASTCALL, bytearray_insert__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300315
316static PyObject *
317bytearray_insert_impl(PyByteArrayObject *self, Py_ssize_t index, int item);
318
319static PyObject *
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +0300320bytearray_insert(PyByteArrayObject *self, PyObject **args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300321{
322 PyObject *return_value = NULL;
323 Py_ssize_t index;
324 int item;
325
Sylvain74453812017-06-10 06:51:48 +0200326 if (!_PyArg_ParseStack(args, nargs, "nO&:insert",
327 &index, _getbytevalue, &item)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100328 goto exit;
329 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300330 return_value = bytearray_insert_impl(self, index, item);
331
332exit:
333 return return_value;
334}
335
336PyDoc_STRVAR(bytearray_append__doc__,
337"append($self, item, /)\n"
338"--\n"
339"\n"
340"Append a single item to the end of the bytearray.\n"
341"\n"
342" item\n"
343" The item to be appended.");
344
345#define BYTEARRAY_APPEND_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300346 {"append", (PyCFunction)bytearray_append, METH_O, bytearray_append__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300347
348static PyObject *
349bytearray_append_impl(PyByteArrayObject *self, int item);
350
351static PyObject *
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300352bytearray_append(PyByteArrayObject *self, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300353{
354 PyObject *return_value = NULL;
355 int item;
356
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300357 if (!PyArg_Parse(arg, "O&:append", _getbytevalue, &item)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300358 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300359 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300360 return_value = bytearray_append_impl(self, item);
361
362exit:
363 return return_value;
364}
365
366PyDoc_STRVAR(bytearray_extend__doc__,
367"extend($self, iterable_of_ints, /)\n"
368"--\n"
369"\n"
370"Append all the items from the iterator or sequence to the end of the bytearray.\n"
371"\n"
372" iterable_of_ints\n"
373" The iterable of items to append.");
374
375#define BYTEARRAY_EXTEND_METHODDEF \
376 {"extend", (PyCFunction)bytearray_extend, METH_O, bytearray_extend__doc__},
377
378PyDoc_STRVAR(bytearray_pop__doc__,
379"pop($self, index=-1, /)\n"
380"--\n"
381"\n"
382"Remove and return a single item from B.\n"
383"\n"
384" index\n"
385" The index from where to remove the item.\n"
386" -1 (the default value) means remove the last item.\n"
387"\n"
388"If no index argument is given, will pop the last item.");
389
390#define BYTEARRAY_POP_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +0100391 {"pop", (PyCFunction)bytearray_pop, METH_FASTCALL, bytearray_pop__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300392
393static PyObject *
394bytearray_pop_impl(PyByteArrayObject *self, Py_ssize_t index);
395
396static PyObject *
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +0300397bytearray_pop(PyByteArrayObject *self, PyObject **args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300398{
399 PyObject *return_value = NULL;
400 Py_ssize_t index = -1;
401
Sylvain74453812017-06-10 06:51:48 +0200402 if (!_PyArg_ParseStack(args, nargs, "|n:pop",
403 &index)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100404 goto exit;
405 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300406 return_value = bytearray_pop_impl(self, index);
407
408exit:
409 return return_value;
410}
411
412PyDoc_STRVAR(bytearray_remove__doc__,
413"remove($self, value, /)\n"
414"--\n"
415"\n"
416"Remove the first occurrence of a value in the bytearray.\n"
417"\n"
418" value\n"
419" The value to remove.");
420
421#define BYTEARRAY_REMOVE_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300422 {"remove", (PyCFunction)bytearray_remove, METH_O, bytearray_remove__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300423
424static PyObject *
425bytearray_remove_impl(PyByteArrayObject *self, int value);
426
427static PyObject *
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300428bytearray_remove(PyByteArrayObject *self, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300429{
430 PyObject *return_value = NULL;
431 int value;
432
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300433 if (!PyArg_Parse(arg, "O&:remove", _getbytevalue, &value)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300434 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300435 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300436 return_value = bytearray_remove_impl(self, value);
437
438exit:
439 return return_value;
440}
441
442PyDoc_STRVAR(bytearray_strip__doc__,
443"strip($self, bytes=None, /)\n"
444"--\n"
445"\n"
446"Strip leading and trailing bytes contained in the argument.\n"
447"\n"
448"If the argument is omitted or None, strip leading and trailing ASCII whitespace.");
449
450#define BYTEARRAY_STRIP_METHODDEF \
Victor Stinner0c4a8282017-01-17 02:21:47 +0100451 {"strip", (PyCFunction)bytearray_strip, METH_FASTCALL, bytearray_strip__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300452
453static PyObject *
454bytearray_strip_impl(PyByteArrayObject *self, PyObject *bytes);
455
456static PyObject *
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +0300457bytearray_strip(PyByteArrayObject *self, PyObject **args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300458{
459 PyObject *return_value = NULL;
460 PyObject *bytes = Py_None;
461
Sylvain74453812017-06-10 06:51:48 +0200462 if (!_PyArg_UnpackStack(args, nargs, "strip",
463 0, 1,
464 &bytes)) {
Victor Stinner0c4a8282017-01-17 02:21:47 +0100465 goto exit;
466 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300467 return_value = bytearray_strip_impl(self, bytes);
468
469exit:
470 return return_value;
471}
472
473PyDoc_STRVAR(bytearray_lstrip__doc__,
474"lstrip($self, bytes=None, /)\n"
475"--\n"
476"\n"
477"Strip leading bytes contained in the argument.\n"
478"\n"
479"If the argument is omitted or None, strip leading ASCII whitespace.");
480
481#define BYTEARRAY_LSTRIP_METHODDEF \
Victor Stinner0c4a8282017-01-17 02:21:47 +0100482 {"lstrip", (PyCFunction)bytearray_lstrip, METH_FASTCALL, bytearray_lstrip__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300483
484static PyObject *
485bytearray_lstrip_impl(PyByteArrayObject *self, PyObject *bytes);
486
487static PyObject *
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +0300488bytearray_lstrip(PyByteArrayObject *self, PyObject **args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300489{
490 PyObject *return_value = NULL;
491 PyObject *bytes = Py_None;
492
Sylvain74453812017-06-10 06:51:48 +0200493 if (!_PyArg_UnpackStack(args, nargs, "lstrip",
494 0, 1,
495 &bytes)) {
Victor Stinner0c4a8282017-01-17 02:21:47 +0100496 goto exit;
497 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300498 return_value = bytearray_lstrip_impl(self, bytes);
499
500exit:
501 return return_value;
502}
503
504PyDoc_STRVAR(bytearray_rstrip__doc__,
505"rstrip($self, bytes=None, /)\n"
506"--\n"
507"\n"
508"Strip trailing bytes contained in the argument.\n"
509"\n"
510"If the argument is omitted or None, strip trailing ASCII whitespace.");
511
512#define BYTEARRAY_RSTRIP_METHODDEF \
Victor Stinner0c4a8282017-01-17 02:21:47 +0100513 {"rstrip", (PyCFunction)bytearray_rstrip, METH_FASTCALL, bytearray_rstrip__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300514
515static PyObject *
516bytearray_rstrip_impl(PyByteArrayObject *self, PyObject *bytes);
517
518static PyObject *
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +0300519bytearray_rstrip(PyByteArrayObject *self, PyObject **args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300520{
521 PyObject *return_value = NULL;
522 PyObject *bytes = Py_None;
523
Sylvain74453812017-06-10 06:51:48 +0200524 if (!_PyArg_UnpackStack(args, nargs, "rstrip",
525 0, 1,
526 &bytes)) {
Victor Stinner0c4a8282017-01-17 02:21:47 +0100527 goto exit;
528 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300529 return_value = bytearray_rstrip_impl(self, bytes);
530
531exit:
532 return return_value;
533}
534
535PyDoc_STRVAR(bytearray_decode__doc__,
536"decode($self, /, encoding=\'utf-8\', errors=\'strict\')\n"
537"--\n"
538"\n"
539"Decode the bytearray using the codec registered for encoding.\n"
540"\n"
541" encoding\n"
542" The encoding with which to decode the bytearray.\n"
543" errors\n"
544" The error handling scheme to use for the handling of decoding errors.\n"
545" The default is \'strict\' meaning that decoding errors raise a\n"
546" UnicodeDecodeError. Other possible values are \'ignore\' and \'replace\'\n"
547" as well as any other name registered with codecs.register_error that\n"
548" can handle UnicodeDecodeErrors.");
549
550#define BYTEARRAY_DECODE_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +0300551 {"decode", (PyCFunction)bytearray_decode, METH_FASTCALL|METH_KEYWORDS, bytearray_decode__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300552
553static PyObject *
Larry Hastings89964c42015-04-14 18:07:59 -0400554bytearray_decode_impl(PyByteArrayObject *self, const char *encoding,
555 const char *errors);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300556
557static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700558bytearray_decode(PyByteArrayObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300559{
560 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300561 static const char * const _keywords[] = {"encoding", "errors", NULL};
562 static _PyArg_Parser _parser = {"|ss:decode", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300563 const char *encoding = NULL;
564 const char *errors = NULL;
565
Victor Stinner3e1fad62017-01-17 01:29:01 +0100566 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300567 &encoding, &errors)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300568 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300569 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300570 return_value = bytearray_decode_impl(self, encoding, errors);
571
572exit:
573 return return_value;
574}
575
576PyDoc_STRVAR(bytearray_join__doc__,
577"join($self, iterable_of_bytes, /)\n"
578"--\n"
579"\n"
580"Concatenate any number of bytes/bytearray objects.\n"
581"\n"
582"The bytearray whose method is called is inserted in between each pair.\n"
583"\n"
584"The result is returned as a new bytearray object.");
585
586#define BYTEARRAY_JOIN_METHODDEF \
587 {"join", (PyCFunction)bytearray_join, METH_O, bytearray_join__doc__},
588
589PyDoc_STRVAR(bytearray_splitlines__doc__,
590"splitlines($self, /, keepends=False)\n"
591"--\n"
592"\n"
593"Return a list of the lines in the bytearray, breaking at line boundaries.\n"
594"\n"
595"Line breaks are not included in the resulting list unless keepends is given and\n"
596"true.");
597
598#define BYTEARRAY_SPLITLINES_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +0300599 {"splitlines", (PyCFunction)bytearray_splitlines, METH_FASTCALL|METH_KEYWORDS, bytearray_splitlines__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300600
601static PyObject *
602bytearray_splitlines_impl(PyByteArrayObject *self, int keepends);
603
604static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700605bytearray_splitlines(PyByteArrayObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300606{
607 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300608 static const char * const _keywords[] = {"keepends", NULL};
609 static _PyArg_Parser _parser = {"|i:splitlines", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300610 int keepends = 0;
611
Victor Stinner3e1fad62017-01-17 01:29:01 +0100612 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300613 &keepends)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300614 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300615 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300616 return_value = bytearray_splitlines_impl(self, keepends);
617
618exit:
619 return return_value;
620}
621
622PyDoc_STRVAR(bytearray_fromhex__doc__,
623"fromhex($type, string, /)\n"
624"--\n"
625"\n"
626"Create a bytearray object from a string of hexadecimal numbers.\n"
627"\n"
628"Spaces between two numbers are accepted.\n"
629"Example: bytearray.fromhex(\'B9 01EF\') -> bytearray(b\'\\\\xb9\\\\x01\\\\xef\')");
630
631#define BYTEARRAY_FROMHEX_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300632 {"fromhex", (PyCFunction)bytearray_fromhex, METH_O|METH_CLASS, bytearray_fromhex__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300633
634static PyObject *
Serhiy Storchaka0855e702016-07-01 17:22:31 +0300635bytearray_fromhex_impl(PyTypeObject *type, PyObject *string);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300636
637static PyObject *
Serhiy Storchaka0855e702016-07-01 17:22:31 +0300638bytearray_fromhex(PyTypeObject *type, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300639{
640 PyObject *return_value = NULL;
641 PyObject *string;
642
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300643 if (!PyArg_Parse(arg, "U:fromhex", &string)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300644 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300645 }
Serhiy Storchaka0855e702016-07-01 17:22:31 +0300646 return_value = bytearray_fromhex_impl(type, string);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300647
648exit:
649 return return_value;
650}
651
652PyDoc_STRVAR(bytearray_reduce__doc__,
653"__reduce__($self, /)\n"
654"--\n"
655"\n"
656"Return state information for pickling.");
657
658#define BYTEARRAY_REDUCE_METHODDEF \
659 {"__reduce__", (PyCFunction)bytearray_reduce, METH_NOARGS, bytearray_reduce__doc__},
660
661static PyObject *
662bytearray_reduce_impl(PyByteArrayObject *self);
663
664static PyObject *
665bytearray_reduce(PyByteArrayObject *self, PyObject *Py_UNUSED(ignored))
666{
667 return bytearray_reduce_impl(self);
668}
669
670PyDoc_STRVAR(bytearray_reduce_ex__doc__,
671"__reduce_ex__($self, proto=0, /)\n"
672"--\n"
673"\n"
674"Return state information for pickling.");
675
676#define BYTEARRAY_REDUCE_EX_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +0100677 {"__reduce_ex__", (PyCFunction)bytearray_reduce_ex, METH_FASTCALL, bytearray_reduce_ex__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300678
679static PyObject *
680bytearray_reduce_ex_impl(PyByteArrayObject *self, int proto);
681
682static PyObject *
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +0300683bytearray_reduce_ex(PyByteArrayObject *self, PyObject **args, Py_ssize_t nargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300684{
685 PyObject *return_value = NULL;
686 int proto = 0;
687
Sylvain74453812017-06-10 06:51:48 +0200688 if (!_PyArg_ParseStack(args, nargs, "|i:__reduce_ex__",
689 &proto)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100690 goto exit;
691 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300692 return_value = bytearray_reduce_ex_impl(self, proto);
693
694exit:
695 return return_value;
696}
697
698PyDoc_STRVAR(bytearray_sizeof__doc__,
699"__sizeof__($self, /)\n"
700"--\n"
701"\n"
702"Returns the size of the bytearray object in memory, in bytes.");
703
704#define BYTEARRAY_SIZEOF_METHODDEF \
705 {"__sizeof__", (PyCFunction)bytearray_sizeof, METH_NOARGS, bytearray_sizeof__doc__},
706
707static PyObject *
708bytearray_sizeof_impl(PyByteArrayObject *self);
709
710static PyObject *
711bytearray_sizeof(PyByteArrayObject *self, PyObject *Py_UNUSED(ignored))
712{
713 return bytearray_sizeof_impl(self);
714}
Serhiy Storchakaa2314282017-10-29 02:11:54 +0300715/*[clinic end generated code: output=c2804d009182328c input=a9049054013a1b77]*/