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