Tal Einat | 3286ce4 | 2018-09-10 21:33:08 +0300 | [diff] [blame] | 1 | /*[clinic input] |
| 2 | preserve |
| 3 | [clinic start generated code]*/ |
| 4 | |
| 5 | PyDoc_STRVAR(itertools_groupby__doc__, |
| 6 | "groupby(iterable, key=None)\n" |
| 7 | "--\n" |
| 8 | "\n" |
| 9 | "make an iterator that returns consecutive keys and groups from the iterable\n" |
| 10 | "\n" |
| 11 | " iterable\n" |
| 12 | " Elements to divide into groups according to the key function.\n" |
| 13 | " key\n" |
| 14 | " A function for computing the group category for each element.\n" |
| 15 | " If the key function is not specified or is None, the element itself\n" |
| 16 | " is used for grouping."); |
| 17 | |
| 18 | static PyObject * |
| 19 | itertools_groupby_impl(PyTypeObject *type, PyObject *it, PyObject *keyfunc); |
| 20 | |
| 21 | static PyObject * |
| 22 | itertools_groupby(PyTypeObject *type, PyObject *args, PyObject *kwargs) |
| 23 | { |
| 24 | PyObject *return_value = NULL; |
| 25 | static const char * const _keywords[] = {"iterable", "key", NULL}; |
| 26 | static _PyArg_Parser _parser = {"O|O:groupby", _keywords, 0}; |
| 27 | PyObject *it; |
| 28 | PyObject *keyfunc = Py_None; |
| 29 | |
| 30 | if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser, |
| 31 | &it, &keyfunc)) { |
| 32 | goto exit; |
| 33 | } |
| 34 | return_value = itertools_groupby_impl(type, it, keyfunc); |
| 35 | |
| 36 | exit: |
| 37 | return return_value; |
| 38 | } |
| 39 | |
| 40 | static PyObject * |
| 41 | itertools__grouper_impl(PyTypeObject *type, PyObject *parent, |
| 42 | PyObject *tgtkey); |
| 43 | |
| 44 | static PyObject * |
| 45 | itertools__grouper(PyTypeObject *type, PyObject *args, PyObject *kwargs) |
| 46 | { |
| 47 | PyObject *return_value = NULL; |
| 48 | PyObject *parent; |
| 49 | PyObject *tgtkey; |
| 50 | |
| 51 | if ((type == &_grouper_type) && |
| 52 | !_PyArg_NoKeywords("_grouper", kwargs)) { |
| 53 | goto exit; |
| 54 | } |
| 55 | if (!PyArg_ParseTuple(args, "O!O:_grouper", |
| 56 | &groupby_type, &parent, &tgtkey)) { |
| 57 | goto exit; |
| 58 | } |
| 59 | return_value = itertools__grouper_impl(type, parent, tgtkey); |
| 60 | |
| 61 | exit: |
| 62 | return return_value; |
| 63 | } |
Tal Einat | c4bccd3 | 2018-09-12 00:49:13 +0300 | [diff] [blame] | 64 | |
| 65 | PyDoc_STRVAR(itertools_teedataobject__doc__, |
| 66 | "teedataobject(iterable, values, next, /)\n" |
| 67 | "--\n" |
| 68 | "\n" |
| 69 | "Data container common to multiple tee objects."); |
| 70 | |
| 71 | static PyObject * |
| 72 | itertools_teedataobject_impl(PyTypeObject *type, PyObject *it, |
| 73 | PyObject *values, PyObject *next); |
| 74 | |
| 75 | static PyObject * |
| 76 | itertools_teedataobject(PyTypeObject *type, PyObject *args, PyObject *kwargs) |
| 77 | { |
| 78 | PyObject *return_value = NULL; |
| 79 | PyObject *it; |
| 80 | PyObject *values; |
| 81 | PyObject *next; |
| 82 | |
| 83 | if ((type == &teedataobject_type) && |
| 84 | !_PyArg_NoKeywords("teedataobject", kwargs)) { |
| 85 | goto exit; |
| 86 | } |
| 87 | if (!PyArg_ParseTuple(args, "OO!O:teedataobject", |
| 88 | &it, &PyList_Type, &values, &next)) { |
| 89 | goto exit; |
| 90 | } |
| 91 | return_value = itertools_teedataobject_impl(type, it, values, next); |
| 92 | |
| 93 | exit: |
| 94 | return return_value; |
| 95 | } |
| 96 | |
| 97 | PyDoc_STRVAR(itertools__tee__doc__, |
| 98 | "_tee(iterable, /)\n" |
| 99 | "--\n" |
| 100 | "\n" |
| 101 | "Iterator wrapped to make it copyable."); |
| 102 | |
| 103 | static PyObject * |
| 104 | itertools__tee_impl(PyTypeObject *type, PyObject *iterable); |
| 105 | |
| 106 | static PyObject * |
| 107 | itertools__tee(PyTypeObject *type, PyObject *args, PyObject *kwargs) |
| 108 | { |
| 109 | PyObject *return_value = NULL; |
| 110 | PyObject *iterable; |
| 111 | |
| 112 | if ((type == &tee_type) && |
| 113 | !_PyArg_NoKeywords("_tee", kwargs)) { |
| 114 | goto exit; |
| 115 | } |
| 116 | if (!PyArg_UnpackTuple(args, "_tee", |
| 117 | 1, 1, |
| 118 | &iterable)) { |
| 119 | goto exit; |
| 120 | } |
| 121 | return_value = itertools__tee_impl(type, iterable); |
| 122 | |
| 123 | exit: |
| 124 | return return_value; |
| 125 | } |
| 126 | |
| 127 | PyDoc_STRVAR(itertools_tee__doc__, |
| 128 | "tee($module, iterable, n=2, /)\n" |
| 129 | "--\n" |
| 130 | "\n" |
| 131 | "Returns a tuple of n independent iterators."); |
| 132 | |
| 133 | #define ITERTOOLS_TEE_METHODDEF \ |
| 134 | {"tee", (PyCFunction)itertools_tee, METH_FASTCALL, itertools_tee__doc__}, |
| 135 | |
| 136 | static PyObject * |
| 137 | itertools_tee_impl(PyObject *module, PyObject *iterable, Py_ssize_t n); |
| 138 | |
| 139 | static PyObject * |
| 140 | itertools_tee(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
| 141 | { |
| 142 | PyObject *return_value = NULL; |
| 143 | PyObject *iterable; |
| 144 | Py_ssize_t n = 2; |
| 145 | |
| 146 | if (!_PyArg_ParseStack(args, nargs, "O|n:tee", |
| 147 | &iterable, &n)) { |
| 148 | goto exit; |
| 149 | } |
| 150 | return_value = itertools_tee_impl(module, iterable, n); |
| 151 | |
| 152 | exit: |
| 153 | return return_value; |
| 154 | } |
| 155 | |
| 156 | PyDoc_STRVAR(itertools_cycle__doc__, |
| 157 | "cycle(iterable, /)\n" |
| 158 | "--\n" |
| 159 | "\n" |
| 160 | "Return elements from the iterable until it is exhausted. Then repeat the sequence indefinitely."); |
| 161 | |
| 162 | static PyObject * |
| 163 | itertools_cycle_impl(PyTypeObject *type, PyObject *iterable); |
| 164 | |
| 165 | static PyObject * |
| 166 | itertools_cycle(PyTypeObject *type, PyObject *args, PyObject *kwargs) |
| 167 | { |
| 168 | PyObject *return_value = NULL; |
| 169 | PyObject *iterable; |
| 170 | |
| 171 | if ((type == &cycle_type) && |
| 172 | !_PyArg_NoKeywords("cycle", kwargs)) { |
| 173 | goto exit; |
| 174 | } |
| 175 | if (!PyArg_UnpackTuple(args, "cycle", |
| 176 | 1, 1, |
| 177 | &iterable)) { |
| 178 | goto exit; |
| 179 | } |
| 180 | return_value = itertools_cycle_impl(type, iterable); |
| 181 | |
| 182 | exit: |
| 183 | return return_value; |
| 184 | } |
| 185 | |
| 186 | PyDoc_STRVAR(itertools_dropwhile__doc__, |
| 187 | "dropwhile(predicate, iterable, /)\n" |
| 188 | "--\n" |
| 189 | "\n" |
| 190 | "Drop items from the iterable while predicate(item) is true.\n" |
| 191 | "\n" |
| 192 | "Afterwards, return every element until the iterable is exhausted."); |
| 193 | |
| 194 | static PyObject * |
| 195 | itertools_dropwhile_impl(PyTypeObject *type, PyObject *func, PyObject *seq); |
| 196 | |
| 197 | static PyObject * |
| 198 | itertools_dropwhile(PyTypeObject *type, PyObject *args, PyObject *kwargs) |
| 199 | { |
| 200 | PyObject *return_value = NULL; |
| 201 | PyObject *func; |
| 202 | PyObject *seq; |
| 203 | |
| 204 | if ((type == &dropwhile_type) && |
| 205 | !_PyArg_NoKeywords("dropwhile", kwargs)) { |
| 206 | goto exit; |
| 207 | } |
| 208 | if (!PyArg_UnpackTuple(args, "dropwhile", |
| 209 | 2, 2, |
| 210 | &func, &seq)) { |
| 211 | goto exit; |
| 212 | } |
| 213 | return_value = itertools_dropwhile_impl(type, func, seq); |
| 214 | |
| 215 | exit: |
| 216 | return return_value; |
| 217 | } |
| 218 | |
| 219 | PyDoc_STRVAR(itertools_takewhile__doc__, |
| 220 | "takewhile(predicate, iterable, /)\n" |
| 221 | "--\n" |
| 222 | "\n" |
| 223 | "Return successive entries from an iterable as long as the predicate evaluates to true for each entry."); |
| 224 | |
| 225 | static PyObject * |
| 226 | itertools_takewhile_impl(PyTypeObject *type, PyObject *func, PyObject *seq); |
| 227 | |
| 228 | static PyObject * |
| 229 | itertools_takewhile(PyTypeObject *type, PyObject *args, PyObject *kwargs) |
| 230 | { |
| 231 | PyObject *return_value = NULL; |
| 232 | PyObject *func; |
| 233 | PyObject *seq; |
| 234 | |
| 235 | if ((type == &takewhile_type) && |
| 236 | !_PyArg_NoKeywords("takewhile", kwargs)) { |
| 237 | goto exit; |
| 238 | } |
| 239 | if (!PyArg_UnpackTuple(args, "takewhile", |
| 240 | 2, 2, |
| 241 | &func, &seq)) { |
| 242 | goto exit; |
| 243 | } |
| 244 | return_value = itertools_takewhile_impl(type, func, seq); |
| 245 | |
| 246 | exit: |
| 247 | return return_value; |
| 248 | } |
| 249 | |
| 250 | PyDoc_STRVAR(itertools_starmap__doc__, |
| 251 | "starmap(function, iterable, /)\n" |
| 252 | "--\n" |
| 253 | "\n" |
| 254 | "Return an iterator whose values are returned from the function evaluated with an argument tuple taken from the given sequence."); |
| 255 | |
| 256 | static PyObject * |
| 257 | itertools_starmap_impl(PyTypeObject *type, PyObject *func, PyObject *seq); |
| 258 | |
| 259 | static PyObject * |
| 260 | itertools_starmap(PyTypeObject *type, PyObject *args, PyObject *kwargs) |
| 261 | { |
| 262 | PyObject *return_value = NULL; |
| 263 | PyObject *func; |
| 264 | PyObject *seq; |
| 265 | |
| 266 | if ((type == &starmap_type) && |
| 267 | !_PyArg_NoKeywords("starmap", kwargs)) { |
| 268 | goto exit; |
| 269 | } |
| 270 | if (!PyArg_UnpackTuple(args, "starmap", |
| 271 | 2, 2, |
| 272 | &func, &seq)) { |
| 273 | goto exit; |
| 274 | } |
| 275 | return_value = itertools_starmap_impl(type, func, seq); |
| 276 | |
| 277 | exit: |
| 278 | return return_value; |
| 279 | } |
| 280 | |
| 281 | PyDoc_STRVAR(itertools_chain_from_iterable__doc__, |
| 282 | "from_iterable($type, iterable, /)\n" |
| 283 | "--\n" |
| 284 | "\n" |
| 285 | "Alternative chain() constructor taking a single iterable argument that evaluates lazily."); |
| 286 | |
| 287 | #define ITERTOOLS_CHAIN_FROM_ITERABLE_METHODDEF \ |
| 288 | {"from_iterable", (PyCFunction)itertools_chain_from_iterable, METH_O|METH_CLASS, itertools_chain_from_iterable__doc__}, |
| 289 | |
| 290 | PyDoc_STRVAR(itertools_combinations__doc__, |
| 291 | "combinations(iterable, r)\n" |
| 292 | "--\n" |
| 293 | "\n" |
| 294 | "Return successive r-length combinations of elements in the iterable.\n" |
| 295 | "\n" |
| 296 | "combinations(range(4), 3) --> (0,1,2), (0,1,3), (0,2,3), (1,2,3)"); |
| 297 | |
| 298 | static PyObject * |
| 299 | itertools_combinations_impl(PyTypeObject *type, PyObject *iterable, |
| 300 | Py_ssize_t r); |
| 301 | |
| 302 | static PyObject * |
| 303 | itertools_combinations(PyTypeObject *type, PyObject *args, PyObject *kwargs) |
| 304 | { |
| 305 | PyObject *return_value = NULL; |
| 306 | static const char * const _keywords[] = {"iterable", "r", NULL}; |
| 307 | static _PyArg_Parser _parser = {"On:combinations", _keywords, 0}; |
| 308 | PyObject *iterable; |
| 309 | Py_ssize_t r; |
| 310 | |
| 311 | if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser, |
| 312 | &iterable, &r)) { |
| 313 | goto exit; |
| 314 | } |
| 315 | return_value = itertools_combinations_impl(type, iterable, r); |
| 316 | |
| 317 | exit: |
| 318 | return return_value; |
| 319 | } |
| 320 | |
| 321 | PyDoc_STRVAR(itertools_combinations_with_replacement__doc__, |
| 322 | "combinations_with_replacement(iterable, r)\n" |
| 323 | "--\n" |
| 324 | "\n" |
| 325 | "Return successive r-length combinations of elements in the iterable allowing individual elements to have successive repeats.\n" |
| 326 | "\n" |
| 327 | "combinations_with_replacement(\'ABC\', 2) --> AA AB AC BB BC CC\""); |
| 328 | |
| 329 | static PyObject * |
| 330 | itertools_combinations_with_replacement_impl(PyTypeObject *type, |
| 331 | PyObject *iterable, |
| 332 | Py_ssize_t r); |
| 333 | |
| 334 | static PyObject * |
| 335 | itertools_combinations_with_replacement(PyTypeObject *type, PyObject *args, PyObject *kwargs) |
| 336 | { |
| 337 | PyObject *return_value = NULL; |
| 338 | static const char * const _keywords[] = {"iterable", "r", NULL}; |
| 339 | static _PyArg_Parser _parser = {"On:combinations_with_replacement", _keywords, 0}; |
| 340 | PyObject *iterable; |
| 341 | Py_ssize_t r; |
| 342 | |
| 343 | if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser, |
| 344 | &iterable, &r)) { |
| 345 | goto exit; |
| 346 | } |
| 347 | return_value = itertools_combinations_with_replacement_impl(type, iterable, r); |
| 348 | |
| 349 | exit: |
| 350 | return return_value; |
| 351 | } |
| 352 | |
| 353 | PyDoc_STRVAR(itertools_permutations__doc__, |
| 354 | "permutations(iterable, r=None)\n" |
| 355 | "--\n" |
| 356 | "\n" |
| 357 | "Return successive r-length permutations of elements in the iterable.\n" |
| 358 | "\n" |
| 359 | "permutations(range(3), 2) --> (0,1), (0,2), (1,0), (1,2), (2,0), (2,1)"); |
| 360 | |
| 361 | static PyObject * |
| 362 | itertools_permutations_impl(PyTypeObject *type, PyObject *iterable, |
| 363 | PyObject *robj); |
| 364 | |
| 365 | static PyObject * |
| 366 | itertools_permutations(PyTypeObject *type, PyObject *args, PyObject *kwargs) |
| 367 | { |
| 368 | PyObject *return_value = NULL; |
| 369 | static const char * const _keywords[] = {"iterable", "r", NULL}; |
| 370 | static _PyArg_Parser _parser = {"O|O:permutations", _keywords, 0}; |
| 371 | PyObject *iterable; |
| 372 | PyObject *robj = Py_None; |
| 373 | |
| 374 | if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser, |
| 375 | &iterable, &robj)) { |
| 376 | goto exit; |
| 377 | } |
| 378 | return_value = itertools_permutations_impl(type, iterable, robj); |
| 379 | |
| 380 | exit: |
| 381 | return return_value; |
| 382 | } |
| 383 | |
| 384 | PyDoc_STRVAR(itertools_accumulate__doc__, |
Lisa Roach | 9718b59 | 2018-09-23 17:34:59 -0700 | [diff] [blame^] | 385 | "accumulate(iterable, func=None, *, initial=None)\n" |
Tal Einat | c4bccd3 | 2018-09-12 00:49:13 +0300 | [diff] [blame] | 386 | "--\n" |
| 387 | "\n" |
| 388 | "Return series of accumulated sums (or other binary function results)."); |
| 389 | |
| 390 | static PyObject * |
| 391 | itertools_accumulate_impl(PyTypeObject *type, PyObject *iterable, |
Lisa Roach | 9718b59 | 2018-09-23 17:34:59 -0700 | [diff] [blame^] | 392 | PyObject *binop, PyObject *initial); |
Tal Einat | c4bccd3 | 2018-09-12 00:49:13 +0300 | [diff] [blame] | 393 | |
| 394 | static PyObject * |
| 395 | itertools_accumulate(PyTypeObject *type, PyObject *args, PyObject *kwargs) |
| 396 | { |
| 397 | PyObject *return_value = NULL; |
Lisa Roach | 9718b59 | 2018-09-23 17:34:59 -0700 | [diff] [blame^] | 398 | static const char * const _keywords[] = {"iterable", "func", "initial", NULL}; |
| 399 | static _PyArg_Parser _parser = {"O|O$O:accumulate", _keywords, 0}; |
Tal Einat | c4bccd3 | 2018-09-12 00:49:13 +0300 | [diff] [blame] | 400 | PyObject *iterable; |
| 401 | PyObject *binop = Py_None; |
Lisa Roach | 9718b59 | 2018-09-23 17:34:59 -0700 | [diff] [blame^] | 402 | PyObject *initial = Py_None; |
Tal Einat | c4bccd3 | 2018-09-12 00:49:13 +0300 | [diff] [blame] | 403 | |
| 404 | if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser, |
Lisa Roach | 9718b59 | 2018-09-23 17:34:59 -0700 | [diff] [blame^] | 405 | &iterable, &binop, &initial)) { |
Tal Einat | c4bccd3 | 2018-09-12 00:49:13 +0300 | [diff] [blame] | 406 | goto exit; |
| 407 | } |
Lisa Roach | 9718b59 | 2018-09-23 17:34:59 -0700 | [diff] [blame^] | 408 | return_value = itertools_accumulate_impl(type, iterable, binop, initial); |
Tal Einat | c4bccd3 | 2018-09-12 00:49:13 +0300 | [diff] [blame] | 409 | |
| 410 | exit: |
| 411 | return return_value; |
| 412 | } |
| 413 | |
| 414 | PyDoc_STRVAR(itertools_compress__doc__, |
| 415 | "compress(data, selectors)\n" |
| 416 | "--\n" |
| 417 | "\n" |
| 418 | "Return data elements corresponding to true selector elements.\n" |
| 419 | "\n" |
| 420 | "Forms a shorter iterator from selected data elements using the selectors to\n" |
| 421 | "choose the data elements."); |
| 422 | |
| 423 | static PyObject * |
| 424 | itertools_compress_impl(PyTypeObject *type, PyObject *seq1, PyObject *seq2); |
| 425 | |
| 426 | static PyObject * |
| 427 | itertools_compress(PyTypeObject *type, PyObject *args, PyObject *kwargs) |
| 428 | { |
| 429 | PyObject *return_value = NULL; |
| 430 | static const char * const _keywords[] = {"data", "selectors", NULL}; |
| 431 | static _PyArg_Parser _parser = {"OO:compress", _keywords, 0}; |
| 432 | PyObject *seq1; |
| 433 | PyObject *seq2; |
| 434 | |
| 435 | if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser, |
| 436 | &seq1, &seq2)) { |
| 437 | goto exit; |
| 438 | } |
| 439 | return_value = itertools_compress_impl(type, seq1, seq2); |
| 440 | |
| 441 | exit: |
| 442 | return return_value; |
| 443 | } |
| 444 | |
| 445 | PyDoc_STRVAR(itertools_filterfalse__doc__, |
| 446 | "filterfalse(function, iterable, /)\n" |
| 447 | "--\n" |
| 448 | "\n" |
| 449 | "Return those items of iterable for which function(item) is false.\n" |
| 450 | "\n" |
| 451 | "If function is None, return the items that are false."); |
| 452 | |
| 453 | static PyObject * |
| 454 | itertools_filterfalse_impl(PyTypeObject *type, PyObject *func, PyObject *seq); |
| 455 | |
| 456 | static PyObject * |
| 457 | itertools_filterfalse(PyTypeObject *type, PyObject *args, PyObject *kwargs) |
| 458 | { |
| 459 | PyObject *return_value = NULL; |
| 460 | PyObject *func; |
| 461 | PyObject *seq; |
| 462 | |
| 463 | if ((type == &filterfalse_type) && |
| 464 | !_PyArg_NoKeywords("filterfalse", kwargs)) { |
| 465 | goto exit; |
| 466 | } |
| 467 | if (!PyArg_UnpackTuple(args, "filterfalse", |
| 468 | 2, 2, |
| 469 | &func, &seq)) { |
| 470 | goto exit; |
| 471 | } |
| 472 | return_value = itertools_filterfalse_impl(type, func, seq); |
| 473 | |
| 474 | exit: |
| 475 | return return_value; |
| 476 | } |
| 477 | |
| 478 | PyDoc_STRVAR(itertools_count__doc__, |
| 479 | "count(start=0, step=1)\n" |
| 480 | "--\n" |
| 481 | "\n" |
| 482 | "Return a count object whose .__next__() method returns consecutive values.\n" |
| 483 | "\n" |
| 484 | "Equivalent to:\n" |
| 485 | " def count(firstval=0, step=1):\n" |
| 486 | " x = firstval\n" |
| 487 | " while 1:\n" |
| 488 | " yield x\n" |
| 489 | " x += step"); |
| 490 | |
| 491 | static PyObject * |
| 492 | itertools_count_impl(PyTypeObject *type, PyObject *long_cnt, |
| 493 | PyObject *long_step); |
| 494 | |
| 495 | static PyObject * |
| 496 | itertools_count(PyTypeObject *type, PyObject *args, PyObject *kwargs) |
| 497 | { |
| 498 | PyObject *return_value = NULL; |
| 499 | static const char * const _keywords[] = {"start", "step", NULL}; |
| 500 | static _PyArg_Parser _parser = {"|OO:count", _keywords, 0}; |
| 501 | PyObject *long_cnt = NULL; |
| 502 | PyObject *long_step = NULL; |
| 503 | |
| 504 | if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser, |
| 505 | &long_cnt, &long_step)) { |
| 506 | goto exit; |
| 507 | } |
| 508 | return_value = itertools_count_impl(type, long_cnt, long_step); |
| 509 | |
| 510 | exit: |
| 511 | return return_value; |
| 512 | } |
Lisa Roach | 9718b59 | 2018-09-23 17:34:59 -0700 | [diff] [blame^] | 513 | /*[clinic end generated code: output=c8c47b766deeffc3 input=a9049054013a1b77]*/ |