blob: 0cced8ee10e858e0a3c5bfe43335bebe74bb680f [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;
29 static char *_keywords[] = {"sep", "maxsplit", NULL};
30 PyObject *sep = Py_None;
31 Py_ssize_t maxsplit = -1;
32
Serhiy Storchaka247789c2015-04-24 00:40:51 +030033 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|On:split", _keywords,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030034 &sep, &maxsplit)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030035 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030036 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030037 return_value = bytes_split_impl(self, sep, maxsplit);
38
39exit:
40 return return_value;
41}
42
43PyDoc_STRVAR(bytes_partition__doc__,
44"partition($self, sep, /)\n"
45"--\n"
46"\n"
47"Partition the bytes into three parts using the given separator.\n"
48"\n"
49"This will search for the separator sep in the bytes. If the separator is found,\n"
50"returns a 3-tuple containing the part before the separator, the separator\n"
51"itself, and the part after it.\n"
52"\n"
53"If the separator is not found, returns a 3-tuple containing the original bytes\n"
54"object and two empty bytes objects.");
55
56#define BYTES_PARTITION_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +030057 {"partition", (PyCFunction)bytes_partition, METH_O, bytes_partition__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030058
59static PyObject *
60bytes_partition_impl(PyBytesObject *self, Py_buffer *sep);
61
62static PyObject *
Serhiy Storchaka92e8af62015-04-04 00:12:11 +030063bytes_partition(PyBytesObject *self, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030064{
65 PyObject *return_value = NULL;
66 Py_buffer sep = {NULL, NULL};
67
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030068 if (!PyArg_Parse(arg, "y*:partition", &sep)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030069 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030070 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030071 return_value = bytes_partition_impl(self, &sep);
72
73exit:
74 /* Cleanup for sep */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030075 if (sep.obj) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030076 PyBuffer_Release(&sep);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030077 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030078
79 return return_value;
80}
81
82PyDoc_STRVAR(bytes_rpartition__doc__,
83"rpartition($self, sep, /)\n"
84"--\n"
85"\n"
86"Partition the bytes into three parts using the given separator.\n"
87"\n"
88"This will search for the separator sep in the bytes, starting and the end. If\n"
89"the separator is found, returns a 3-tuple containing the part before the\n"
90"separator, the separator itself, and the part after it.\n"
91"\n"
92"If the separator is not found, returns a 3-tuple containing two empty bytes\n"
93"objects and the original bytes object.");
94
95#define BYTES_RPARTITION_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +030096 {"rpartition", (PyCFunction)bytes_rpartition, METH_O, bytes_rpartition__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +030097
98static PyObject *
99bytes_rpartition_impl(PyBytesObject *self, Py_buffer *sep);
100
101static PyObject *
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300102bytes_rpartition(PyBytesObject *self, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300103{
104 PyObject *return_value = NULL;
105 Py_buffer sep = {NULL, NULL};
106
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300107 if (!PyArg_Parse(arg, "y*:rpartition", &sep)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300108 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300109 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300110 return_value = bytes_rpartition_impl(self, &sep);
111
112exit:
113 /* Cleanup for sep */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300114 if (sep.obj) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300115 PyBuffer_Release(&sep);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300116 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300117
118 return return_value;
119}
120
121PyDoc_STRVAR(bytes_rsplit__doc__,
122"rsplit($self, /, sep=None, maxsplit=-1)\n"
123"--\n"
124"\n"
125"Return a list of the sections in the bytes, using sep as the delimiter.\n"
126"\n"
127" sep\n"
128" The delimiter according which to split the bytes.\n"
129" None (the default value) means split on ASCII whitespace characters\n"
130" (space, tab, return, newline, formfeed, vertical tab).\n"
131" maxsplit\n"
132" Maximum number of splits to do.\n"
133" -1 (the default value) means no limit.\n"
134"\n"
135"Splitting is done starting at the end of the bytes and working to the front.");
136
137#define BYTES_RSPLIT_METHODDEF \
138 {"rsplit", (PyCFunction)bytes_rsplit, METH_VARARGS|METH_KEYWORDS, bytes_rsplit__doc__},
139
140static PyObject *
Serhiy Storchaka7a9579c2016-05-02 13:45:20 +0300141bytes_rsplit_impl(PyBytesObject *self, PyObject *sep, Py_ssize_t maxsplit);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300142
143static PyObject *
Serhiy Storchaka7a9579c2016-05-02 13:45:20 +0300144bytes_rsplit(PyBytesObject *self, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300145{
146 PyObject *return_value = NULL;
147 static char *_keywords[] = {"sep", "maxsplit", NULL};
148 PyObject *sep = Py_None;
149 Py_ssize_t maxsplit = -1;
150
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300151 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|On:rsplit", _keywords,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300152 &sep, &maxsplit)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300153 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300154 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300155 return_value = bytes_rsplit_impl(self, sep, maxsplit);
156
157exit:
158 return return_value;
159}
160
161PyDoc_STRVAR(bytes_join__doc__,
162"join($self, iterable_of_bytes, /)\n"
163"--\n"
164"\n"
165"Concatenate any number of bytes objects.\n"
166"\n"
167"The bytes whose method is called is inserted in between each pair.\n"
168"\n"
169"The result is returned as a new bytes object.\n"
170"\n"
171"Example: b\'.\'.join([b\'ab\', b\'pq\', b\'rs\']) -> b\'ab.pq.rs\'.");
172
173#define BYTES_JOIN_METHODDEF \
174 {"join", (PyCFunction)bytes_join, METH_O, bytes_join__doc__},
175
176PyDoc_STRVAR(bytes_strip__doc__,
177"strip($self, bytes=None, /)\n"
178"--\n"
179"\n"
180"Strip leading and trailing bytes contained in the argument.\n"
181"\n"
182"If the argument is omitted or None, strip leading and trailing ASCII whitespace.");
183
184#define BYTES_STRIP_METHODDEF \
185 {"strip", (PyCFunction)bytes_strip, METH_VARARGS, bytes_strip__doc__},
186
187static PyObject *
188bytes_strip_impl(PyBytesObject *self, PyObject *bytes);
189
190static PyObject *
191bytes_strip(PyBytesObject *self, PyObject *args)
192{
193 PyObject *return_value = NULL;
194 PyObject *bytes = Py_None;
195
196 if (!PyArg_UnpackTuple(args, "strip",
197 0, 1,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300198 &bytes)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300199 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300200 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300201 return_value = bytes_strip_impl(self, bytes);
202
203exit:
204 return return_value;
205}
206
207PyDoc_STRVAR(bytes_lstrip__doc__,
208"lstrip($self, bytes=None, /)\n"
209"--\n"
210"\n"
211"Strip leading bytes contained in the argument.\n"
212"\n"
213"If the argument is omitted or None, strip leading ASCII whitespace.");
214
215#define BYTES_LSTRIP_METHODDEF \
216 {"lstrip", (PyCFunction)bytes_lstrip, METH_VARARGS, bytes_lstrip__doc__},
217
218static PyObject *
219bytes_lstrip_impl(PyBytesObject *self, PyObject *bytes);
220
221static PyObject *
222bytes_lstrip(PyBytesObject *self, PyObject *args)
223{
224 PyObject *return_value = NULL;
225 PyObject *bytes = Py_None;
226
227 if (!PyArg_UnpackTuple(args, "lstrip",
228 0, 1,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300229 &bytes)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300230 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300231 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300232 return_value = bytes_lstrip_impl(self, bytes);
233
234exit:
235 return return_value;
236}
237
238PyDoc_STRVAR(bytes_rstrip__doc__,
239"rstrip($self, bytes=None, /)\n"
240"--\n"
241"\n"
242"Strip trailing bytes contained in the argument.\n"
243"\n"
244"If the argument is omitted or None, strip trailing ASCII whitespace.");
245
246#define BYTES_RSTRIP_METHODDEF \
247 {"rstrip", (PyCFunction)bytes_rstrip, METH_VARARGS, bytes_rstrip__doc__},
248
249static PyObject *
250bytes_rstrip_impl(PyBytesObject *self, PyObject *bytes);
251
252static PyObject *
253bytes_rstrip(PyBytesObject *self, PyObject *args)
254{
255 PyObject *return_value = NULL;
256 PyObject *bytes = Py_None;
257
258 if (!PyArg_UnpackTuple(args, "rstrip",
259 0, 1,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300260 &bytes)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300261 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300262 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300263 return_value = bytes_rstrip_impl(self, bytes);
264
265exit:
266 return return_value;
267}
268
269PyDoc_STRVAR(bytes_translate__doc__,
270"translate(table, [deletechars])\n"
271"Return a copy with each character mapped by the given translation table.\n"
272"\n"
273" table\n"
274" Translation table, which must be a bytes object of length 256.\n"
275"\n"
276"All characters occurring in the optional argument deletechars are removed.\n"
277"The remaining characters are mapped through the given translation table.");
278
279#define BYTES_TRANSLATE_METHODDEF \
280 {"translate", (PyCFunction)bytes_translate, METH_VARARGS, bytes_translate__doc__},
281
282static PyObject *
Larry Hastings89964c42015-04-14 18:07:59 -0400283bytes_translate_impl(PyBytesObject *self, PyObject *table, int group_right_1,
284 PyObject *deletechars);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300285
286static PyObject *
287bytes_translate(PyBytesObject *self, PyObject *args)
288{
289 PyObject *return_value = NULL;
290 PyObject *table;
291 int group_right_1 = 0;
292 PyObject *deletechars = NULL;
293
294 switch (PyTuple_GET_SIZE(args)) {
295 case 1:
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300296 if (!PyArg_ParseTuple(args, "O:translate", &table)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300297 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300298 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300299 break;
300 case 2:
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300301 if (!PyArg_ParseTuple(args, "OO:translate", &table, &deletechars)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300302 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300303 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300304 group_right_1 = 1;
305 break;
306 default:
307 PyErr_SetString(PyExc_TypeError, "bytes.translate requires 1 to 2 arguments");
308 goto exit;
309 }
310 return_value = bytes_translate_impl(self, table, group_right_1, deletechars);
311
312exit:
313 return return_value;
314}
315
316PyDoc_STRVAR(bytes_maketrans__doc__,
317"maketrans(frm, to, /)\n"
318"--\n"
319"\n"
320"Return a translation table useable for the bytes or bytearray translate method.\n"
321"\n"
322"The returned table will be one where each byte in frm is mapped to the byte at\n"
323"the same position in to.\n"
324"\n"
325"The bytes objects frm and to must be of the same length.");
326
327#define BYTES_MAKETRANS_METHODDEF \
328 {"maketrans", (PyCFunction)bytes_maketrans, METH_VARARGS|METH_STATIC, bytes_maketrans__doc__},
329
330static PyObject *
331bytes_maketrans_impl(Py_buffer *frm, Py_buffer *to);
332
333static PyObject *
334bytes_maketrans(void *null, PyObject *args)
335{
336 PyObject *return_value = NULL;
337 Py_buffer frm = {NULL, NULL};
338 Py_buffer to = {NULL, NULL};
339
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300340 if (!PyArg_ParseTuple(args, "y*y*:maketrans",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300341 &frm, &to)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300342 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300343 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300344 return_value = bytes_maketrans_impl(&frm, &to);
345
346exit:
347 /* Cleanup for frm */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300348 if (frm.obj) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300349 PyBuffer_Release(&frm);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300350 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300351 /* Cleanup for to */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300352 if (to.obj) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300353 PyBuffer_Release(&to);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300354 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300355
356 return return_value;
357}
358
359PyDoc_STRVAR(bytes_replace__doc__,
360"replace($self, old, new, count=-1, /)\n"
361"--\n"
362"\n"
363"Return a copy with all occurrences of substring old replaced by new.\n"
364"\n"
365" count\n"
366" Maximum number of occurrences to replace.\n"
367" -1 (the default value) means replace all occurrences.\n"
368"\n"
369"If the optional argument count is given, only the first count occurrences are\n"
370"replaced.");
371
372#define BYTES_REPLACE_METHODDEF \
373 {"replace", (PyCFunction)bytes_replace, METH_VARARGS, bytes_replace__doc__},
374
375static PyObject *
Serhiy Storchaka7a9579c2016-05-02 13:45:20 +0300376bytes_replace_impl(PyBytesObject *self, Py_buffer *old, Py_buffer *new,
Larry Hastings89964c42015-04-14 18:07:59 -0400377 Py_ssize_t count);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300378
379static PyObject *
Serhiy Storchaka7a9579c2016-05-02 13:45:20 +0300380bytes_replace(PyBytesObject *self, PyObject *args)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300381{
382 PyObject *return_value = NULL;
383 Py_buffer old = {NULL, NULL};
384 Py_buffer new = {NULL, NULL};
385 Py_ssize_t count = -1;
386
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300387 if (!PyArg_ParseTuple(args, "y*y*|n:replace",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300388 &old, &new, &count)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300389 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300390 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300391 return_value = bytes_replace_impl(self, &old, &new, count);
392
393exit:
394 /* Cleanup for old */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300395 if (old.obj) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300396 PyBuffer_Release(&old);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300397 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300398 /* Cleanup for new */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300399 if (new.obj) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300400 PyBuffer_Release(&new);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300401 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300402
403 return return_value;
404}
405
406PyDoc_STRVAR(bytes_decode__doc__,
407"decode($self, /, encoding=\'utf-8\', errors=\'strict\')\n"
408"--\n"
409"\n"
410"Decode the bytes using the codec registered for encoding.\n"
411"\n"
412" encoding\n"
413" The encoding with which to decode the bytes.\n"
414" errors\n"
415" The error handling scheme to use for the handling of decoding errors.\n"
416" The default is \'strict\' meaning that decoding errors raise a\n"
417" UnicodeDecodeError. Other possible values are \'ignore\' and \'replace\'\n"
418" as well as any other name registered with codecs.register_error that\n"
419" can handle UnicodeDecodeErrors.");
420
421#define BYTES_DECODE_METHODDEF \
422 {"decode", (PyCFunction)bytes_decode, METH_VARARGS|METH_KEYWORDS, bytes_decode__doc__},
423
424static PyObject *
Serhiy Storchaka7a9579c2016-05-02 13:45:20 +0300425bytes_decode_impl(PyBytesObject *self, const char *encoding,
Larry Hastings89964c42015-04-14 18:07:59 -0400426 const char *errors);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300427
428static PyObject *
Serhiy Storchaka7a9579c2016-05-02 13:45:20 +0300429bytes_decode(PyBytesObject *self, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300430{
431 PyObject *return_value = NULL;
432 static char *_keywords[] = {"encoding", "errors", NULL};
433 const char *encoding = NULL;
434 const char *errors = NULL;
435
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300436 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|ss:decode", _keywords,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300437 &encoding, &errors)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300438 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300439 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300440 return_value = bytes_decode_impl(self, encoding, errors);
441
442exit:
443 return return_value;
444}
445
446PyDoc_STRVAR(bytes_splitlines__doc__,
447"splitlines($self, /, keepends=False)\n"
448"--\n"
449"\n"
450"Return a list of the lines in the bytes, breaking at line boundaries.\n"
451"\n"
452"Line breaks are not included in the resulting list unless keepends is given and\n"
453"true.");
454
455#define BYTES_SPLITLINES_METHODDEF \
456 {"splitlines", (PyCFunction)bytes_splitlines, METH_VARARGS|METH_KEYWORDS, bytes_splitlines__doc__},
457
458static PyObject *
Serhiy Storchaka7a9579c2016-05-02 13:45:20 +0300459bytes_splitlines_impl(PyBytesObject *self, int keepends);
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300460
461static PyObject *
Serhiy Storchaka7a9579c2016-05-02 13:45:20 +0300462bytes_splitlines(PyBytesObject *self, PyObject *args, PyObject *kwargs)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300463{
464 PyObject *return_value = NULL;
465 static char *_keywords[] = {"keepends", NULL};
466 int keepends = 0;
467
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300468 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|i:splitlines", _keywords,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300469 &keepends)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300470 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300471 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300472 return_value = bytes_splitlines_impl(self, keepends);
473
474exit:
475 return return_value;
476}
477
478PyDoc_STRVAR(bytes_fromhex__doc__,
479"fromhex($type, string, /)\n"
480"--\n"
481"\n"
482"Create a bytes object from a string of hexadecimal numbers.\n"
483"\n"
484"Spaces between two numbers are accepted.\n"
485"Example: bytes.fromhex(\'B9 01EF\') -> b\'\\\\xb9\\\\x01\\\\xef\'.");
486
487#define BYTES_FROMHEX_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300488 {"fromhex", (PyCFunction)bytes_fromhex, METH_O|METH_CLASS, bytes_fromhex__doc__},
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300489
490static PyObject *
491bytes_fromhex_impl(PyTypeObject *type, PyObject *string);
492
493static PyObject *
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300494bytes_fromhex(PyTypeObject *type, PyObject *arg)
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300495{
496 PyObject *return_value = NULL;
497 PyObject *string;
498
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300499 if (!PyArg_Parse(arg, "U:fromhex", &string)) {
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300500 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300501 }
Serhiy Storchaka1009bf12015-04-03 23:53:51 +0300502 return_value = bytes_fromhex_impl(type, string);
503
504exit:
505 return return_value;
506}
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300507/*[clinic end generated code: output=6fe884a74e7d49cf input=a9049054013a1b77]*/