Branch data Line data Source code
1 : : /*[clinic input]
2 : : preserve
3 : : [clinic start generated code]*/
4 : :
5 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
6 : : # include "pycore_gc.h" // PyGC_Head
7 : : # include "pycore_runtime.h" // _Py_ID()
8 : : #endif
9 : :
10 : :
11 : : PyDoc_STRVAR(_asyncio_Future___init____doc__,
12 : : "Future(*, loop=None)\n"
13 : : "--\n"
14 : : "\n"
15 : : "This class is *almost* compatible with concurrent.futures.Future.\n"
16 : : "\n"
17 : : " Differences:\n"
18 : : "\n"
19 : : " - result() and exception() do not take a timeout argument and\n"
20 : : " raise an exception when the future isn\'t done yet.\n"
21 : : "\n"
22 : : " - Callbacks registered with add_done_callback() are always called\n"
23 : : " via the event loop\'s call_soon_threadsafe().\n"
24 : : "\n"
25 : : " - This class is not compatible with the wait() and as_completed()\n"
26 : : " methods in the concurrent.futures package.");
27 : :
28 : : static int
29 : : _asyncio_Future___init___impl(FutureObj *self, PyObject *loop);
30 : :
31 : : static int
32 : 0 : _asyncio_Future___init__(PyObject *self, PyObject *args, PyObject *kwargs)
33 : : {
34 : 0 : int return_value = -1;
35 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
36 : :
37 : : #define NUM_KEYWORDS 1
38 : : static struct {
39 : : PyGC_Head _this_is_not_used;
40 : : PyObject_VAR_HEAD
41 : : PyObject *ob_item[NUM_KEYWORDS];
42 : : } _kwtuple = {
43 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
44 : : .ob_item = { &_Py_ID(loop), },
45 : : };
46 : : #undef NUM_KEYWORDS
47 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
48 : :
49 : : #else // !Py_BUILD_CORE
50 : : # define KWTUPLE NULL
51 : : #endif // !Py_BUILD_CORE
52 : :
53 : : static const char * const _keywords[] = {"loop", NULL};
54 : : static _PyArg_Parser _parser = {
55 : : .keywords = _keywords,
56 : : .fname = "Future",
57 : : .kwtuple = KWTUPLE,
58 : : };
59 : : #undef KWTUPLE
60 : : PyObject *argsbuf[1];
61 : : PyObject * const *fastargs;
62 : 0 : Py_ssize_t nargs = PyTuple_GET_SIZE(args);
63 [ # # ]: 0 : Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 0;
64 : 0 : PyObject *loop = Py_None;
65 : :
66 [ # # # # : 0 : fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 0, 0, 0, argsbuf);
# # # # ]
67 [ # # ]: 0 : if (!fastargs) {
68 : 0 : goto exit;
69 : : }
70 [ # # ]: 0 : if (!noptargs) {
71 : 0 : goto skip_optional_kwonly;
72 : : }
73 : 0 : loop = fastargs[0];
74 : 0 : skip_optional_kwonly:
75 : 0 : return_value = _asyncio_Future___init___impl((FutureObj *)self, loop);
76 : :
77 : 0 : exit:
78 : 0 : return return_value;
79 : : }
80 : :
81 : : PyDoc_STRVAR(_asyncio_Future_result__doc__,
82 : : "result($self, /)\n"
83 : : "--\n"
84 : : "\n"
85 : : "Return the result this future represents.\n"
86 : : "\n"
87 : : "If the future has been cancelled, raises CancelledError. If the\n"
88 : : "future\'s result isn\'t yet available, raises InvalidStateError. If\n"
89 : : "the future is done and has an exception set, this exception is raised.");
90 : :
91 : : #define _ASYNCIO_FUTURE_RESULT_METHODDEF \
92 : : {"result", (PyCFunction)_asyncio_Future_result, METH_NOARGS, _asyncio_Future_result__doc__},
93 : :
94 : : static PyObject *
95 : : _asyncio_Future_result_impl(FutureObj *self);
96 : :
97 : : static PyObject *
98 : 0 : _asyncio_Future_result(FutureObj *self, PyObject *Py_UNUSED(ignored))
99 : : {
100 : 0 : return _asyncio_Future_result_impl(self);
101 : : }
102 : :
103 : : PyDoc_STRVAR(_asyncio_Future_exception__doc__,
104 : : "exception($self, /)\n"
105 : : "--\n"
106 : : "\n"
107 : : "Return the exception that was set on this future.\n"
108 : : "\n"
109 : : "The exception (or None if no exception was set) is returned only if\n"
110 : : "the future is done. If the future has been cancelled, raises\n"
111 : : "CancelledError. If the future isn\'t done yet, raises\n"
112 : : "InvalidStateError.");
113 : :
114 : : #define _ASYNCIO_FUTURE_EXCEPTION_METHODDEF \
115 : : {"exception", _PyCFunction_CAST(_asyncio_Future_exception), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _asyncio_Future_exception__doc__},
116 : :
117 : : static PyObject *
118 : : _asyncio_Future_exception_impl(FutureObj *self, PyTypeObject *cls);
119 : :
120 : : static PyObject *
121 : 0 : _asyncio_Future_exception(FutureObj *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
122 : : {
123 [ # # ]: 0 : if (nargs) {
124 : 0 : PyErr_SetString(PyExc_TypeError, "exception() takes no arguments");
125 : 0 : return NULL;
126 : : }
127 : 0 : return _asyncio_Future_exception_impl(self, cls);
128 : : }
129 : :
130 : : PyDoc_STRVAR(_asyncio_Future_set_result__doc__,
131 : : "set_result($self, result, /)\n"
132 : : "--\n"
133 : : "\n"
134 : : "Mark the future done and set its result.\n"
135 : : "\n"
136 : : "If the future is already done when this method is called, raises\n"
137 : : "InvalidStateError.");
138 : :
139 : : #define _ASYNCIO_FUTURE_SET_RESULT_METHODDEF \
140 : : {"set_result", _PyCFunction_CAST(_asyncio_Future_set_result), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _asyncio_Future_set_result__doc__},
141 : :
142 : : static PyObject *
143 : : _asyncio_Future_set_result_impl(FutureObj *self, PyTypeObject *cls,
144 : : PyObject *result);
145 : :
146 : : static PyObject *
147 : 0 : _asyncio_Future_set_result(FutureObj *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
148 : : {
149 : 0 : PyObject *return_value = NULL;
150 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
151 : : # define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty)
152 : : #else
153 : : # define KWTUPLE NULL
154 : : #endif
155 : :
156 : : static const char * const _keywords[] = {"", NULL};
157 : : static _PyArg_Parser _parser = {
158 : : .keywords = _keywords,
159 : : .fname = "set_result",
160 : : .kwtuple = KWTUPLE,
161 : : };
162 : : #undef KWTUPLE
163 : : PyObject *argsbuf[1];
164 : : PyObject *result;
165 : :
166 [ # # # # : 0 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
# # # # ]
167 [ # # ]: 0 : if (!args) {
168 : 0 : goto exit;
169 : : }
170 : 0 : result = args[0];
171 : 0 : return_value = _asyncio_Future_set_result_impl(self, cls, result);
172 : :
173 : 0 : exit:
174 : 0 : return return_value;
175 : : }
176 : :
177 : : PyDoc_STRVAR(_asyncio_Future_set_exception__doc__,
178 : : "set_exception($self, exception, /)\n"
179 : : "--\n"
180 : : "\n"
181 : : "Mark the future done and set an exception.\n"
182 : : "\n"
183 : : "If the future is already done when this method is called, raises\n"
184 : : "InvalidStateError.");
185 : :
186 : : #define _ASYNCIO_FUTURE_SET_EXCEPTION_METHODDEF \
187 : : {"set_exception", _PyCFunction_CAST(_asyncio_Future_set_exception), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _asyncio_Future_set_exception__doc__},
188 : :
189 : : static PyObject *
190 : : _asyncio_Future_set_exception_impl(FutureObj *self, PyTypeObject *cls,
191 : : PyObject *exception);
192 : :
193 : : static PyObject *
194 : 0 : _asyncio_Future_set_exception(FutureObj *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
195 : : {
196 : 0 : PyObject *return_value = NULL;
197 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
198 : : # define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty)
199 : : #else
200 : : # define KWTUPLE NULL
201 : : #endif
202 : :
203 : : static const char * const _keywords[] = {"", NULL};
204 : : static _PyArg_Parser _parser = {
205 : : .keywords = _keywords,
206 : : .fname = "set_exception",
207 : : .kwtuple = KWTUPLE,
208 : : };
209 : : #undef KWTUPLE
210 : : PyObject *argsbuf[1];
211 : : PyObject *exception;
212 : :
213 [ # # # # : 0 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
# # # # ]
214 [ # # ]: 0 : if (!args) {
215 : 0 : goto exit;
216 : : }
217 : 0 : exception = args[0];
218 : 0 : return_value = _asyncio_Future_set_exception_impl(self, cls, exception);
219 : :
220 : 0 : exit:
221 : 0 : return return_value;
222 : : }
223 : :
224 : : PyDoc_STRVAR(_asyncio_Future_add_done_callback__doc__,
225 : : "add_done_callback($self, fn, /, *, context=<unrepresentable>)\n"
226 : : "--\n"
227 : : "\n"
228 : : "Add a callback to be run when the future becomes done.\n"
229 : : "\n"
230 : : "The callback is called with a single argument - the future object. If\n"
231 : : "the future is already done when this is called, the callback is\n"
232 : : "scheduled with call_soon.");
233 : :
234 : : #define _ASYNCIO_FUTURE_ADD_DONE_CALLBACK_METHODDEF \
235 : : {"add_done_callback", _PyCFunction_CAST(_asyncio_Future_add_done_callback), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _asyncio_Future_add_done_callback__doc__},
236 : :
237 : : static PyObject *
238 : : _asyncio_Future_add_done_callback_impl(FutureObj *self, PyTypeObject *cls,
239 : : PyObject *fn, PyObject *context);
240 : :
241 : : static PyObject *
242 : 0 : _asyncio_Future_add_done_callback(FutureObj *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
243 : : {
244 : 0 : PyObject *return_value = NULL;
245 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
246 : :
247 : : #define NUM_KEYWORDS 1
248 : : static struct {
249 : : PyGC_Head _this_is_not_used;
250 : : PyObject_VAR_HEAD
251 : : PyObject *ob_item[NUM_KEYWORDS];
252 : : } _kwtuple = {
253 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
254 : : .ob_item = { &_Py_ID(context), },
255 : : };
256 : : #undef NUM_KEYWORDS
257 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
258 : :
259 : : #else // !Py_BUILD_CORE
260 : : # define KWTUPLE NULL
261 : : #endif // !Py_BUILD_CORE
262 : :
263 : : static const char * const _keywords[] = {"", "context", NULL};
264 : : static _PyArg_Parser _parser = {
265 : : .keywords = _keywords,
266 : : .fname = "add_done_callback",
267 : : .kwtuple = KWTUPLE,
268 : : };
269 : : #undef KWTUPLE
270 : : PyObject *argsbuf[2];
271 [ # # ]: 0 : Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
272 : : PyObject *fn;
273 : 0 : PyObject *context = NULL;
274 : :
275 [ # # # # : 0 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
# # # # ]
276 [ # # ]: 0 : if (!args) {
277 : 0 : goto exit;
278 : : }
279 : 0 : fn = args[0];
280 [ # # ]: 0 : if (!noptargs) {
281 : 0 : goto skip_optional_kwonly;
282 : : }
283 : 0 : context = args[1];
284 : 0 : skip_optional_kwonly:
285 : 0 : return_value = _asyncio_Future_add_done_callback_impl(self, cls, fn, context);
286 : :
287 : 0 : exit:
288 : 0 : return return_value;
289 : : }
290 : :
291 : : PyDoc_STRVAR(_asyncio_Future_remove_done_callback__doc__,
292 : : "remove_done_callback($self, fn, /)\n"
293 : : "--\n"
294 : : "\n"
295 : : "Remove all instances of a callback from the \"call when done\" list.\n"
296 : : "\n"
297 : : "Returns the number of callbacks removed.");
298 : :
299 : : #define _ASYNCIO_FUTURE_REMOVE_DONE_CALLBACK_METHODDEF \
300 : : {"remove_done_callback", _PyCFunction_CAST(_asyncio_Future_remove_done_callback), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _asyncio_Future_remove_done_callback__doc__},
301 : :
302 : : static PyObject *
303 : : _asyncio_Future_remove_done_callback_impl(FutureObj *self, PyTypeObject *cls,
304 : : PyObject *fn);
305 : :
306 : : static PyObject *
307 : 0 : _asyncio_Future_remove_done_callback(FutureObj *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
308 : : {
309 : 0 : PyObject *return_value = NULL;
310 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
311 : : # define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty)
312 : : #else
313 : : # define KWTUPLE NULL
314 : : #endif
315 : :
316 : : static const char * const _keywords[] = {"", NULL};
317 : : static _PyArg_Parser _parser = {
318 : : .keywords = _keywords,
319 : : .fname = "remove_done_callback",
320 : : .kwtuple = KWTUPLE,
321 : : };
322 : : #undef KWTUPLE
323 : : PyObject *argsbuf[1];
324 : : PyObject *fn;
325 : :
326 [ # # # # : 0 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
# # # # ]
327 [ # # ]: 0 : if (!args) {
328 : 0 : goto exit;
329 : : }
330 : 0 : fn = args[0];
331 : 0 : return_value = _asyncio_Future_remove_done_callback_impl(self, cls, fn);
332 : :
333 : 0 : exit:
334 : 0 : return return_value;
335 : : }
336 : :
337 : : PyDoc_STRVAR(_asyncio_Future_cancel__doc__,
338 : : "cancel($self, /, msg=None)\n"
339 : : "--\n"
340 : : "\n"
341 : : "Cancel the future and schedule callbacks.\n"
342 : : "\n"
343 : : "If the future is already done or cancelled, return False. Otherwise,\n"
344 : : "change the future\'s state to cancelled, schedule the callbacks and\n"
345 : : "return True.");
346 : :
347 : : #define _ASYNCIO_FUTURE_CANCEL_METHODDEF \
348 : : {"cancel", _PyCFunction_CAST(_asyncio_Future_cancel), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _asyncio_Future_cancel__doc__},
349 : :
350 : : static PyObject *
351 : : _asyncio_Future_cancel_impl(FutureObj *self, PyTypeObject *cls,
352 : : PyObject *msg);
353 : :
354 : : static PyObject *
355 : 0 : _asyncio_Future_cancel(FutureObj *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
356 : : {
357 : 0 : PyObject *return_value = NULL;
358 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
359 : :
360 : : #define NUM_KEYWORDS 1
361 : : static struct {
362 : : PyGC_Head _this_is_not_used;
363 : : PyObject_VAR_HEAD
364 : : PyObject *ob_item[NUM_KEYWORDS];
365 : : } _kwtuple = {
366 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
367 : : .ob_item = { &_Py_ID(msg), },
368 : : };
369 : : #undef NUM_KEYWORDS
370 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
371 : :
372 : : #else // !Py_BUILD_CORE
373 : : # define KWTUPLE NULL
374 : : #endif // !Py_BUILD_CORE
375 : :
376 : : static const char * const _keywords[] = {"msg", NULL};
377 : : static _PyArg_Parser _parser = {
378 : : .keywords = _keywords,
379 : : .fname = "cancel",
380 : : .kwtuple = KWTUPLE,
381 : : };
382 : : #undef KWTUPLE
383 : : PyObject *argsbuf[1];
384 [ # # ]: 0 : Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
385 : 0 : PyObject *msg = Py_None;
386 : :
387 [ # # # # : 0 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
# # # # ]
388 [ # # ]: 0 : if (!args) {
389 : 0 : goto exit;
390 : : }
391 [ # # ]: 0 : if (!noptargs) {
392 : 0 : goto skip_optional_pos;
393 : : }
394 : 0 : msg = args[0];
395 : 0 : skip_optional_pos:
396 : 0 : return_value = _asyncio_Future_cancel_impl(self, cls, msg);
397 : :
398 : 0 : exit:
399 : 0 : return return_value;
400 : : }
401 : :
402 : : PyDoc_STRVAR(_asyncio_Future_cancelled__doc__,
403 : : "cancelled($self, /)\n"
404 : : "--\n"
405 : : "\n"
406 : : "Return True if the future was cancelled.");
407 : :
408 : : #define _ASYNCIO_FUTURE_CANCELLED_METHODDEF \
409 : : {"cancelled", (PyCFunction)_asyncio_Future_cancelled, METH_NOARGS, _asyncio_Future_cancelled__doc__},
410 : :
411 : : static PyObject *
412 : : _asyncio_Future_cancelled_impl(FutureObj *self);
413 : :
414 : : static PyObject *
415 : 0 : _asyncio_Future_cancelled(FutureObj *self, PyObject *Py_UNUSED(ignored))
416 : : {
417 : 0 : return _asyncio_Future_cancelled_impl(self);
418 : : }
419 : :
420 : : PyDoc_STRVAR(_asyncio_Future_done__doc__,
421 : : "done($self, /)\n"
422 : : "--\n"
423 : : "\n"
424 : : "Return True if the future is done.\n"
425 : : "\n"
426 : : "Done means either that a result / exception are available, or that the\n"
427 : : "future was cancelled.");
428 : :
429 : : #define _ASYNCIO_FUTURE_DONE_METHODDEF \
430 : : {"done", (PyCFunction)_asyncio_Future_done, METH_NOARGS, _asyncio_Future_done__doc__},
431 : :
432 : : static PyObject *
433 : : _asyncio_Future_done_impl(FutureObj *self);
434 : :
435 : : static PyObject *
436 : 0 : _asyncio_Future_done(FutureObj *self, PyObject *Py_UNUSED(ignored))
437 : : {
438 : 0 : return _asyncio_Future_done_impl(self);
439 : : }
440 : :
441 : : PyDoc_STRVAR(_asyncio_Future_get_loop__doc__,
442 : : "get_loop($self, /)\n"
443 : : "--\n"
444 : : "\n"
445 : : "Return the event loop the Future is bound to.");
446 : :
447 : : #define _ASYNCIO_FUTURE_GET_LOOP_METHODDEF \
448 : : {"get_loop", _PyCFunction_CAST(_asyncio_Future_get_loop), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _asyncio_Future_get_loop__doc__},
449 : :
450 : : static PyObject *
451 : : _asyncio_Future_get_loop_impl(FutureObj *self, PyTypeObject *cls);
452 : :
453 : : static PyObject *
454 : 0 : _asyncio_Future_get_loop(FutureObj *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
455 : : {
456 [ # # ]: 0 : if (nargs) {
457 : 0 : PyErr_SetString(PyExc_TypeError, "get_loop() takes no arguments");
458 : 0 : return NULL;
459 : : }
460 : 0 : return _asyncio_Future_get_loop_impl(self, cls);
461 : : }
462 : :
463 : : PyDoc_STRVAR(_asyncio_Future__make_cancelled_error__doc__,
464 : : "_make_cancelled_error($self, /)\n"
465 : : "--\n"
466 : : "\n"
467 : : "Create the CancelledError to raise if the Future is cancelled.\n"
468 : : "\n"
469 : : "This should only be called once when handling a cancellation since\n"
470 : : "it erases the context exception value.");
471 : :
472 : : #define _ASYNCIO_FUTURE__MAKE_CANCELLED_ERROR_METHODDEF \
473 : : {"_make_cancelled_error", (PyCFunction)_asyncio_Future__make_cancelled_error, METH_NOARGS, _asyncio_Future__make_cancelled_error__doc__},
474 : :
475 : : static PyObject *
476 : : _asyncio_Future__make_cancelled_error_impl(FutureObj *self);
477 : :
478 : : static PyObject *
479 : 0 : _asyncio_Future__make_cancelled_error(FutureObj *self, PyObject *Py_UNUSED(ignored))
480 : : {
481 : 0 : return _asyncio_Future__make_cancelled_error_impl(self);
482 : : }
483 : :
484 : : PyDoc_STRVAR(_asyncio_Task___init____doc__,
485 : : "Task(coro, *, loop=None, name=None, context=None)\n"
486 : : "--\n"
487 : : "\n"
488 : : "A coroutine wrapped in a Future.");
489 : :
490 : : static int
491 : : _asyncio_Task___init___impl(TaskObj *self, PyObject *coro, PyObject *loop,
492 : : PyObject *name, PyObject *context);
493 : :
494 : : static int
495 : 0 : _asyncio_Task___init__(PyObject *self, PyObject *args, PyObject *kwargs)
496 : : {
497 : 0 : int return_value = -1;
498 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
499 : :
500 : : #define NUM_KEYWORDS 4
501 : : static struct {
502 : : PyGC_Head _this_is_not_used;
503 : : PyObject_VAR_HEAD
504 : : PyObject *ob_item[NUM_KEYWORDS];
505 : : } _kwtuple = {
506 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
507 : : .ob_item = { &_Py_ID(coro), &_Py_ID(loop), &_Py_ID(name), &_Py_ID(context), },
508 : : };
509 : : #undef NUM_KEYWORDS
510 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
511 : :
512 : : #else // !Py_BUILD_CORE
513 : : # define KWTUPLE NULL
514 : : #endif // !Py_BUILD_CORE
515 : :
516 : : static const char * const _keywords[] = {"coro", "loop", "name", "context", NULL};
517 : : static _PyArg_Parser _parser = {
518 : : .keywords = _keywords,
519 : : .fname = "Task",
520 : : .kwtuple = KWTUPLE,
521 : : };
522 : : #undef KWTUPLE
523 : : PyObject *argsbuf[4];
524 : : PyObject * const *fastargs;
525 : 0 : Py_ssize_t nargs = PyTuple_GET_SIZE(args);
526 [ # # ]: 0 : Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 1;
527 : : PyObject *coro;
528 : 0 : PyObject *loop = Py_None;
529 : 0 : PyObject *name = Py_None;
530 : 0 : PyObject *context = Py_None;
531 : :
532 [ # # # # : 0 : fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 1, 1, 0, argsbuf);
# # # # ]
533 [ # # ]: 0 : if (!fastargs) {
534 : 0 : goto exit;
535 : : }
536 : 0 : coro = fastargs[0];
537 [ # # ]: 0 : if (!noptargs) {
538 : 0 : goto skip_optional_kwonly;
539 : : }
540 [ # # ]: 0 : if (fastargs[1]) {
541 : 0 : loop = fastargs[1];
542 [ # # ]: 0 : if (!--noptargs) {
543 : 0 : goto skip_optional_kwonly;
544 : : }
545 : : }
546 [ # # ]: 0 : if (fastargs[2]) {
547 : 0 : name = fastargs[2];
548 [ # # ]: 0 : if (!--noptargs) {
549 : 0 : goto skip_optional_kwonly;
550 : : }
551 : : }
552 : 0 : context = fastargs[3];
553 : 0 : skip_optional_kwonly:
554 : 0 : return_value = _asyncio_Task___init___impl((TaskObj *)self, coro, loop, name, context);
555 : :
556 : 0 : exit:
557 : 0 : return return_value;
558 : : }
559 : :
560 : : PyDoc_STRVAR(_asyncio_Task__make_cancelled_error__doc__,
561 : : "_make_cancelled_error($self, /)\n"
562 : : "--\n"
563 : : "\n"
564 : : "Create the CancelledError to raise if the Task is cancelled.\n"
565 : : "\n"
566 : : "This should only be called once when handling a cancellation since\n"
567 : : "it erases the context exception value.");
568 : :
569 : : #define _ASYNCIO_TASK__MAKE_CANCELLED_ERROR_METHODDEF \
570 : : {"_make_cancelled_error", (PyCFunction)_asyncio_Task__make_cancelled_error, METH_NOARGS, _asyncio_Task__make_cancelled_error__doc__},
571 : :
572 : : static PyObject *
573 : : _asyncio_Task__make_cancelled_error_impl(TaskObj *self);
574 : :
575 : : static PyObject *
576 : 0 : _asyncio_Task__make_cancelled_error(TaskObj *self, PyObject *Py_UNUSED(ignored))
577 : : {
578 : 0 : return _asyncio_Task__make_cancelled_error_impl(self);
579 : : }
580 : :
581 : : PyDoc_STRVAR(_asyncio_Task_cancel__doc__,
582 : : "cancel($self, /, msg=None)\n"
583 : : "--\n"
584 : : "\n"
585 : : "Request that this task cancel itself.\n"
586 : : "\n"
587 : : "This arranges for a CancelledError to be thrown into the\n"
588 : : "wrapped coroutine on the next cycle through the event loop.\n"
589 : : "The coroutine then has a chance to clean up or even deny\n"
590 : : "the request using try/except/finally.\n"
591 : : "\n"
592 : : "Unlike Future.cancel, this does not guarantee that the\n"
593 : : "task will be cancelled: the exception might be caught and\n"
594 : : "acted upon, delaying cancellation of the task or preventing\n"
595 : : "cancellation completely. The task may also return a value or\n"
596 : : "raise a different exception.\n"
597 : : "\n"
598 : : "Immediately after this method is called, Task.cancelled() will\n"
599 : : "not return True (unless the task was already cancelled). A\n"
600 : : "task will be marked as cancelled when the wrapped coroutine\n"
601 : : "terminates with a CancelledError exception (even if cancel()\n"
602 : : "was not called).\n"
603 : : "\n"
604 : : "This also increases the task\'s count of cancellation requests.");
605 : :
606 : : #define _ASYNCIO_TASK_CANCEL_METHODDEF \
607 : : {"cancel", _PyCFunction_CAST(_asyncio_Task_cancel), METH_FASTCALL|METH_KEYWORDS, _asyncio_Task_cancel__doc__},
608 : :
609 : : static PyObject *
610 : : _asyncio_Task_cancel_impl(TaskObj *self, PyObject *msg);
611 : :
612 : : static PyObject *
613 : 0 : _asyncio_Task_cancel(TaskObj *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
614 : : {
615 : 0 : PyObject *return_value = NULL;
616 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
617 : :
618 : : #define NUM_KEYWORDS 1
619 : : static struct {
620 : : PyGC_Head _this_is_not_used;
621 : : PyObject_VAR_HEAD
622 : : PyObject *ob_item[NUM_KEYWORDS];
623 : : } _kwtuple = {
624 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
625 : : .ob_item = { &_Py_ID(msg), },
626 : : };
627 : : #undef NUM_KEYWORDS
628 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
629 : :
630 : : #else // !Py_BUILD_CORE
631 : : # define KWTUPLE NULL
632 : : #endif // !Py_BUILD_CORE
633 : :
634 : : static const char * const _keywords[] = {"msg", NULL};
635 : : static _PyArg_Parser _parser = {
636 : : .keywords = _keywords,
637 : : .fname = "cancel",
638 : : .kwtuple = KWTUPLE,
639 : : };
640 : : #undef KWTUPLE
641 : : PyObject *argsbuf[1];
642 [ # # ]: 0 : Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
643 : 0 : PyObject *msg = Py_None;
644 : :
645 [ # # # # : 0 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
# # # # ]
646 [ # # ]: 0 : if (!args) {
647 : 0 : goto exit;
648 : : }
649 [ # # ]: 0 : if (!noptargs) {
650 : 0 : goto skip_optional_pos;
651 : : }
652 : 0 : msg = args[0];
653 : 0 : skip_optional_pos:
654 : 0 : return_value = _asyncio_Task_cancel_impl(self, msg);
655 : :
656 : 0 : exit:
657 : 0 : return return_value;
658 : : }
659 : :
660 : : PyDoc_STRVAR(_asyncio_Task_cancelling__doc__,
661 : : "cancelling($self, /)\n"
662 : : "--\n"
663 : : "\n"
664 : : "Return the count of the task\'s cancellation requests.\n"
665 : : "\n"
666 : : "This count is incremented when .cancel() is called\n"
667 : : "and may be decremented using .uncancel().");
668 : :
669 : : #define _ASYNCIO_TASK_CANCELLING_METHODDEF \
670 : : {"cancelling", (PyCFunction)_asyncio_Task_cancelling, METH_NOARGS, _asyncio_Task_cancelling__doc__},
671 : :
672 : : static PyObject *
673 : : _asyncio_Task_cancelling_impl(TaskObj *self);
674 : :
675 : : static PyObject *
676 : 0 : _asyncio_Task_cancelling(TaskObj *self, PyObject *Py_UNUSED(ignored))
677 : : {
678 : 0 : return _asyncio_Task_cancelling_impl(self);
679 : : }
680 : :
681 : : PyDoc_STRVAR(_asyncio_Task_uncancel__doc__,
682 : : "uncancel($self, /)\n"
683 : : "--\n"
684 : : "\n"
685 : : "Decrement the task\'s count of cancellation requests.\n"
686 : : "\n"
687 : : "This should be used by tasks that catch CancelledError\n"
688 : : "and wish to continue indefinitely until they are cancelled again.\n"
689 : : "\n"
690 : : "Returns the remaining number of cancellation requests.");
691 : :
692 : : #define _ASYNCIO_TASK_UNCANCEL_METHODDEF \
693 : : {"uncancel", (PyCFunction)_asyncio_Task_uncancel, METH_NOARGS, _asyncio_Task_uncancel__doc__},
694 : :
695 : : static PyObject *
696 : : _asyncio_Task_uncancel_impl(TaskObj *self);
697 : :
698 : : static PyObject *
699 : 0 : _asyncio_Task_uncancel(TaskObj *self, PyObject *Py_UNUSED(ignored))
700 : : {
701 : 0 : return _asyncio_Task_uncancel_impl(self);
702 : : }
703 : :
704 : : PyDoc_STRVAR(_asyncio_Task_get_stack__doc__,
705 : : "get_stack($self, /, *, limit=None)\n"
706 : : "--\n"
707 : : "\n"
708 : : "Return the list of stack frames for this task\'s coroutine.\n"
709 : : "\n"
710 : : "If the coroutine is not done, this returns the stack where it is\n"
711 : : "suspended. If the coroutine has completed successfully or was\n"
712 : : "cancelled, this returns an empty list. If the coroutine was\n"
713 : : "terminated by an exception, this returns the list of traceback\n"
714 : : "frames.\n"
715 : : "\n"
716 : : "The frames are always ordered from oldest to newest.\n"
717 : : "\n"
718 : : "The optional limit gives the maximum number of frames to\n"
719 : : "return; by default all available frames are returned. Its\n"
720 : : "meaning differs depending on whether a stack or a traceback is\n"
721 : : "returned: the newest frames of a stack are returned, but the\n"
722 : : "oldest frames of a traceback are returned. (This matches the\n"
723 : : "behavior of the traceback module.)\n"
724 : : "\n"
725 : : "For reasons beyond our control, only one stack frame is\n"
726 : : "returned for a suspended coroutine.");
727 : :
728 : : #define _ASYNCIO_TASK_GET_STACK_METHODDEF \
729 : : {"get_stack", _PyCFunction_CAST(_asyncio_Task_get_stack), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _asyncio_Task_get_stack__doc__},
730 : :
731 : : static PyObject *
732 : : _asyncio_Task_get_stack_impl(TaskObj *self, PyTypeObject *cls,
733 : : PyObject *limit);
734 : :
735 : : static PyObject *
736 : 0 : _asyncio_Task_get_stack(TaskObj *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
737 : : {
738 : 0 : PyObject *return_value = NULL;
739 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
740 : :
741 : : #define NUM_KEYWORDS 1
742 : : static struct {
743 : : PyGC_Head _this_is_not_used;
744 : : PyObject_VAR_HEAD
745 : : PyObject *ob_item[NUM_KEYWORDS];
746 : : } _kwtuple = {
747 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
748 : : .ob_item = { &_Py_ID(limit), },
749 : : };
750 : : #undef NUM_KEYWORDS
751 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
752 : :
753 : : #else // !Py_BUILD_CORE
754 : : # define KWTUPLE NULL
755 : : #endif // !Py_BUILD_CORE
756 : :
757 : : static const char * const _keywords[] = {"limit", NULL};
758 : : static _PyArg_Parser _parser = {
759 : : .keywords = _keywords,
760 : : .fname = "get_stack",
761 : : .kwtuple = KWTUPLE,
762 : : };
763 : : #undef KWTUPLE
764 : : PyObject *argsbuf[1];
765 [ # # ]: 0 : Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
766 : 0 : PyObject *limit = Py_None;
767 : :
768 [ # # # # : 0 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf);
# # # # ]
769 [ # # ]: 0 : if (!args) {
770 : 0 : goto exit;
771 : : }
772 [ # # ]: 0 : if (!noptargs) {
773 : 0 : goto skip_optional_kwonly;
774 : : }
775 : 0 : limit = args[0];
776 : 0 : skip_optional_kwonly:
777 : 0 : return_value = _asyncio_Task_get_stack_impl(self, cls, limit);
778 : :
779 : 0 : exit:
780 : 0 : return return_value;
781 : : }
782 : :
783 : : PyDoc_STRVAR(_asyncio_Task_print_stack__doc__,
784 : : "print_stack($self, /, *, limit=None, file=None)\n"
785 : : "--\n"
786 : : "\n"
787 : : "Print the stack or traceback for this task\'s coroutine.\n"
788 : : "\n"
789 : : "This produces output similar to that of the traceback module,\n"
790 : : "for the frames retrieved by get_stack(). The limit argument\n"
791 : : "is passed to get_stack(). The file argument is an I/O stream\n"
792 : : "to which the output is written; by default output is written\n"
793 : : "to sys.stderr.");
794 : :
795 : : #define _ASYNCIO_TASK_PRINT_STACK_METHODDEF \
796 : : {"print_stack", _PyCFunction_CAST(_asyncio_Task_print_stack), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _asyncio_Task_print_stack__doc__},
797 : :
798 : : static PyObject *
799 : : _asyncio_Task_print_stack_impl(TaskObj *self, PyTypeObject *cls,
800 : : PyObject *limit, PyObject *file);
801 : :
802 : : static PyObject *
803 : 0 : _asyncio_Task_print_stack(TaskObj *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
804 : : {
805 : 0 : PyObject *return_value = NULL;
806 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
807 : :
808 : : #define NUM_KEYWORDS 2
809 : : static struct {
810 : : PyGC_Head _this_is_not_used;
811 : : PyObject_VAR_HEAD
812 : : PyObject *ob_item[NUM_KEYWORDS];
813 : : } _kwtuple = {
814 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
815 : : .ob_item = { &_Py_ID(limit), &_Py_ID(file), },
816 : : };
817 : : #undef NUM_KEYWORDS
818 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
819 : :
820 : : #else // !Py_BUILD_CORE
821 : : # define KWTUPLE NULL
822 : : #endif // !Py_BUILD_CORE
823 : :
824 : : static const char * const _keywords[] = {"limit", "file", NULL};
825 : : static _PyArg_Parser _parser = {
826 : : .keywords = _keywords,
827 : : .fname = "print_stack",
828 : : .kwtuple = KWTUPLE,
829 : : };
830 : : #undef KWTUPLE
831 : : PyObject *argsbuf[2];
832 [ # # ]: 0 : Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
833 : 0 : PyObject *limit = Py_None;
834 : 0 : PyObject *file = Py_None;
835 : :
836 [ # # # # : 0 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf);
# # # # ]
837 [ # # ]: 0 : if (!args) {
838 : 0 : goto exit;
839 : : }
840 [ # # ]: 0 : if (!noptargs) {
841 : 0 : goto skip_optional_kwonly;
842 : : }
843 [ # # ]: 0 : if (args[0]) {
844 : 0 : limit = args[0];
845 [ # # ]: 0 : if (!--noptargs) {
846 : 0 : goto skip_optional_kwonly;
847 : : }
848 : : }
849 : 0 : file = args[1];
850 : 0 : skip_optional_kwonly:
851 : 0 : return_value = _asyncio_Task_print_stack_impl(self, cls, limit, file);
852 : :
853 : 0 : exit:
854 : 0 : return return_value;
855 : : }
856 : :
857 : : PyDoc_STRVAR(_asyncio_Task_set_result__doc__,
858 : : "set_result($self, result, /)\n"
859 : : "--\n"
860 : : "\n");
861 : :
862 : : #define _ASYNCIO_TASK_SET_RESULT_METHODDEF \
863 : : {"set_result", (PyCFunction)_asyncio_Task_set_result, METH_O, _asyncio_Task_set_result__doc__},
864 : :
865 : : PyDoc_STRVAR(_asyncio_Task_set_exception__doc__,
866 : : "set_exception($self, exception, /)\n"
867 : : "--\n"
868 : : "\n");
869 : :
870 : : #define _ASYNCIO_TASK_SET_EXCEPTION_METHODDEF \
871 : : {"set_exception", (PyCFunction)_asyncio_Task_set_exception, METH_O, _asyncio_Task_set_exception__doc__},
872 : :
873 : : PyDoc_STRVAR(_asyncio_Task_get_coro__doc__,
874 : : "get_coro($self, /)\n"
875 : : "--\n"
876 : : "\n");
877 : :
878 : : #define _ASYNCIO_TASK_GET_CORO_METHODDEF \
879 : : {"get_coro", (PyCFunction)_asyncio_Task_get_coro, METH_NOARGS, _asyncio_Task_get_coro__doc__},
880 : :
881 : : static PyObject *
882 : : _asyncio_Task_get_coro_impl(TaskObj *self);
883 : :
884 : : static PyObject *
885 : 0 : _asyncio_Task_get_coro(TaskObj *self, PyObject *Py_UNUSED(ignored))
886 : : {
887 : 0 : return _asyncio_Task_get_coro_impl(self);
888 : : }
889 : :
890 : : PyDoc_STRVAR(_asyncio_Task_get_context__doc__,
891 : : "get_context($self, /)\n"
892 : : "--\n"
893 : : "\n");
894 : :
895 : : #define _ASYNCIO_TASK_GET_CONTEXT_METHODDEF \
896 : : {"get_context", (PyCFunction)_asyncio_Task_get_context, METH_NOARGS, _asyncio_Task_get_context__doc__},
897 : :
898 : : static PyObject *
899 : : _asyncio_Task_get_context_impl(TaskObj *self);
900 : :
901 : : static PyObject *
902 : 0 : _asyncio_Task_get_context(TaskObj *self, PyObject *Py_UNUSED(ignored))
903 : : {
904 : 0 : return _asyncio_Task_get_context_impl(self);
905 : : }
906 : :
907 : : PyDoc_STRVAR(_asyncio_Task_get_name__doc__,
908 : : "get_name($self, /)\n"
909 : : "--\n"
910 : : "\n");
911 : :
912 : : #define _ASYNCIO_TASK_GET_NAME_METHODDEF \
913 : : {"get_name", (PyCFunction)_asyncio_Task_get_name, METH_NOARGS, _asyncio_Task_get_name__doc__},
914 : :
915 : : static PyObject *
916 : : _asyncio_Task_get_name_impl(TaskObj *self);
917 : :
918 : : static PyObject *
919 : 0 : _asyncio_Task_get_name(TaskObj *self, PyObject *Py_UNUSED(ignored))
920 : : {
921 : 0 : return _asyncio_Task_get_name_impl(self);
922 : : }
923 : :
924 : : PyDoc_STRVAR(_asyncio_Task_set_name__doc__,
925 : : "set_name($self, value, /)\n"
926 : : "--\n"
927 : : "\n");
928 : :
929 : : #define _ASYNCIO_TASK_SET_NAME_METHODDEF \
930 : : {"set_name", (PyCFunction)_asyncio_Task_set_name, METH_O, _asyncio_Task_set_name__doc__},
931 : :
932 : : PyDoc_STRVAR(_asyncio__get_running_loop__doc__,
933 : : "_get_running_loop($module, /)\n"
934 : : "--\n"
935 : : "\n"
936 : : "Return the running event loop or None.\n"
937 : : "\n"
938 : : "This is a low-level function intended to be used by event loops.\n"
939 : : "This function is thread-specific.");
940 : :
941 : : #define _ASYNCIO__GET_RUNNING_LOOP_METHODDEF \
942 : : {"_get_running_loop", (PyCFunction)_asyncio__get_running_loop, METH_NOARGS, _asyncio__get_running_loop__doc__},
943 : :
944 : : static PyObject *
945 : : _asyncio__get_running_loop_impl(PyObject *module);
946 : :
947 : : static PyObject *
948 : 0 : _asyncio__get_running_loop(PyObject *module, PyObject *Py_UNUSED(ignored))
949 : : {
950 : 0 : return _asyncio__get_running_loop_impl(module);
951 : : }
952 : :
953 : : PyDoc_STRVAR(_asyncio__set_running_loop__doc__,
954 : : "_set_running_loop($module, loop, /)\n"
955 : : "--\n"
956 : : "\n"
957 : : "Set the running event loop.\n"
958 : : "\n"
959 : : "This is a low-level function intended to be used by event loops.\n"
960 : : "This function is thread-specific.");
961 : :
962 : : #define _ASYNCIO__SET_RUNNING_LOOP_METHODDEF \
963 : : {"_set_running_loop", (PyCFunction)_asyncio__set_running_loop, METH_O, _asyncio__set_running_loop__doc__},
964 : :
965 : : PyDoc_STRVAR(_asyncio_get_event_loop__doc__,
966 : : "get_event_loop($module, /)\n"
967 : : "--\n"
968 : : "\n"
969 : : "Return an asyncio event loop.\n"
970 : : "\n"
971 : : "When called from a coroutine or a callback (e.g. scheduled with\n"
972 : : "call_soon or similar API), this function will always return the\n"
973 : : "running event loop.\n"
974 : : "\n"
975 : : "If there is no running event loop set, the function will return\n"
976 : : "the result of `get_event_loop_policy().get_event_loop()` call.");
977 : :
978 : : #define _ASYNCIO_GET_EVENT_LOOP_METHODDEF \
979 : : {"get_event_loop", (PyCFunction)_asyncio_get_event_loop, METH_NOARGS, _asyncio_get_event_loop__doc__},
980 : :
981 : : static PyObject *
982 : : _asyncio_get_event_loop_impl(PyObject *module);
983 : :
984 : : static PyObject *
985 : 0 : _asyncio_get_event_loop(PyObject *module, PyObject *Py_UNUSED(ignored))
986 : : {
987 : 0 : return _asyncio_get_event_loop_impl(module);
988 : : }
989 : :
990 : : PyDoc_STRVAR(_asyncio_get_running_loop__doc__,
991 : : "get_running_loop($module, /)\n"
992 : : "--\n"
993 : : "\n"
994 : : "Return the running event loop. Raise a RuntimeError if there is none.\n"
995 : : "\n"
996 : : "This function is thread-specific.");
997 : :
998 : : #define _ASYNCIO_GET_RUNNING_LOOP_METHODDEF \
999 : : {"get_running_loop", (PyCFunction)_asyncio_get_running_loop, METH_NOARGS, _asyncio_get_running_loop__doc__},
1000 : :
1001 : : static PyObject *
1002 : : _asyncio_get_running_loop_impl(PyObject *module);
1003 : :
1004 : : static PyObject *
1005 : 0 : _asyncio_get_running_loop(PyObject *module, PyObject *Py_UNUSED(ignored))
1006 : : {
1007 : 0 : return _asyncio_get_running_loop_impl(module);
1008 : : }
1009 : :
1010 : : PyDoc_STRVAR(_asyncio__register_task__doc__,
1011 : : "_register_task($module, /, task)\n"
1012 : : "--\n"
1013 : : "\n"
1014 : : "Register a new task in asyncio as executed by loop.\n"
1015 : : "\n"
1016 : : "Returns None.");
1017 : :
1018 : : #define _ASYNCIO__REGISTER_TASK_METHODDEF \
1019 : : {"_register_task", _PyCFunction_CAST(_asyncio__register_task), METH_FASTCALL|METH_KEYWORDS, _asyncio__register_task__doc__},
1020 : :
1021 : : static PyObject *
1022 : : _asyncio__register_task_impl(PyObject *module, PyObject *task);
1023 : :
1024 : : static PyObject *
1025 : 0 : _asyncio__register_task(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1026 : : {
1027 : 0 : PyObject *return_value = NULL;
1028 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1029 : :
1030 : : #define NUM_KEYWORDS 1
1031 : : static struct {
1032 : : PyGC_Head _this_is_not_used;
1033 : : PyObject_VAR_HEAD
1034 : : PyObject *ob_item[NUM_KEYWORDS];
1035 : : } _kwtuple = {
1036 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1037 : : .ob_item = { &_Py_ID(task), },
1038 : : };
1039 : : #undef NUM_KEYWORDS
1040 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1041 : :
1042 : : #else // !Py_BUILD_CORE
1043 : : # define KWTUPLE NULL
1044 : : #endif // !Py_BUILD_CORE
1045 : :
1046 : : static const char * const _keywords[] = {"task", NULL};
1047 : : static _PyArg_Parser _parser = {
1048 : : .keywords = _keywords,
1049 : : .fname = "_register_task",
1050 : : .kwtuple = KWTUPLE,
1051 : : };
1052 : : #undef KWTUPLE
1053 : : PyObject *argsbuf[1];
1054 : : PyObject *task;
1055 : :
1056 [ # # # # : 0 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
# # # # ]
1057 [ # # ]: 0 : if (!args) {
1058 : 0 : goto exit;
1059 : : }
1060 : 0 : task = args[0];
1061 : 0 : return_value = _asyncio__register_task_impl(module, task);
1062 : :
1063 : 0 : exit:
1064 : 0 : return return_value;
1065 : : }
1066 : :
1067 : : PyDoc_STRVAR(_asyncio__unregister_task__doc__,
1068 : : "_unregister_task($module, /, task)\n"
1069 : : "--\n"
1070 : : "\n"
1071 : : "Unregister a task.\n"
1072 : : "\n"
1073 : : "Returns None.");
1074 : :
1075 : : #define _ASYNCIO__UNREGISTER_TASK_METHODDEF \
1076 : : {"_unregister_task", _PyCFunction_CAST(_asyncio__unregister_task), METH_FASTCALL|METH_KEYWORDS, _asyncio__unregister_task__doc__},
1077 : :
1078 : : static PyObject *
1079 : : _asyncio__unregister_task_impl(PyObject *module, PyObject *task);
1080 : :
1081 : : static PyObject *
1082 : 0 : _asyncio__unregister_task(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1083 : : {
1084 : 0 : PyObject *return_value = NULL;
1085 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1086 : :
1087 : : #define NUM_KEYWORDS 1
1088 : : static struct {
1089 : : PyGC_Head _this_is_not_used;
1090 : : PyObject_VAR_HEAD
1091 : : PyObject *ob_item[NUM_KEYWORDS];
1092 : : } _kwtuple = {
1093 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1094 : : .ob_item = { &_Py_ID(task), },
1095 : : };
1096 : : #undef NUM_KEYWORDS
1097 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1098 : :
1099 : : #else // !Py_BUILD_CORE
1100 : : # define KWTUPLE NULL
1101 : : #endif // !Py_BUILD_CORE
1102 : :
1103 : : static const char * const _keywords[] = {"task", NULL};
1104 : : static _PyArg_Parser _parser = {
1105 : : .keywords = _keywords,
1106 : : .fname = "_unregister_task",
1107 : : .kwtuple = KWTUPLE,
1108 : : };
1109 : : #undef KWTUPLE
1110 : : PyObject *argsbuf[1];
1111 : : PyObject *task;
1112 : :
1113 [ # # # # : 0 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
# # # # ]
1114 [ # # ]: 0 : if (!args) {
1115 : 0 : goto exit;
1116 : : }
1117 : 0 : task = args[0];
1118 : 0 : return_value = _asyncio__unregister_task_impl(module, task);
1119 : :
1120 : 0 : exit:
1121 : 0 : return return_value;
1122 : : }
1123 : :
1124 : : PyDoc_STRVAR(_asyncio__enter_task__doc__,
1125 : : "_enter_task($module, /, loop, task)\n"
1126 : : "--\n"
1127 : : "\n"
1128 : : "Enter into task execution or resume suspended task.\n"
1129 : : "\n"
1130 : : "Task belongs to loop.\n"
1131 : : "\n"
1132 : : "Returns None.");
1133 : :
1134 : : #define _ASYNCIO__ENTER_TASK_METHODDEF \
1135 : : {"_enter_task", _PyCFunction_CAST(_asyncio__enter_task), METH_FASTCALL|METH_KEYWORDS, _asyncio__enter_task__doc__},
1136 : :
1137 : : static PyObject *
1138 : : _asyncio__enter_task_impl(PyObject *module, PyObject *loop, PyObject *task);
1139 : :
1140 : : static PyObject *
1141 : 0 : _asyncio__enter_task(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1142 : : {
1143 : 0 : PyObject *return_value = NULL;
1144 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1145 : :
1146 : : #define NUM_KEYWORDS 2
1147 : : static struct {
1148 : : PyGC_Head _this_is_not_used;
1149 : : PyObject_VAR_HEAD
1150 : : PyObject *ob_item[NUM_KEYWORDS];
1151 : : } _kwtuple = {
1152 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1153 : : .ob_item = { &_Py_ID(loop), &_Py_ID(task), },
1154 : : };
1155 : : #undef NUM_KEYWORDS
1156 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1157 : :
1158 : : #else // !Py_BUILD_CORE
1159 : : # define KWTUPLE NULL
1160 : : #endif // !Py_BUILD_CORE
1161 : :
1162 : : static const char * const _keywords[] = {"loop", "task", NULL};
1163 : : static _PyArg_Parser _parser = {
1164 : : .keywords = _keywords,
1165 : : .fname = "_enter_task",
1166 : : .kwtuple = KWTUPLE,
1167 : : };
1168 : : #undef KWTUPLE
1169 : : PyObject *argsbuf[2];
1170 : : PyObject *loop;
1171 : : PyObject *task;
1172 : :
1173 [ # # # # : 0 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
# # # # ]
1174 [ # # ]: 0 : if (!args) {
1175 : 0 : goto exit;
1176 : : }
1177 : 0 : loop = args[0];
1178 : 0 : task = args[1];
1179 : 0 : return_value = _asyncio__enter_task_impl(module, loop, task);
1180 : :
1181 : 0 : exit:
1182 : 0 : return return_value;
1183 : : }
1184 : :
1185 : : PyDoc_STRVAR(_asyncio__leave_task__doc__,
1186 : : "_leave_task($module, /, loop, task)\n"
1187 : : "--\n"
1188 : : "\n"
1189 : : "Leave task execution or suspend a task.\n"
1190 : : "\n"
1191 : : "Task belongs to loop.\n"
1192 : : "\n"
1193 : : "Returns None.");
1194 : :
1195 : : #define _ASYNCIO__LEAVE_TASK_METHODDEF \
1196 : : {"_leave_task", _PyCFunction_CAST(_asyncio__leave_task), METH_FASTCALL|METH_KEYWORDS, _asyncio__leave_task__doc__},
1197 : :
1198 : : static PyObject *
1199 : : _asyncio__leave_task_impl(PyObject *module, PyObject *loop, PyObject *task);
1200 : :
1201 : : static PyObject *
1202 : 0 : _asyncio__leave_task(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1203 : : {
1204 : 0 : PyObject *return_value = NULL;
1205 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1206 : :
1207 : : #define NUM_KEYWORDS 2
1208 : : static struct {
1209 : : PyGC_Head _this_is_not_used;
1210 : : PyObject_VAR_HEAD
1211 : : PyObject *ob_item[NUM_KEYWORDS];
1212 : : } _kwtuple = {
1213 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1214 : : .ob_item = { &_Py_ID(loop), &_Py_ID(task), },
1215 : : };
1216 : : #undef NUM_KEYWORDS
1217 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1218 : :
1219 : : #else // !Py_BUILD_CORE
1220 : : # define KWTUPLE NULL
1221 : : #endif // !Py_BUILD_CORE
1222 : :
1223 : : static const char * const _keywords[] = {"loop", "task", NULL};
1224 : : static _PyArg_Parser _parser = {
1225 : : .keywords = _keywords,
1226 : : .fname = "_leave_task",
1227 : : .kwtuple = KWTUPLE,
1228 : : };
1229 : : #undef KWTUPLE
1230 : : PyObject *argsbuf[2];
1231 : : PyObject *loop;
1232 : : PyObject *task;
1233 : :
1234 [ # # # # : 0 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
# # # # ]
1235 [ # # ]: 0 : if (!args) {
1236 : 0 : goto exit;
1237 : : }
1238 : 0 : loop = args[0];
1239 : 0 : task = args[1];
1240 : 0 : return_value = _asyncio__leave_task_impl(module, loop, task);
1241 : :
1242 : 0 : exit:
1243 : 0 : return return_value;
1244 : : }
1245 : :
1246 : : PyDoc_STRVAR(_asyncio_current_task__doc__,
1247 : : "current_task($module, /, loop=None)\n"
1248 : : "--\n"
1249 : : "\n"
1250 : : "Return a currently executed task.");
1251 : :
1252 : : #define _ASYNCIO_CURRENT_TASK_METHODDEF \
1253 : : {"current_task", _PyCFunction_CAST(_asyncio_current_task), METH_FASTCALL|METH_KEYWORDS, _asyncio_current_task__doc__},
1254 : :
1255 : : static PyObject *
1256 : : _asyncio_current_task_impl(PyObject *module, PyObject *loop);
1257 : :
1258 : : static PyObject *
1259 : 0 : _asyncio_current_task(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1260 : : {
1261 : 0 : PyObject *return_value = NULL;
1262 : : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1263 : :
1264 : : #define NUM_KEYWORDS 1
1265 : : static struct {
1266 : : PyGC_Head _this_is_not_used;
1267 : : PyObject_VAR_HEAD
1268 : : PyObject *ob_item[NUM_KEYWORDS];
1269 : : } _kwtuple = {
1270 : : .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1271 : : .ob_item = { &_Py_ID(loop), },
1272 : : };
1273 : : #undef NUM_KEYWORDS
1274 : : #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1275 : :
1276 : : #else // !Py_BUILD_CORE
1277 : : # define KWTUPLE NULL
1278 : : #endif // !Py_BUILD_CORE
1279 : :
1280 : : static const char * const _keywords[] = {"loop", NULL};
1281 : : static _PyArg_Parser _parser = {
1282 : : .keywords = _keywords,
1283 : : .fname = "current_task",
1284 : : .kwtuple = KWTUPLE,
1285 : : };
1286 : : #undef KWTUPLE
1287 : : PyObject *argsbuf[1];
1288 [ # # ]: 0 : Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
1289 : 0 : PyObject *loop = Py_None;
1290 : :
1291 [ # # # # : 0 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
# # # # ]
1292 [ # # ]: 0 : if (!args) {
1293 : 0 : goto exit;
1294 : : }
1295 [ # # ]: 0 : if (!noptargs) {
1296 : 0 : goto skip_optional_pos;
1297 : : }
1298 : 0 : loop = args[0];
1299 : 0 : skip_optional_pos:
1300 : 0 : return_value = _asyncio_current_task_impl(module, loop);
1301 : :
1302 : 0 : exit:
1303 : 0 : return return_value;
1304 : : }
1305 : : /*[clinic end generated code: output=00f494214f2fd008 input=a9049054013a1b77]*/
|