blob: a99ce48ac6df09c3045abc24237bce2cffccc853 [file] [log] [blame]
Serhiy Storchaka1009bf12015-04-03 23:53:51 +03001/*[clinic input]
2preserve
3[clinic start generated code]*/
4
5PyDoc_STRVAR(bytes_split__doc__,
6"split($self, /, sep=None, maxsplit=-1)\n"
7"--\n"
8"\n"
9"Return a list of the sections in the bytes, using sep as the delimiter.\n"
10"\n"
11" sep\n"
12" The delimiter according which to split the bytes.\n"
13" None (the default value) means split on ASCII whitespace characters\n"
14" (space, tab, return, newline, formfeed, vertical tab).\n"
15" maxsplit\n"
16" Maximum number of splits to do.\n"
17" -1 (the default value) means no limit.");
18
19#define BYTES_SPLIT_METHODDEF \
20 {"split", (PyCFunction)bytes_split, METH_VARARGS|METH_KEYWORDS, bytes_split__doc__},
21
22static PyObject *
Serhiy Storchaka7a9579c2016-05-02 13:45:20 +030023bytes_split_impl(PyBytesObject *self, PyObject *sep, Py_ssize_t maxsplit);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030024
25static PyObject *
Serhiy Storchaka7a9579c2016-05-02 13:45:20 +030026bytes_split(PyBytesObject *self, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030027{
28 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +030029 static const char * const _keywords[] = {"sep", "maxsplit", NULL};
30 static _PyArg_Parser _parser = {"|On:split", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030031 PyObject *sep = Py_None;
32 Py_ssize_t maxsplit = -1;
33
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +030034 if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030035 &sep, &maxsplit)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030036 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030037 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030038 return_value = bytes_split_impl(self, sep, maxsplit);
39
40exit:
41 return return_value;
42}
43
44PyDoc_STRVAR(bytes_partition__doc__,
45"partition($self, sep, /)\n"
46"--\n"
47"\n"
48"Partition the bytes into three parts using the given separator.\n"
49"\n"
50"This will search for the separator sep in the bytes. If the separator is found,\n"
51"returns a 3-tuple containing the part before the separator, the separator\n"
52"itself, and the part after it.\n"
53"\n"
54"If the separator is not found, returns a 3-tuple containing the original bytes\n"
55"object and two empty bytes objects.");
56
57#define BYTES_PARTITION_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +030058 {"partition", (PyCFunction)bytes_partition, METH_O, bytes_partition__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030059
60static PyObject *
61bytes_partition_impl(PyBytesObject *self, Py_buffer *sep);
62
63static PyObject *
Serhiy Storchaka92e8af62015-04-04 00:12:11 +030064bytes_partition(PyBytesObject *self, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030065{
66 PyObject *return_value = NULL;
67 Py_buffer sep = {NULL, NULL};
68
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030069 if (!PyArg_Parse(arg, "y*:partition", &sep)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030070 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030071 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030072 return_value = bytes_partition_impl(self, &sep);
73
74exit:
75 /* Cleanup for sep */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030076 if (sep.obj) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030077 PyBuffer_Release(&sep);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030078 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030079
80 return return_value;
81}
82
83PyDoc_STRVAR(bytes_rpartition__doc__,
84"rpartition($self, sep, /)\n"
85"--\n"
86"\n"
87"Partition the bytes into three parts using the given separator.\n"
88"\n"
89"This will search for the separator sep in the bytes, starting and the end. If\n"
90"the separator is found, returns a 3-tuple containing the part before the\n"
91"separator, the separator itself, and the part after it.\n"
92"\n"
93"If the separator is not found, returns a 3-tuple containing two empty bytes\n"
94"objects and the original bytes object.");
95
96#define BYTES_RPARTITION_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +030097 {"rpartition", (PyCFunction)bytes_rpartition, METH_O, bytes_rpartition__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030098
99static PyObject *
100bytes_rpartition_impl(PyBytesObject *self, Py_buffer *sep);
101
102static PyObject *
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300103bytes_rpartition(PyBytesObject *self, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300104{
105 PyObject *return_value = NULL;
106 Py_buffer sep = {NULL, NULL};
107
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300108 if (!PyArg_Parse(arg, "y*:rpartition", &sep)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300109 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300110 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300111 return_value = bytes_rpartition_impl(self, &sep);
112
113exit:
114 /* Cleanup for sep */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300115 if (sep.obj) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300116 PyBuffer_Release(&sep);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300117 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300118
119 return return_value;
120}
121
122PyDoc_STRVAR(bytes_rsplit__doc__,
123"rsplit($self, /, sep=None, maxsplit=-1)\n"
124"--\n"
125"\n"
126"Return a list of the sections in the bytes, using sep as the delimiter.\n"
127"\n"
128" sep\n"
129" The delimiter according which to split the bytes.\n"
130" None (the default value) means split on ASCII whitespace characters\n"
131" (space, tab, return, newline, formfeed, vertical tab).\n"
132" maxsplit\n"
133" Maximum number of splits to do.\n"
134" -1 (the default value) means no limit.\n"
135"\n"
136"Splitting is done starting at the end of the bytes and working to the front.");
137
138#define BYTES_RSPLIT_METHODDEF \
139 {"rsplit", (PyCFunction)bytes_rsplit, METH_VARARGS|METH_KEYWORDS, bytes_rsplit__doc__},
140
141static PyObject *
Serhiy Storchaka7a9579c2016-05-02 13:45:20 +0300142bytes_rsplit_impl(PyBytesObject *self, PyObject *sep, Py_ssize_t maxsplit);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300143
144static PyObject *
Serhiy Storchaka7a9579c2016-05-02 13:45:20 +0300145bytes_rsplit(PyBytesObject *self, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300146{
147 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300148 static const char * const _keywords[] = {"sep", "maxsplit", NULL};
149 static _PyArg_Parser _parser = {"|On:rsplit", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300150 PyObject *sep = Py_None;
151 Py_ssize_t maxsplit = -1;
152
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300153 if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300154 &sep, &maxsplit)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300155 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300156 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300157 return_value = bytes_rsplit_impl(self, sep, maxsplit);
158
159exit:
160 return return_value;
161}
162
163PyDoc_STRVAR(bytes_join__doc__,
164"join($self, iterable_of_bytes, /)\n"
165"--\n"
166"\n"
167"Concatenate any number of bytes objects.\n"
168"\n"
169"The bytes whose method is called is inserted in between each pair.\n"
170"\n"
171"The result is returned as a new bytes object.\n"
172"\n"
173"Example: b\'.\'.join([b\'ab\', b\'pq\', b\'rs\']) -> b\'ab.pq.rs\'.");
174
175#define BYTES_JOIN_METHODDEF \
176 {"join", (PyCFunction)bytes_join, METH_O, bytes_join__doc__},
177
178PyDoc_STRVAR(bytes_strip__doc__,
179"strip($self, bytes=None, /)\n"
180"--\n"
181"\n"
182"Strip leading and trailing bytes contained in the argument.\n"
183"\n"
184"If the argument is omitted or None, strip leading and trailing ASCII whitespace.");
185
186#define BYTES_STRIP_METHODDEF \
187 {"strip", (PyCFunction)bytes_strip, METH_VARARGS, bytes_strip__doc__},
188
189static PyObject *
190bytes_strip_impl(PyBytesObject *self, PyObject *bytes);
191
192static PyObject *
193bytes_strip(PyBytesObject *self, PyObject *args)
194{
195 PyObject *return_value = NULL;
196 PyObject *bytes = Py_None;
197
198 if (!PyArg_UnpackTuple(args, "strip",
199 0, 1,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300200 &bytes)) {
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 = bytes_strip_impl(self, bytes);
204
205exit:
206 return return_value;
207}
208
209PyDoc_STRVAR(bytes_lstrip__doc__,
210"lstrip($self, bytes=None, /)\n"
211"--\n"
212"\n"
213"Strip leading bytes contained in the argument.\n"
214"\n"
215"If the argument is omitted or None, strip leading ASCII whitespace.");
216
217#define BYTES_LSTRIP_METHODDEF \
218 {"lstrip", (PyCFunction)bytes_lstrip, METH_VARARGS, bytes_lstrip__doc__},
219
220static PyObject *
221bytes_lstrip_impl(PyBytesObject *self, PyObject *bytes);
222
223static PyObject *
224bytes_lstrip(PyBytesObject *self, PyObject *args)
225{
226 PyObject *return_value = NULL;
227 PyObject *bytes = Py_None;
228
229 if (!PyArg_UnpackTuple(args, "lstrip",
230 0, 1,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300231 &bytes)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300232 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300233 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300234 return_value = bytes_lstrip_impl(self, bytes);
235
236exit:
237 return return_value;
238}
239
240PyDoc_STRVAR(bytes_rstrip__doc__,
241"rstrip($self, bytes=None, /)\n"
242"--\n"
243"\n"
244"Strip trailing bytes contained in the argument.\n"
245"\n"
246"If the argument is omitted or None, strip trailing ASCII whitespace.");
247
248#define BYTES_RSTRIP_METHODDEF \
249 {"rstrip", (PyCFunction)bytes_rstrip, METH_VARARGS, bytes_rstrip__doc__},
250
251static PyObject *
252bytes_rstrip_impl(PyBytesObject *self, PyObject *bytes);
253
254static PyObject *
255bytes_rstrip(PyBytesObject *self, PyObject *args)
256{
257 PyObject *return_value = NULL;
258 PyObject *bytes = Py_None;
259
260 if (!PyArg_UnpackTuple(args, "rstrip",
261 0, 1,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300262 &bytes)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300263 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300264 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300265 return_value = bytes_rstrip_impl(self, bytes);
266
267exit:
268 return return_value;
269}
270
271PyDoc_STRVAR(bytes_translate__doc__,
272"translate(table, [deletechars])\n"
273"Return a copy with each character mapped by the given translation table.\n"
274"\n"
275" table\n"
276" Translation table, which must be a bytes object of length 256.\n"
277"\n"
278"All characters occurring in the optional argument deletechars are removed.\n"
279"The remaining characters are mapped through the given translation table.");
280
281#define BYTES_TRANSLATE_METHODDEF \
282 {"translate", (PyCFunction)bytes_translate, METH_VARARGS, bytes_translate__doc__},
283
284static PyObject *
Larry Hastings89964c42015-04-14 18:07:59 -0400285bytes_translate_impl(PyBytesObject *self, PyObject *table, int group_right_1,
286 PyObject *deletechars);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300287
288static PyObject *
289bytes_translate(PyBytesObject *self, PyObject *args)
290{
291 PyObject *return_value = NULL;
292 PyObject *table;
293 int group_right_1 = 0;
294 PyObject *deletechars = NULL;
295
296 switch (PyTuple_GET_SIZE(args)) {
297 case 1:
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300298 if (!PyArg_ParseTuple(args, "O:translate", &table)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300299 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300300 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300301 break;
302 case 2:
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300303 if (!PyArg_ParseTuple(args, "OO:translate", &table, &deletechars)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300304 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300305 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300306 group_right_1 = 1;
307 break;
308 default:
309 PyErr_SetString(PyExc_TypeError, "bytes.translate requires 1 to 2 arguments");
310 goto exit;
311 }
312 return_value = bytes_translate_impl(self, table, group_right_1, deletechars);
313
314exit:
315 return return_value;
316}
317
318PyDoc_STRVAR(bytes_maketrans__doc__,
319"maketrans(frm, to, /)\n"
320"--\n"
321"\n"
322"Return a translation table useable for the bytes or bytearray translate method.\n"
323"\n"
324"The returned table will be one where each byte in frm is mapped to the byte at\n"
325"the same position in to.\n"
326"\n"
327"The bytes objects frm and to must be of the same length.");
328
329#define BYTES_MAKETRANS_METHODDEF \
330 {"maketrans", (PyCFunction)bytes_maketrans, METH_VARARGS|METH_STATIC, bytes_maketrans__doc__},
331
332static PyObject *
333bytes_maketrans_impl(Py_buffer *frm, Py_buffer *to);
334
335static PyObject *
336bytes_maketrans(void *null, PyObject *args)
337{
338 PyObject *return_value = NULL;
339 Py_buffer frm = {NULL, NULL};
340 Py_buffer to = {NULL, NULL};
341
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300342 if (!PyArg_ParseTuple(args, "y*y*:maketrans",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300343 &frm, &to)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300344 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300345 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300346 return_value = bytes_maketrans_impl(&frm, &to);
347
348exit:
349 /* Cleanup for frm */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300350 if (frm.obj) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300351 PyBuffer_Release(&frm);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300352 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300353 /* Cleanup for to */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300354 if (to.obj) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300355 PyBuffer_Release(&to);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300356 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300357
358 return return_value;
359}
360
361PyDoc_STRVAR(bytes_replace__doc__,
362"replace($self, old, new, count=-1, /)\n"
363"--\n"
364"\n"
365"Return a copy with all occurrences of substring old replaced by new.\n"
366"\n"
367" count\n"
368" Maximum number of occurrences to replace.\n"
369" -1 (the default value) means replace all occurrences.\n"
370"\n"
371"If the optional argument count is given, only the first count occurrences are\n"
372"replaced.");
373
374#define BYTES_REPLACE_METHODDEF \
375 {"replace", (PyCFunction)bytes_replace, METH_VARARGS, bytes_replace__doc__},
376
377static PyObject *
Serhiy Storchaka7a9579c2016-05-02 13:45:20 +0300378bytes_replace_impl(PyBytesObject *self, Py_buffer *old, Py_buffer *new,
Larry Hastings89964c42015-04-14 18:07:59 -0400379 Py_ssize_t count);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300380
381static PyObject *
Serhiy Storchaka7a9579c2016-05-02 13:45:20 +0300382bytes_replace(PyBytesObject *self, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300383{
384 PyObject *return_value = NULL;
385 Py_buffer old = {NULL, NULL};
386 Py_buffer new = {NULL, NULL};
387 Py_ssize_t count = -1;
388
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300389 if (!PyArg_ParseTuple(args, "y*y*|n:replace",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300390 &old, &new, &count)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300391 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300392 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300393 return_value = bytes_replace_impl(self, &old, &new, count);
394
395exit:
396 /* Cleanup for old */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300397 if (old.obj) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300398 PyBuffer_Release(&old);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300399 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300400 /* Cleanup for new */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300401 if (new.obj) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300402 PyBuffer_Release(&new);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300403 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300404
405 return return_value;
406}
407
408PyDoc_STRVAR(bytes_decode__doc__,
409"decode($self, /, encoding=\'utf-8\', errors=\'strict\')\n"
410"--\n"
411"\n"
412"Decode the bytes using the codec registered for encoding.\n"
413"\n"
414" encoding\n"
415" The encoding with which to decode the bytes.\n"
416" errors\n"
417" The error handling scheme to use for the handling of decoding errors.\n"
418" The default is \'strict\' meaning that decoding errors raise a\n"
419" UnicodeDecodeError. Other possible values are \'ignore\' and \'replace\'\n"
420" as well as any other name registered with codecs.register_error that\n"
421" can handle UnicodeDecodeErrors.");
422
423#define BYTES_DECODE_METHODDEF \
424 {"decode", (PyCFunction)bytes_decode, METH_VARARGS|METH_KEYWORDS, bytes_decode__doc__},
425
426static PyObject *
Serhiy Storchaka7a9579c2016-05-02 13:45:20 +0300427bytes_decode_impl(PyBytesObject *self, const char *encoding,
Larry Hastings89964c42015-04-14 18:07:59 -0400428 const char *errors);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300429
430static PyObject *
Serhiy Storchaka7a9579c2016-05-02 13:45:20 +0300431bytes_decode(PyBytesObject *self, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300432{
433 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300434 static const char * const _keywords[] = {"encoding", "errors", NULL};
435 static _PyArg_Parser _parser = {"|ss:decode", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300436 const char *encoding = NULL;
437 const char *errors = NULL;
438
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300439 if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300440 &encoding, &errors)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300441 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300442 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300443 return_value = bytes_decode_impl(self, encoding, errors);
444
445exit:
446 return return_value;
447}
448
449PyDoc_STRVAR(bytes_splitlines__doc__,
450"splitlines($self, /, keepends=False)\n"
451"--\n"
452"\n"
453"Return a list of the lines in the bytes, breaking at line boundaries.\n"
454"\n"
455"Line breaks are not included in the resulting list unless keepends is given and\n"
456"true.");
457
458#define BYTES_SPLITLINES_METHODDEF \
459 {"splitlines", (PyCFunction)bytes_splitlines, METH_VARARGS|METH_KEYWORDS, bytes_splitlines__doc__},
460
461static PyObject *
Serhiy Storchaka7a9579c2016-05-02 13:45:20 +0300462bytes_splitlines_impl(PyBytesObject *self, int keepends);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300463
464static PyObject *
Serhiy Storchaka7a9579c2016-05-02 13:45:20 +0300465bytes_splitlines(PyBytesObject *self, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300466{
467 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300468 static const char * const _keywords[] = {"keepends", NULL};
469 static _PyArg_Parser _parser = {"|i:splitlines", _keywords, 0};
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300470 int keepends = 0;
471
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300472 if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300473 &keepends)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300474 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300475 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300476 return_value = bytes_splitlines_impl(self, keepends);
477
478exit:
479 return return_value;
480}
481
482PyDoc_STRVAR(bytes_fromhex__doc__,
483"fromhex($type, string, /)\n"
484"--\n"
485"\n"
486"Create a bytes object from a string of hexadecimal numbers.\n"
487"\n"
488"Spaces between two numbers are accepted.\n"
489"Example: bytes.fromhex(\'B9 01EF\') -> b\'\\\\xb9\\\\x01\\\\xef\'.");
490
491#define BYTES_FROMHEX_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300492 {"fromhex", (PyCFunction)bytes_fromhex, METH_O|METH_CLASS, bytes_fromhex__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300493
494static PyObject *
495bytes_fromhex_impl(PyTypeObject *type, PyObject *string);
496
497static PyObject *
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300498bytes_fromhex(PyTypeObject *type, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300499{
500 PyObject *return_value = NULL;
501 PyObject *string;
502
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300503 if (!PyArg_Parse(arg, "U:fromhex", &string)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300504 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300505 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300506 return_value = bytes_fromhex_impl(type, string);
507
508exit:
509 return return_value;
510}
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300511/*[clinic end generated code: output=637c2c14610d3c8d input=a9049054013a1b77]*/