Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1 | /*[clinic input] |
| 2 | preserve |
| 3 | [clinic start generated code]*/ |
| 4 | |
| 5 | PyDoc_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 | |
| 22 | static PyObject * |
| 23 | bytes_split_impl(PyBytesObject*self, PyObject *sep, Py_ssize_t maxsplit); |
| 24 | |
| 25 | static PyObject * |
| 26 | bytes_split(PyBytesObject*self, PyObject *args, PyObject *kwargs) |
| 27 | { |
| 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 Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 33 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|On:split", _keywords, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 34 | &sep, &maxsplit)) |
| 35 | goto exit; |
| 36 | return_value = bytes_split_impl(self, sep, maxsplit); |
| 37 | |
| 38 | exit: |
| 39 | return return_value; |
| 40 | } |
| 41 | |
| 42 | PyDoc_STRVAR(bytes_partition__doc__, |
| 43 | "partition($self, sep, /)\n" |
| 44 | "--\n" |
| 45 | "\n" |
| 46 | "Partition the bytes into three parts using the given separator.\n" |
| 47 | "\n" |
| 48 | "This will search for the separator sep in the bytes. If the separator is found,\n" |
| 49 | "returns a 3-tuple containing the part before the separator, the separator\n" |
| 50 | "itself, and the part after it.\n" |
| 51 | "\n" |
| 52 | "If the separator is not found, returns a 3-tuple containing the original bytes\n" |
| 53 | "object and two empty bytes objects."); |
| 54 | |
| 55 | #define BYTES_PARTITION_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 56 | {"partition", (PyCFunction)bytes_partition, METH_O, bytes_partition__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 57 | |
| 58 | static PyObject * |
| 59 | bytes_partition_impl(PyBytesObject *self, Py_buffer *sep); |
| 60 | |
| 61 | static PyObject * |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 62 | bytes_partition(PyBytesObject *self, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 63 | { |
| 64 | PyObject *return_value = NULL; |
| 65 | Py_buffer sep = {NULL, NULL}; |
| 66 | |
Serhiy Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 67 | if (!PyArg_Parse(arg, "y*:partition", &sep)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 68 | goto exit; |
| 69 | return_value = bytes_partition_impl(self, &sep); |
| 70 | |
| 71 | exit: |
| 72 | /* Cleanup for sep */ |
| 73 | if (sep.obj) |
| 74 | PyBuffer_Release(&sep); |
| 75 | |
| 76 | return return_value; |
| 77 | } |
| 78 | |
| 79 | PyDoc_STRVAR(bytes_rpartition__doc__, |
| 80 | "rpartition($self, sep, /)\n" |
| 81 | "--\n" |
| 82 | "\n" |
| 83 | "Partition the bytes into three parts using the given separator.\n" |
| 84 | "\n" |
| 85 | "This will search for the separator sep in the bytes, starting and the end. If\n" |
| 86 | "the separator is found, returns a 3-tuple containing the part before the\n" |
| 87 | "separator, the separator itself, and the part after it.\n" |
| 88 | "\n" |
| 89 | "If the separator is not found, returns a 3-tuple containing two empty bytes\n" |
| 90 | "objects and the original bytes object."); |
| 91 | |
| 92 | #define BYTES_RPARTITION_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 93 | {"rpartition", (PyCFunction)bytes_rpartition, METH_O, bytes_rpartition__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 94 | |
| 95 | static PyObject * |
| 96 | bytes_rpartition_impl(PyBytesObject *self, Py_buffer *sep); |
| 97 | |
| 98 | static PyObject * |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 99 | bytes_rpartition(PyBytesObject *self, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 100 | { |
| 101 | PyObject *return_value = NULL; |
| 102 | Py_buffer sep = {NULL, NULL}; |
| 103 | |
Serhiy Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 104 | if (!PyArg_Parse(arg, "y*:rpartition", &sep)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 105 | goto exit; |
| 106 | return_value = bytes_rpartition_impl(self, &sep); |
| 107 | |
| 108 | exit: |
| 109 | /* Cleanup for sep */ |
| 110 | if (sep.obj) |
| 111 | PyBuffer_Release(&sep); |
| 112 | |
| 113 | return return_value; |
| 114 | } |
| 115 | |
| 116 | PyDoc_STRVAR(bytes_rsplit__doc__, |
| 117 | "rsplit($self, /, sep=None, maxsplit=-1)\n" |
| 118 | "--\n" |
| 119 | "\n" |
| 120 | "Return a list of the sections in the bytes, using sep as the delimiter.\n" |
| 121 | "\n" |
| 122 | " sep\n" |
| 123 | " The delimiter according which to split the bytes.\n" |
| 124 | " None (the default value) means split on ASCII whitespace characters\n" |
| 125 | " (space, tab, return, newline, formfeed, vertical tab).\n" |
| 126 | " maxsplit\n" |
| 127 | " Maximum number of splits to do.\n" |
| 128 | " -1 (the default value) means no limit.\n" |
| 129 | "\n" |
| 130 | "Splitting is done starting at the end of the bytes and working to the front."); |
| 131 | |
| 132 | #define BYTES_RSPLIT_METHODDEF \ |
| 133 | {"rsplit", (PyCFunction)bytes_rsplit, METH_VARARGS|METH_KEYWORDS, bytes_rsplit__doc__}, |
| 134 | |
| 135 | static PyObject * |
| 136 | bytes_rsplit_impl(PyBytesObject*self, PyObject *sep, Py_ssize_t maxsplit); |
| 137 | |
| 138 | static PyObject * |
| 139 | bytes_rsplit(PyBytesObject*self, PyObject *args, PyObject *kwargs) |
| 140 | { |
| 141 | PyObject *return_value = NULL; |
| 142 | static char *_keywords[] = {"sep", "maxsplit", NULL}; |
| 143 | PyObject *sep = Py_None; |
| 144 | Py_ssize_t maxsplit = -1; |
| 145 | |
Serhiy Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 146 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|On:rsplit", _keywords, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 147 | &sep, &maxsplit)) |
| 148 | goto exit; |
| 149 | return_value = bytes_rsplit_impl(self, sep, maxsplit); |
| 150 | |
| 151 | exit: |
| 152 | return return_value; |
| 153 | } |
| 154 | |
| 155 | PyDoc_STRVAR(bytes_join__doc__, |
| 156 | "join($self, iterable_of_bytes, /)\n" |
| 157 | "--\n" |
| 158 | "\n" |
| 159 | "Concatenate any number of bytes objects.\n" |
| 160 | "\n" |
| 161 | "The bytes whose method is called is inserted in between each pair.\n" |
| 162 | "\n" |
| 163 | "The result is returned as a new bytes object.\n" |
| 164 | "\n" |
| 165 | "Example: b\'.\'.join([b\'ab\', b\'pq\', b\'rs\']) -> b\'ab.pq.rs\'."); |
| 166 | |
| 167 | #define BYTES_JOIN_METHODDEF \ |
| 168 | {"join", (PyCFunction)bytes_join, METH_O, bytes_join__doc__}, |
| 169 | |
| 170 | PyDoc_STRVAR(bytes_strip__doc__, |
| 171 | "strip($self, bytes=None, /)\n" |
| 172 | "--\n" |
| 173 | "\n" |
| 174 | "Strip leading and trailing bytes contained in the argument.\n" |
| 175 | "\n" |
| 176 | "If the argument is omitted or None, strip leading and trailing ASCII whitespace."); |
| 177 | |
| 178 | #define BYTES_STRIP_METHODDEF \ |
| 179 | {"strip", (PyCFunction)bytes_strip, METH_VARARGS, bytes_strip__doc__}, |
| 180 | |
| 181 | static PyObject * |
| 182 | bytes_strip_impl(PyBytesObject *self, PyObject *bytes); |
| 183 | |
| 184 | static PyObject * |
| 185 | bytes_strip(PyBytesObject *self, PyObject *args) |
| 186 | { |
| 187 | PyObject *return_value = NULL; |
| 188 | PyObject *bytes = Py_None; |
| 189 | |
| 190 | if (!PyArg_UnpackTuple(args, "strip", |
| 191 | 0, 1, |
| 192 | &bytes)) |
| 193 | goto exit; |
| 194 | return_value = bytes_strip_impl(self, bytes); |
| 195 | |
| 196 | exit: |
| 197 | return return_value; |
| 198 | } |
| 199 | |
| 200 | PyDoc_STRVAR(bytes_lstrip__doc__, |
| 201 | "lstrip($self, bytes=None, /)\n" |
| 202 | "--\n" |
| 203 | "\n" |
| 204 | "Strip leading bytes contained in the argument.\n" |
| 205 | "\n" |
| 206 | "If the argument is omitted or None, strip leading ASCII whitespace."); |
| 207 | |
| 208 | #define BYTES_LSTRIP_METHODDEF \ |
| 209 | {"lstrip", (PyCFunction)bytes_lstrip, METH_VARARGS, bytes_lstrip__doc__}, |
| 210 | |
| 211 | static PyObject * |
| 212 | bytes_lstrip_impl(PyBytesObject *self, PyObject *bytes); |
| 213 | |
| 214 | static PyObject * |
| 215 | bytes_lstrip(PyBytesObject *self, PyObject *args) |
| 216 | { |
| 217 | PyObject *return_value = NULL; |
| 218 | PyObject *bytes = Py_None; |
| 219 | |
| 220 | if (!PyArg_UnpackTuple(args, "lstrip", |
| 221 | 0, 1, |
| 222 | &bytes)) |
| 223 | goto exit; |
| 224 | return_value = bytes_lstrip_impl(self, bytes); |
| 225 | |
| 226 | exit: |
| 227 | return return_value; |
| 228 | } |
| 229 | |
| 230 | PyDoc_STRVAR(bytes_rstrip__doc__, |
| 231 | "rstrip($self, bytes=None, /)\n" |
| 232 | "--\n" |
| 233 | "\n" |
| 234 | "Strip trailing bytes contained in the argument.\n" |
| 235 | "\n" |
| 236 | "If the argument is omitted or None, strip trailing ASCII whitespace."); |
| 237 | |
| 238 | #define BYTES_RSTRIP_METHODDEF \ |
| 239 | {"rstrip", (PyCFunction)bytes_rstrip, METH_VARARGS, bytes_rstrip__doc__}, |
| 240 | |
| 241 | static PyObject * |
| 242 | bytes_rstrip_impl(PyBytesObject *self, PyObject *bytes); |
| 243 | |
| 244 | static PyObject * |
| 245 | bytes_rstrip(PyBytesObject *self, PyObject *args) |
| 246 | { |
| 247 | PyObject *return_value = NULL; |
| 248 | PyObject *bytes = Py_None; |
| 249 | |
| 250 | if (!PyArg_UnpackTuple(args, "rstrip", |
| 251 | 0, 1, |
| 252 | &bytes)) |
| 253 | goto exit; |
| 254 | return_value = bytes_rstrip_impl(self, bytes); |
| 255 | |
| 256 | exit: |
| 257 | return return_value; |
| 258 | } |
| 259 | |
| 260 | PyDoc_STRVAR(bytes_translate__doc__, |
| 261 | "translate(table, [deletechars])\n" |
| 262 | "Return a copy with each character mapped by the given translation table.\n" |
| 263 | "\n" |
| 264 | " table\n" |
| 265 | " Translation table, which must be a bytes object of length 256.\n" |
| 266 | "\n" |
| 267 | "All characters occurring in the optional argument deletechars are removed.\n" |
| 268 | "The remaining characters are mapped through the given translation table."); |
| 269 | |
| 270 | #define BYTES_TRANSLATE_METHODDEF \ |
| 271 | {"translate", (PyCFunction)bytes_translate, METH_VARARGS, bytes_translate__doc__}, |
| 272 | |
| 273 | static PyObject * |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 274 | bytes_translate_impl(PyBytesObject *self, PyObject *table, int group_right_1, |
| 275 | PyObject *deletechars); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 276 | |
| 277 | static PyObject * |
| 278 | bytes_translate(PyBytesObject *self, PyObject *args) |
| 279 | { |
| 280 | PyObject *return_value = NULL; |
| 281 | PyObject *table; |
| 282 | int group_right_1 = 0; |
| 283 | PyObject *deletechars = NULL; |
| 284 | |
| 285 | switch (PyTuple_GET_SIZE(args)) { |
| 286 | case 1: |
| 287 | if (!PyArg_ParseTuple(args, "O:translate", &table)) |
| 288 | goto exit; |
| 289 | break; |
| 290 | case 2: |
| 291 | if (!PyArg_ParseTuple(args, "OO:translate", &table, &deletechars)) |
| 292 | goto exit; |
| 293 | group_right_1 = 1; |
| 294 | break; |
| 295 | default: |
| 296 | PyErr_SetString(PyExc_TypeError, "bytes.translate requires 1 to 2 arguments"); |
| 297 | goto exit; |
| 298 | } |
| 299 | return_value = bytes_translate_impl(self, table, group_right_1, deletechars); |
| 300 | |
| 301 | exit: |
| 302 | return return_value; |
| 303 | } |
| 304 | |
| 305 | PyDoc_STRVAR(bytes_maketrans__doc__, |
| 306 | "maketrans(frm, to, /)\n" |
| 307 | "--\n" |
| 308 | "\n" |
| 309 | "Return a translation table useable for the bytes or bytearray translate method.\n" |
| 310 | "\n" |
| 311 | "The returned table will be one where each byte in frm is mapped to the byte at\n" |
| 312 | "the same position in to.\n" |
| 313 | "\n" |
| 314 | "The bytes objects frm and to must be of the same length."); |
| 315 | |
| 316 | #define BYTES_MAKETRANS_METHODDEF \ |
| 317 | {"maketrans", (PyCFunction)bytes_maketrans, METH_VARARGS|METH_STATIC, bytes_maketrans__doc__}, |
| 318 | |
| 319 | static PyObject * |
| 320 | bytes_maketrans_impl(Py_buffer *frm, Py_buffer *to); |
| 321 | |
| 322 | static PyObject * |
| 323 | bytes_maketrans(void *null, PyObject *args) |
| 324 | { |
| 325 | PyObject *return_value = NULL; |
| 326 | Py_buffer frm = {NULL, NULL}; |
| 327 | Py_buffer to = {NULL, NULL}; |
| 328 | |
Serhiy Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 329 | if (!PyArg_ParseTuple(args, "y*y*:maketrans", |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 330 | &frm, &to)) |
| 331 | goto exit; |
| 332 | return_value = bytes_maketrans_impl(&frm, &to); |
| 333 | |
| 334 | exit: |
| 335 | /* Cleanup for frm */ |
| 336 | if (frm.obj) |
| 337 | PyBuffer_Release(&frm); |
| 338 | /* Cleanup for to */ |
| 339 | if (to.obj) |
| 340 | PyBuffer_Release(&to); |
| 341 | |
| 342 | return return_value; |
| 343 | } |
| 344 | |
| 345 | PyDoc_STRVAR(bytes_replace__doc__, |
| 346 | "replace($self, old, new, count=-1, /)\n" |
| 347 | "--\n" |
| 348 | "\n" |
| 349 | "Return a copy with all occurrences of substring old replaced by new.\n" |
| 350 | "\n" |
| 351 | " count\n" |
| 352 | " Maximum number of occurrences to replace.\n" |
| 353 | " -1 (the default value) means replace all occurrences.\n" |
| 354 | "\n" |
| 355 | "If the optional argument count is given, only the first count occurrences are\n" |
| 356 | "replaced."); |
| 357 | |
| 358 | #define BYTES_REPLACE_METHODDEF \ |
| 359 | {"replace", (PyCFunction)bytes_replace, METH_VARARGS, bytes_replace__doc__}, |
| 360 | |
| 361 | static PyObject * |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 362 | bytes_replace_impl(PyBytesObject*self, Py_buffer *old, Py_buffer *new, |
| 363 | Py_ssize_t count); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 364 | |
| 365 | static PyObject * |
| 366 | bytes_replace(PyBytesObject*self, PyObject *args) |
| 367 | { |
| 368 | PyObject *return_value = NULL; |
| 369 | Py_buffer old = {NULL, NULL}; |
| 370 | Py_buffer new = {NULL, NULL}; |
| 371 | Py_ssize_t count = -1; |
| 372 | |
Serhiy Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 373 | if (!PyArg_ParseTuple(args, "y*y*|n:replace", |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 374 | &old, &new, &count)) |
| 375 | goto exit; |
| 376 | return_value = bytes_replace_impl(self, &old, &new, count); |
| 377 | |
| 378 | exit: |
| 379 | /* Cleanup for old */ |
| 380 | if (old.obj) |
| 381 | PyBuffer_Release(&old); |
| 382 | /* Cleanup for new */ |
| 383 | if (new.obj) |
| 384 | PyBuffer_Release(&new); |
| 385 | |
| 386 | return return_value; |
| 387 | } |
| 388 | |
| 389 | PyDoc_STRVAR(bytes_decode__doc__, |
| 390 | "decode($self, /, encoding=\'utf-8\', errors=\'strict\')\n" |
| 391 | "--\n" |
| 392 | "\n" |
| 393 | "Decode the bytes using the codec registered for encoding.\n" |
| 394 | "\n" |
| 395 | " encoding\n" |
| 396 | " The encoding with which to decode the bytes.\n" |
| 397 | " errors\n" |
| 398 | " The error handling scheme to use for the handling of decoding errors.\n" |
| 399 | " The default is \'strict\' meaning that decoding errors raise a\n" |
| 400 | " UnicodeDecodeError. Other possible values are \'ignore\' and \'replace\'\n" |
| 401 | " as well as any other name registered with codecs.register_error that\n" |
| 402 | " can handle UnicodeDecodeErrors."); |
| 403 | |
| 404 | #define BYTES_DECODE_METHODDEF \ |
| 405 | {"decode", (PyCFunction)bytes_decode, METH_VARARGS|METH_KEYWORDS, bytes_decode__doc__}, |
| 406 | |
| 407 | static PyObject * |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 408 | bytes_decode_impl(PyBytesObject*self, const char *encoding, |
| 409 | const char *errors); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 410 | |
| 411 | static PyObject * |
| 412 | bytes_decode(PyBytesObject*self, PyObject *args, PyObject *kwargs) |
| 413 | { |
| 414 | PyObject *return_value = NULL; |
| 415 | static char *_keywords[] = {"encoding", "errors", NULL}; |
| 416 | const char *encoding = NULL; |
| 417 | const char *errors = NULL; |
| 418 | |
Serhiy Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 419 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|ss:decode", _keywords, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 420 | &encoding, &errors)) |
| 421 | goto exit; |
| 422 | return_value = bytes_decode_impl(self, encoding, errors); |
| 423 | |
| 424 | exit: |
| 425 | return return_value; |
| 426 | } |
| 427 | |
| 428 | PyDoc_STRVAR(bytes_splitlines__doc__, |
| 429 | "splitlines($self, /, keepends=False)\n" |
| 430 | "--\n" |
| 431 | "\n" |
| 432 | "Return a list of the lines in the bytes, breaking at line boundaries.\n" |
| 433 | "\n" |
| 434 | "Line breaks are not included in the resulting list unless keepends is given and\n" |
| 435 | "true."); |
| 436 | |
| 437 | #define BYTES_SPLITLINES_METHODDEF \ |
| 438 | {"splitlines", (PyCFunction)bytes_splitlines, METH_VARARGS|METH_KEYWORDS, bytes_splitlines__doc__}, |
| 439 | |
| 440 | static PyObject * |
| 441 | bytes_splitlines_impl(PyBytesObject*self, int keepends); |
| 442 | |
| 443 | static PyObject * |
| 444 | bytes_splitlines(PyBytesObject*self, PyObject *args, PyObject *kwargs) |
| 445 | { |
| 446 | PyObject *return_value = NULL; |
| 447 | static char *_keywords[] = {"keepends", NULL}; |
| 448 | int keepends = 0; |
| 449 | |
Serhiy Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 450 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|i:splitlines", _keywords, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 451 | &keepends)) |
| 452 | goto exit; |
| 453 | return_value = bytes_splitlines_impl(self, keepends); |
| 454 | |
| 455 | exit: |
| 456 | return return_value; |
| 457 | } |
| 458 | |
| 459 | PyDoc_STRVAR(bytes_fromhex__doc__, |
| 460 | "fromhex($type, string, /)\n" |
| 461 | "--\n" |
| 462 | "\n" |
| 463 | "Create a bytes object from a string of hexadecimal numbers.\n" |
| 464 | "\n" |
| 465 | "Spaces between two numbers are accepted.\n" |
| 466 | "Example: bytes.fromhex(\'B9 01EF\') -> b\'\\\\xb9\\\\x01\\\\xef\'."); |
| 467 | |
| 468 | #define BYTES_FROMHEX_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 469 | {"fromhex", (PyCFunction)bytes_fromhex, METH_O|METH_CLASS, bytes_fromhex__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 470 | |
| 471 | static PyObject * |
| 472 | bytes_fromhex_impl(PyTypeObject *type, PyObject *string); |
| 473 | |
| 474 | static PyObject * |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 475 | bytes_fromhex(PyTypeObject *type, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 476 | { |
| 477 | PyObject *return_value = NULL; |
| 478 | PyObject *string; |
| 479 | |
Serhiy Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 480 | if (!PyArg_Parse(arg, "U:fromhex", &string)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 481 | goto exit; |
| 482 | return_value = bytes_fromhex_impl(type, string); |
| 483 | |
| 484 | exit: |
| 485 | return return_value; |
| 486 | } |
Serhiy Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 487 | /*[clinic end generated code: output=bd0ce8f25d7e18f4 input=a9049054013a1b77]*/ |