blob: 8363dbdd8ed3a777d376e210e2d2ac43b7b00ad8 [file] [log] [blame]
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001/*[clinic input]
2preserve
3[clinic start generated code]*/
4
5PyDoc_STRVAR(bytearray_clear__doc__,
6"clear($self, /)\n"
7"--\n"
8"\n"
9"Remove all items from the bytearray.");
10
11#define BYTEARRAY_CLEAR_METHODDEF \
12 {"clear", (PyCFunction)bytearray_clear, METH_NOARGS, bytearray_clear__doc__},
13
14static PyObject *
15bytearray_clear_impl(PyByteArrayObject *self);
16
17static PyObject *
18bytearray_clear(PyByteArrayObject *self, PyObject *Py_UNUSED(ignored))
19{
20 return bytearray_clear_impl(self);
21}
22
23PyDoc_STRVAR(bytearray_copy__doc__,
24"copy($self, /)\n"
25"--\n"
26"\n"
27"Return a copy of B.");
28
29#define BYTEARRAY_COPY_METHODDEF \
30 {"copy", (PyCFunction)bytearray_copy, METH_NOARGS, bytearray_copy__doc__},
31
32static PyObject *
33bytearray_copy_impl(PyByteArrayObject *self);
34
35static PyObject *
36bytearray_copy(PyByteArrayObject *self, PyObject *Py_UNUSED(ignored))
37{
38 return bytearray_copy_impl(self);
39}
40
41PyDoc_STRVAR(bytearray_translate__doc__,
Martin Panter1b6c6da2016-08-27 08:35:02 +000042"translate($self, table, /, delete=b\'\')\n"
43"--\n"
44"\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030045"Return a copy with each character mapped by the given translation table.\n"
46"\n"
47" table\n"
48" Translation table, which must be a bytes object of length 256.\n"
49"\n"
Martin Panter1b6c6da2016-08-27 08:35:02 +000050"All characters occurring in the optional argument delete are removed.\n"
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030051"The remaining characters are mapped through the given translation table.");
52
53#define BYTEARRAY_TRANSLATE_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -070054 {"translate", (PyCFunction)bytearray_translate, METH_FASTCALL, bytearray_translate__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030055
56static PyObject *
Larry Hastings89964c42015-04-14 18:07:59 -040057bytearray_translate_impl(PyByteArrayObject *self, PyObject *table,
Martin Panter1b6c6da2016-08-27 08:35:02 +000058 PyObject *deletechars);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030059
60static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -070061bytearray_translate(PyByteArrayObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030062{
63 PyObject *return_value = NULL;
Martin Panter1b6c6da2016-08-27 08:35:02 +000064 static const char * const _keywords[] = {"", "delete", NULL};
65 static _PyArg_Parser _parser = {"O|O:translate", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030066 PyObject *table;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030067 PyObject *deletechars = NULL;
68
Victor Stinner3e1fad62017-01-17 01:29:01 +010069 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Martin Panter1b6c6da2016-08-27 08:35:02 +000070 &table, &deletechars)) {
71 goto exit;
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030072 }
Martin Panter1b6c6da2016-08-27 08:35:02 +000073 return_value = bytearray_translate_impl(self, table, deletechars);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030074
75exit:
76 return return_value;
77}
78
79PyDoc_STRVAR(bytearray_maketrans__doc__,
80"maketrans(frm, to, /)\n"
81"--\n"
82"\n"
83"Return a translation table useable for the bytes or bytearray translate method.\n"
84"\n"
85"The returned table will be one where each byte in frm is mapped to the byte at\n"
86"the same position in to.\n"
87"\n"
88"The bytes objects frm and to must be of the same length.");
89
90#define BYTEARRAY_MAKETRANS_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +010091 {"maketrans", (PyCFunction)bytearray_maketrans, METH_FASTCALL|METH_STATIC, bytearray_maketrans__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030092
93static PyObject *
94bytearray_maketrans_impl(Py_buffer *frm, Py_buffer *to);
95
96static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +010097bytearray_maketrans(void *null, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030098{
99 PyObject *return_value = NULL;
100 Py_buffer frm = {NULL, NULL};
101 Py_buffer to = {NULL, NULL};
102
Sylvain74453812017-06-10 06:51:48 +0200103 if (!_PyArg_NoStackKeywords("maketrans", kwnames)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300104 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300105 }
Victor Stinner259f0e42017-01-17 01:35:17 +0100106
Sylvain74453812017-06-10 06:51:48 +0200107 if (!_PyArg_ParseStack(args, nargs, "y*y*:maketrans",
108 &frm, &to)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100109 goto exit;
110 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300111 return_value = bytearray_maketrans_impl(&frm, &to);
112
113exit:
114 /* Cleanup for frm */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300115 if (frm.obj) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300116 PyBuffer_Release(&frm);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300117 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300118 /* Cleanup for to */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300119 if (to.obj) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300120 PyBuffer_Release(&to);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300121 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300122
123 return return_value;
124}
125
126PyDoc_STRVAR(bytearray_replace__doc__,
127"replace($self, old, new, count=-1, /)\n"
128"--\n"
129"\n"
130"Return a copy with all occurrences of substring old replaced by new.\n"
131"\n"
132" count\n"
133" Maximum number of occurrences to replace.\n"
134" -1 (the default value) means replace all occurrences.\n"
135"\n"
136"If the optional argument count is given, only the first count occurrences are\n"
137"replaced.");
138
139#define BYTEARRAY_REPLACE_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +0100140 {"replace", (PyCFunction)bytearray_replace, METH_FASTCALL, bytearray_replace__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300141
142static PyObject *
Larry Hastings89964c42015-04-14 18:07:59 -0400143bytearray_replace_impl(PyByteArrayObject *self, Py_buffer *old,
144 Py_buffer *new, Py_ssize_t count);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300145
146static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +0100147bytearray_replace(PyByteArrayObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300148{
149 PyObject *return_value = NULL;
150 Py_buffer old = {NULL, NULL};
151 Py_buffer new = {NULL, NULL};
152 Py_ssize_t count = -1;
153
Sylvain74453812017-06-10 06:51:48 +0200154 if (!_PyArg_NoStackKeywords("replace", kwnames)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300155 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300156 }
Victor Stinner259f0e42017-01-17 01:35:17 +0100157
Sylvain74453812017-06-10 06:51:48 +0200158 if (!_PyArg_ParseStack(args, nargs, "y*y*|n:replace",
159 &old, &new, &count)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100160 goto exit;
161 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300162 return_value = bytearray_replace_impl(self, &old, &new, count);
163
164exit:
165 /* Cleanup for old */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300166 if (old.obj) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300167 PyBuffer_Release(&old);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300168 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300169 /* Cleanup for new */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300170 if (new.obj) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300171 PyBuffer_Release(&new);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300172 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300173
174 return return_value;
175}
176
177PyDoc_STRVAR(bytearray_split__doc__,
178"split($self, /, sep=None, maxsplit=-1)\n"
179"--\n"
180"\n"
181"Return a list of the sections in the bytearray, using sep as the delimiter.\n"
182"\n"
183" sep\n"
184" The delimiter according which to split the bytearray.\n"
185" None (the default value) means split on ASCII whitespace characters\n"
186" (space, tab, return, newline, formfeed, vertical tab).\n"
187" maxsplit\n"
188" Maximum number of splits to do.\n"
189" -1 (the default value) means no limit.");
190
191#define BYTEARRAY_SPLIT_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -0700192 {"split", (PyCFunction)bytearray_split, METH_FASTCALL, bytearray_split__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300193
194static PyObject *
Larry Hastings89964c42015-04-14 18:07:59 -0400195bytearray_split_impl(PyByteArrayObject *self, PyObject *sep,
196 Py_ssize_t maxsplit);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300197
198static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700199bytearray_split(PyByteArrayObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300200{
201 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300202 static const char * const _keywords[] = {"sep", "maxsplit", NULL};
203 static _PyArg_Parser _parser = {"|On:split", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300204 PyObject *sep = Py_None;
205 Py_ssize_t maxsplit = -1;
206
Victor Stinner3e1fad62017-01-17 01:29:01 +0100207 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300208 &sep, &maxsplit)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300209 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300210 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300211 return_value = bytearray_split_impl(self, sep, maxsplit);
212
213exit:
214 return return_value;
215}
216
217PyDoc_STRVAR(bytearray_partition__doc__,
218"partition($self, sep, /)\n"
219"--\n"
220"\n"
221"Partition the bytearray into three parts using the given separator.\n"
222"\n"
223"This will search for the separator sep in the bytearray. If the separator is\n"
224"found, returns a 3-tuple containing the part before the separator, the\n"
225"separator itself, and the part after it.\n"
226"\n"
227"If the separator is not found, returns a 3-tuple containing the original\n"
228"bytearray object and two empty bytearray objects.");
229
230#define BYTEARRAY_PARTITION_METHODDEF \
231 {"partition", (PyCFunction)bytearray_partition, METH_O, bytearray_partition__doc__},
232
233PyDoc_STRVAR(bytearray_rpartition__doc__,
234"rpartition($self, sep, /)\n"
235"--\n"
236"\n"
237"Partition the bytes into three parts using the given separator.\n"
238"\n"
239"This will search for the separator sep in the bytearray, starting and the end.\n"
240"If the separator is found, returns a 3-tuple containing the part before the\n"
241"separator, the separator itself, and the part after it.\n"
242"\n"
243"If the separator is not found, returns a 3-tuple containing two empty bytearray\n"
244"objects and the original bytearray object.");
245
246#define BYTEARRAY_RPARTITION_METHODDEF \
247 {"rpartition", (PyCFunction)bytearray_rpartition, METH_O, bytearray_rpartition__doc__},
248
249PyDoc_STRVAR(bytearray_rsplit__doc__,
250"rsplit($self, /, sep=None, maxsplit=-1)\n"
251"--\n"
252"\n"
253"Return a list of the sections in the bytearray, using sep as the delimiter.\n"
254"\n"
255" sep\n"
256" The delimiter according which to split the bytearray.\n"
257" None (the default value) means split on ASCII whitespace characters\n"
258" (space, tab, return, newline, formfeed, vertical tab).\n"
259" maxsplit\n"
260" Maximum number of splits to do.\n"
261" -1 (the default value) means no limit.\n"
262"\n"
263"Splitting is done starting at the end of the bytearray and working to the front.");
264
265#define BYTEARRAY_RSPLIT_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -0700266 {"rsplit", (PyCFunction)bytearray_rsplit, METH_FASTCALL, bytearray_rsplit__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300267
268static PyObject *
Larry Hastings89964c42015-04-14 18:07:59 -0400269bytearray_rsplit_impl(PyByteArrayObject *self, PyObject *sep,
270 Py_ssize_t maxsplit);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300271
272static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700273bytearray_rsplit(PyByteArrayObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300274{
275 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300276 static const char * const _keywords[] = {"sep", "maxsplit", NULL};
277 static _PyArg_Parser _parser = {"|On:rsplit", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300278 PyObject *sep = Py_None;
279 Py_ssize_t maxsplit = -1;
280
Victor Stinner3e1fad62017-01-17 01:29:01 +0100281 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300282 &sep, &maxsplit)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300283 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300284 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300285 return_value = bytearray_rsplit_impl(self, sep, maxsplit);
286
287exit:
288 return return_value;
289}
290
291PyDoc_STRVAR(bytearray_reverse__doc__,
292"reverse($self, /)\n"
293"--\n"
294"\n"
295"Reverse the order of the values in B in place.");
296
297#define BYTEARRAY_REVERSE_METHODDEF \
298 {"reverse", (PyCFunction)bytearray_reverse, METH_NOARGS, bytearray_reverse__doc__},
299
300static PyObject *
301bytearray_reverse_impl(PyByteArrayObject *self);
302
303static PyObject *
304bytearray_reverse(PyByteArrayObject *self, PyObject *Py_UNUSED(ignored))
305{
306 return bytearray_reverse_impl(self);
307}
308
309PyDoc_STRVAR(bytearray_insert__doc__,
310"insert($self, index, item, /)\n"
311"--\n"
312"\n"
313"Insert a single item into the bytearray before the given index.\n"
314"\n"
315" index\n"
316" The index where the value is to be inserted.\n"
317" item\n"
318" The item to be inserted.");
319
320#define BYTEARRAY_INSERT_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +0100321 {"insert", (PyCFunction)bytearray_insert, METH_FASTCALL, bytearray_insert__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300322
323static PyObject *
324bytearray_insert_impl(PyByteArrayObject *self, Py_ssize_t index, int item);
325
326static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +0100327bytearray_insert(PyByteArrayObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300328{
329 PyObject *return_value = NULL;
330 Py_ssize_t index;
331 int item;
332
Sylvain74453812017-06-10 06:51:48 +0200333 if (!_PyArg_NoStackKeywords("insert", kwnames)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300334 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300335 }
Victor Stinner259f0e42017-01-17 01:35:17 +0100336
Sylvain74453812017-06-10 06:51:48 +0200337 if (!_PyArg_ParseStack(args, nargs, "nO&:insert",
338 &index, _getbytevalue, &item)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100339 goto exit;
340 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300341 return_value = bytearray_insert_impl(self, index, item);
342
343exit:
344 return return_value;
345}
346
347PyDoc_STRVAR(bytearray_append__doc__,
348"append($self, item, /)\n"
349"--\n"
350"\n"
351"Append a single item to the end of the bytearray.\n"
352"\n"
353" item\n"
354" The item to be appended.");
355
356#define BYTEARRAY_APPEND_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300357 {"append", (PyCFunction)bytearray_append, METH_O, bytearray_append__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300358
359static PyObject *
360bytearray_append_impl(PyByteArrayObject *self, int item);
361
362static PyObject *
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300363bytearray_append(PyByteArrayObject *self, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300364{
365 PyObject *return_value = NULL;
366 int item;
367
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300368 if (!PyArg_Parse(arg, "O&:append", _getbytevalue, &item)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300369 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300370 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300371 return_value = bytearray_append_impl(self, item);
372
373exit:
374 return return_value;
375}
376
377PyDoc_STRVAR(bytearray_extend__doc__,
378"extend($self, iterable_of_ints, /)\n"
379"--\n"
380"\n"
381"Append all the items from the iterator or sequence to the end of the bytearray.\n"
382"\n"
383" iterable_of_ints\n"
384" The iterable of items to append.");
385
386#define BYTEARRAY_EXTEND_METHODDEF \
387 {"extend", (PyCFunction)bytearray_extend, METH_O, bytearray_extend__doc__},
388
389PyDoc_STRVAR(bytearray_pop__doc__,
390"pop($self, index=-1, /)\n"
391"--\n"
392"\n"
393"Remove and return a single item from B.\n"
394"\n"
395" index\n"
396" The index from where to remove the item.\n"
397" -1 (the default value) means remove the last item.\n"
398"\n"
399"If no index argument is given, will pop the last item.");
400
401#define BYTEARRAY_POP_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +0100402 {"pop", (PyCFunction)bytearray_pop, METH_FASTCALL, bytearray_pop__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300403
404static PyObject *
405bytearray_pop_impl(PyByteArrayObject *self, Py_ssize_t index);
406
407static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +0100408bytearray_pop(PyByteArrayObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300409{
410 PyObject *return_value = NULL;
411 Py_ssize_t index = -1;
412
Sylvain74453812017-06-10 06:51:48 +0200413 if (!_PyArg_NoStackKeywords("pop", kwnames)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300414 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300415 }
Victor Stinner259f0e42017-01-17 01:35:17 +0100416
Sylvain74453812017-06-10 06:51:48 +0200417 if (!_PyArg_ParseStack(args, nargs, "|n:pop",
418 &index)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100419 goto exit;
420 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300421 return_value = bytearray_pop_impl(self, index);
422
423exit:
424 return return_value;
425}
426
427PyDoc_STRVAR(bytearray_remove__doc__,
428"remove($self, value, /)\n"
429"--\n"
430"\n"
431"Remove the first occurrence of a value in the bytearray.\n"
432"\n"
433" value\n"
434" The value to remove.");
435
436#define BYTEARRAY_REMOVE_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300437 {"remove", (PyCFunction)bytearray_remove, METH_O, bytearray_remove__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300438
439static PyObject *
440bytearray_remove_impl(PyByteArrayObject *self, int value);
441
442static PyObject *
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300443bytearray_remove(PyByteArrayObject *self, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300444{
445 PyObject *return_value = NULL;
446 int value;
447
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300448 if (!PyArg_Parse(arg, "O&:remove", _getbytevalue, &value)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300449 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300450 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300451 return_value = bytearray_remove_impl(self, value);
452
453exit:
454 return return_value;
455}
456
457PyDoc_STRVAR(bytearray_strip__doc__,
458"strip($self, bytes=None, /)\n"
459"--\n"
460"\n"
461"Strip leading and trailing bytes contained in the argument.\n"
462"\n"
463"If the argument is omitted or None, strip leading and trailing ASCII whitespace.");
464
465#define BYTEARRAY_STRIP_METHODDEF \
Victor Stinner0c4a8282017-01-17 02:21:47 +0100466 {"strip", (PyCFunction)bytearray_strip, METH_FASTCALL, bytearray_strip__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300467
468static PyObject *
469bytearray_strip_impl(PyByteArrayObject *self, PyObject *bytes);
470
471static PyObject *
Victor Stinner0c4a8282017-01-17 02:21:47 +0100472bytearray_strip(PyByteArrayObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300473{
474 PyObject *return_value = NULL;
475 PyObject *bytes = Py_None;
476
Sylvain74453812017-06-10 06:51:48 +0200477 if (!_PyArg_NoStackKeywords("strip", kwnames)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300478 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300479 }
Victor Stinner0c4a8282017-01-17 02:21:47 +0100480
Sylvain74453812017-06-10 06:51:48 +0200481 if (!_PyArg_UnpackStack(args, nargs, "strip",
482 0, 1,
483 &bytes)) {
Victor Stinner0c4a8282017-01-17 02:21:47 +0100484 goto exit;
485 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300486 return_value = bytearray_strip_impl(self, bytes);
487
488exit:
489 return return_value;
490}
491
492PyDoc_STRVAR(bytearray_lstrip__doc__,
493"lstrip($self, bytes=None, /)\n"
494"--\n"
495"\n"
496"Strip leading bytes contained in the argument.\n"
497"\n"
498"If the argument is omitted or None, strip leading ASCII whitespace.");
499
500#define BYTEARRAY_LSTRIP_METHODDEF \
Victor Stinner0c4a8282017-01-17 02:21:47 +0100501 {"lstrip", (PyCFunction)bytearray_lstrip, METH_FASTCALL, bytearray_lstrip__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300502
503static PyObject *
504bytearray_lstrip_impl(PyByteArrayObject *self, PyObject *bytes);
505
506static PyObject *
Victor Stinner0c4a8282017-01-17 02:21:47 +0100507bytearray_lstrip(PyByteArrayObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300508{
509 PyObject *return_value = NULL;
510 PyObject *bytes = Py_None;
511
Sylvain74453812017-06-10 06:51:48 +0200512 if (!_PyArg_NoStackKeywords("lstrip", kwnames)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300513 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300514 }
Victor Stinner0c4a8282017-01-17 02:21:47 +0100515
Sylvain74453812017-06-10 06:51:48 +0200516 if (!_PyArg_UnpackStack(args, nargs, "lstrip",
517 0, 1,
518 &bytes)) {
Victor Stinner0c4a8282017-01-17 02:21:47 +0100519 goto exit;
520 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300521 return_value = bytearray_lstrip_impl(self, bytes);
522
523exit:
524 return return_value;
525}
526
527PyDoc_STRVAR(bytearray_rstrip__doc__,
528"rstrip($self, bytes=None, /)\n"
529"--\n"
530"\n"
531"Strip trailing bytes contained in the argument.\n"
532"\n"
533"If the argument is omitted or None, strip trailing ASCII whitespace.");
534
535#define BYTEARRAY_RSTRIP_METHODDEF \
Victor Stinner0c4a8282017-01-17 02:21:47 +0100536 {"rstrip", (PyCFunction)bytearray_rstrip, METH_FASTCALL, bytearray_rstrip__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300537
538static PyObject *
539bytearray_rstrip_impl(PyByteArrayObject *self, PyObject *bytes);
540
541static PyObject *
Victor Stinner0c4a8282017-01-17 02:21:47 +0100542bytearray_rstrip(PyByteArrayObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300543{
544 PyObject *return_value = NULL;
545 PyObject *bytes = Py_None;
546
Sylvain74453812017-06-10 06:51:48 +0200547 if (!_PyArg_NoStackKeywords("rstrip", kwnames)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300548 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300549 }
Victor Stinner0c4a8282017-01-17 02:21:47 +0100550
Sylvain74453812017-06-10 06:51:48 +0200551 if (!_PyArg_UnpackStack(args, nargs, "rstrip",
552 0, 1,
553 &bytes)) {
Victor Stinner0c4a8282017-01-17 02:21:47 +0100554 goto exit;
555 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300556 return_value = bytearray_rstrip_impl(self, bytes);
557
558exit:
559 return return_value;
560}
561
562PyDoc_STRVAR(bytearray_decode__doc__,
563"decode($self, /, encoding=\'utf-8\', errors=\'strict\')\n"
564"--\n"
565"\n"
566"Decode the bytearray using the codec registered for encoding.\n"
567"\n"
568" encoding\n"
569" The encoding with which to decode the bytearray.\n"
570" errors\n"
571" The error handling scheme to use for the handling of decoding errors.\n"
572" The default is \'strict\' meaning that decoding errors raise a\n"
573" UnicodeDecodeError. Other possible values are \'ignore\' and \'replace\'\n"
574" as well as any other name registered with codecs.register_error that\n"
575" can handle UnicodeDecodeErrors.");
576
577#define BYTEARRAY_DECODE_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -0700578 {"decode", (PyCFunction)bytearray_decode, METH_FASTCALL, bytearray_decode__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300579
580static PyObject *
Larry Hastings89964c42015-04-14 18:07:59 -0400581bytearray_decode_impl(PyByteArrayObject *self, const char *encoding,
582 const char *errors);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300583
584static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700585bytearray_decode(PyByteArrayObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300586{
587 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300588 static const char * const _keywords[] = {"encoding", "errors", NULL};
589 static _PyArg_Parser _parser = {"|ss:decode", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300590 const char *encoding = NULL;
591 const char *errors = NULL;
592
Victor Stinner3e1fad62017-01-17 01:29:01 +0100593 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300594 &encoding, &errors)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300595 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300596 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300597 return_value = bytearray_decode_impl(self, encoding, errors);
598
599exit:
600 return return_value;
601}
602
603PyDoc_STRVAR(bytearray_join__doc__,
604"join($self, iterable_of_bytes, /)\n"
605"--\n"
606"\n"
607"Concatenate any number of bytes/bytearray objects.\n"
608"\n"
609"The bytearray whose method is called is inserted in between each pair.\n"
610"\n"
611"The result is returned as a new bytearray object.");
612
613#define BYTEARRAY_JOIN_METHODDEF \
614 {"join", (PyCFunction)bytearray_join, METH_O, bytearray_join__doc__},
615
616PyDoc_STRVAR(bytearray_splitlines__doc__,
617"splitlines($self, /, keepends=False)\n"
618"--\n"
619"\n"
620"Return a list of the lines in the bytearray, breaking at line boundaries.\n"
621"\n"
622"Line breaks are not included in the resulting list unless keepends is given and\n"
623"true.");
624
625#define BYTEARRAY_SPLITLINES_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -0700626 {"splitlines", (PyCFunction)bytearray_splitlines, METH_FASTCALL, bytearray_splitlines__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300627
628static PyObject *
629bytearray_splitlines_impl(PyByteArrayObject *self, int keepends);
630
631static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700632bytearray_splitlines(PyByteArrayObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300633{
634 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300635 static const char * const _keywords[] = {"keepends", NULL};
636 static _PyArg_Parser _parser = {"|i:splitlines", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300637 int keepends = 0;
638
Victor Stinner3e1fad62017-01-17 01:29:01 +0100639 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300640 &keepends)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300641 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300642 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300643 return_value = bytearray_splitlines_impl(self, keepends);
644
645exit:
646 return return_value;
647}
648
649PyDoc_STRVAR(bytearray_fromhex__doc__,
650"fromhex($type, string, /)\n"
651"--\n"
652"\n"
653"Create a bytearray object from a string of hexadecimal numbers.\n"
654"\n"
655"Spaces between two numbers are accepted.\n"
656"Example: bytearray.fromhex(\'B9 01EF\') -> bytearray(b\'\\\\xb9\\\\x01\\\\xef\')");
657
658#define BYTEARRAY_FROMHEX_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300659 {"fromhex", (PyCFunction)bytearray_fromhex, METH_O|METH_CLASS, bytearray_fromhex__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300660
661static PyObject *
Serhiy Storchaka0855e702016-07-01 17:22:31 +0300662bytearray_fromhex_impl(PyTypeObject *type, PyObject *string);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300663
664static PyObject *
Serhiy Storchaka0855e702016-07-01 17:22:31 +0300665bytearray_fromhex(PyTypeObject *type, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300666{
667 PyObject *return_value = NULL;
668 PyObject *string;
669
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300670 if (!PyArg_Parse(arg, "U:fromhex", &string)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300671 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300672 }
Serhiy Storchaka0855e702016-07-01 17:22:31 +0300673 return_value = bytearray_fromhex_impl(type, string);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300674
675exit:
676 return return_value;
677}
678
679PyDoc_STRVAR(bytearray_reduce__doc__,
680"__reduce__($self, /)\n"
681"--\n"
682"\n"
683"Return state information for pickling.");
684
685#define BYTEARRAY_REDUCE_METHODDEF \
686 {"__reduce__", (PyCFunction)bytearray_reduce, METH_NOARGS, bytearray_reduce__doc__},
687
688static PyObject *
689bytearray_reduce_impl(PyByteArrayObject *self);
690
691static PyObject *
692bytearray_reduce(PyByteArrayObject *self, PyObject *Py_UNUSED(ignored))
693{
694 return bytearray_reduce_impl(self);
695}
696
697PyDoc_STRVAR(bytearray_reduce_ex__doc__,
698"__reduce_ex__($self, proto=0, /)\n"
699"--\n"
700"\n"
701"Return state information for pickling.");
702
703#define BYTEARRAY_REDUCE_EX_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +0100704 {"__reduce_ex__", (PyCFunction)bytearray_reduce_ex, METH_FASTCALL, bytearray_reduce_ex__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300705
706static PyObject *
707bytearray_reduce_ex_impl(PyByteArrayObject *self, int proto);
708
709static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +0100710bytearray_reduce_ex(PyByteArrayObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300711{
712 PyObject *return_value = NULL;
713 int proto = 0;
714
Sylvain74453812017-06-10 06:51:48 +0200715 if (!_PyArg_NoStackKeywords("__reduce_ex__", kwnames)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300716 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300717 }
Victor Stinner259f0e42017-01-17 01:35:17 +0100718
Sylvain74453812017-06-10 06:51:48 +0200719 if (!_PyArg_ParseStack(args, nargs, "|i:__reduce_ex__",
720 &proto)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100721 goto exit;
722 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300723 return_value = bytearray_reduce_ex_impl(self, proto);
724
725exit:
726 return return_value;
727}
728
729PyDoc_STRVAR(bytearray_sizeof__doc__,
730"__sizeof__($self, /)\n"
731"--\n"
732"\n"
733"Returns the size of the bytearray object in memory, in bytes.");
734
735#define BYTEARRAY_SIZEOF_METHODDEF \
736 {"__sizeof__", (PyCFunction)bytearray_sizeof, METH_NOARGS, bytearray_sizeof__doc__},
737
738static PyObject *
739bytearray_sizeof_impl(PyByteArrayObject *self);
740
741static PyObject *
742bytearray_sizeof(PyByteArrayObject *self, PyObject *Py_UNUSED(ignored))
743{
744 return bytearray_sizeof_impl(self);
745}
Sylvain74453812017-06-10 06:51:48 +0200746/*[clinic end generated code: output=f0079d8ee82614f7 input=a9049054013a1b77]*/