| 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 |
#include "pycore_modsupport.h" // _PyArg_UnpackKeywords() |
| 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 |
_asyncio_Future___init__(PyObject *self, PyObject *args, PyObject *kwargs) |
| 33 |
{ |
| 34 |
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 |
Py_ssize_t nargs = PyTuple_GET_SIZE(args); |
| 63 |
Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 0; |
| 64 |
PyObject *loop = Py_None; |
| 65 |
|
| 66 |
fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 0, 0, 0, argsbuf); |
| 67 |
if (!fastargs) { |
| 68 |
goto exit; |
| 69 |
} |
| 70 |
if (!noptargs) { |
| 71 |
goto skip_optional_kwonly; |
| 72 |
} |
| 73 |
loop = fastargs[0]; |
| 74 |
skip_optional_kwonly: |
| 75 |
return_value = _asyncio_Future___init___impl((FutureObj *)self, loop); |
| 76 |
|
| 77 |
exit: |
| 78 |
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 |
_asyncio_Future_result(FutureObj *self, PyObject *Py_UNUSED(ignored)) |
| 99 |
{ |
| 100 |
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 |
_asyncio_Future_exception(FutureObj *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
| 122 |
{ |
| 123 |
if (nargs || (kwnames && PyTuple_GET_SIZE(kwnames))) { |
| 124 |
PyErr_SetString(PyExc_TypeError, "exception() takes no arguments"); |
| 125 |
return NULL; |
| 126 |
} |
| 127 |
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 |
_asyncio_Future_set_result(FutureObj *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
| 148 |
{ |
| 149 |
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 |
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); |
| 167 |
if (!args) { |
| 168 |
goto exit; |
| 169 |
} |
| 170 |
result = args[0]; |
| 171 |
return_value = _asyncio_Future_set_result_impl(self, cls, result); |
| 172 |
|
| 173 |
exit: |
| 174 |
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 |
_asyncio_Future_set_exception(FutureObj *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
| 195 |
{ |
| 196 |
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 |
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); |
| 214 |
if (!args) { |
| 215 |
goto exit; |
| 216 |
} |
| 217 |
exception = args[0]; |
| 218 |
return_value = _asyncio_Future_set_exception_impl(self, cls, exception); |
| 219 |
|
| 220 |
exit: |
| 221 |
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 |
_asyncio_Future_add_done_callback(FutureObj *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
| 243 |
{ |
| 244 |
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 |
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
| 272 |
PyObject *fn; |
| 273 |
PyObject *context = NULL; |
| 274 |
|
| 275 |
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); |
| 276 |
if (!args) { |
| 277 |
goto exit; |
| 278 |
} |
| 279 |
fn = args[0]; |
| 280 |
if (!noptargs) { |
| 281 |
goto skip_optional_kwonly; |
| 282 |
} |
| 283 |
context = args[1]; |
| 284 |
skip_optional_kwonly: |
| 285 |
return_value = _asyncio_Future_add_done_callback_impl(self, cls, fn, context); |
| 286 |
|
| 287 |
exit: |
| 288 |
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 |
_asyncio_Future_remove_done_callback(FutureObj *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
| 308 |
{ |
| 309 |
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 |
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); |
| 327 |
if (!args) { |
| 328 |
goto exit; |
| 329 |
} |
| 330 |
fn = args[0]; |
| 331 |
return_value = _asyncio_Future_remove_done_callback_impl(self, cls, fn); |
| 332 |
|
| 333 |
exit: |
| 334 |
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 |
_asyncio_Future_cancel(FutureObj *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
| 356 |
{ |
| 357 |
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 |
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; |
| 385 |
PyObject *msg = Py_None; |
| 386 |
|
| 387 |
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf); |
| 388 |
if (!args) { |
| 389 |
goto exit; |
| 390 |
} |
| 391 |
if (!noptargs) { |
| 392 |
goto skip_optional_pos; |
| 393 |
} |
| 394 |
msg = args[0]; |
| 395 |
skip_optional_pos: |
| 396 |
return_value = _asyncio_Future_cancel_impl(self, cls, msg); |
| 397 |
|
| 398 |
exit: |
| 399 |
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 |
_asyncio_Future_cancelled(FutureObj *self, PyObject *Py_UNUSED(ignored)) |
| 416 |
{ |
| 417 |
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 |
_asyncio_Future_done(FutureObj *self, PyObject *Py_UNUSED(ignored)) |
| 437 |
{ |
| 438 |
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 |
_asyncio_Future_get_loop(FutureObj *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
| 455 |
{ |
| 456 |
if (nargs || (kwnames && PyTuple_GET_SIZE(kwnames))) { |
| 457 |
PyErr_SetString(PyExc_TypeError, "get_loop() takes no arguments"); |
| 458 |
return NULL; |
| 459 |
} |
| 460 |
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 |
_asyncio_Future__make_cancelled_error(FutureObj *self, PyObject *Py_UNUSED(ignored)) |
| 480 |
{ |
| 481 |
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, eager_start=False)\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 |
int eager_start); |
| 494 |
|
| 495 |
static int |
| 496 |
_asyncio_Task___init__(PyObject *self, PyObject *args, PyObject *kwargs) |
| 497 |
{ |
| 498 |
int return_value = -1; |
| 499 |
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
| 500 |
|
| 501 |
#define NUM_KEYWORDS 5 |
| 502 |
static struct { |
| 503 |
PyGC_Head _this_is_not_used; |
| 504 |
PyObject_VAR_HEAD |
| 505 |
PyObject *ob_item[NUM_KEYWORDS]; |
| 506 |
} _kwtuple = { |
| 507 |
.ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
| 508 |
.ob_item = { &_Py_ID(coro), &_Py_ID(loop), &_Py_ID(name), &_Py_ID(context), &_Py_ID(eager_start), }, |
| 509 |
}; |
| 510 |
#undef NUM_KEYWORDS |
| 511 |
#define KWTUPLE (&_kwtuple.ob_base.ob_base) |
| 512 |
|
| 513 |
#else // !Py_BUILD_CORE |
| 514 |
# define KWTUPLE NULL |
| 515 |
#endif // !Py_BUILD_CORE |
| 516 |
|
| 517 |
static const char * const _keywords[] = {"coro", "loop", "name", "context", "eager_start", NULL}; |
| 518 |
static _PyArg_Parser _parser = { |
| 519 |
.keywords = _keywords, |
| 520 |
.fname = "Task", |
| 521 |
.kwtuple = KWTUPLE, |
| 522 |
}; |
| 523 |
#undef KWTUPLE |
| 524 |
PyObject *argsbuf[5]; |
| 525 |
PyObject * const *fastargs; |
| 526 |
Py_ssize_t nargs = PyTuple_GET_SIZE(args); |
| 527 |
Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 1; |
| 528 |
PyObject *coro; |
| 529 |
PyObject *loop = Py_None; |
| 530 |
PyObject *name = Py_None; |
| 531 |
PyObject *context = Py_None; |
| 532 |
int eager_start = 0; |
| 533 |
|
| 534 |
fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 1, 1, 0, argsbuf); |
| 535 |
if (!fastargs) { |
| 536 |
goto exit; |
| 537 |
} |
| 538 |
coro = fastargs[0]; |
| 539 |
if (!noptargs) { |
| 540 |
goto skip_optional_kwonly; |
| 541 |
} |
| 542 |
if (fastargs[1]) { |
| 543 |
loop = fastargs[1]; |
| 544 |
if (!--noptargs) { |
| 545 |
goto skip_optional_kwonly; |
| 546 |
} |
| 547 |
} |
| 548 |
if (fastargs[2]) { |
| 549 |
name = fastargs[2]; |
| 550 |
if (!--noptargs) { |
| 551 |
goto skip_optional_kwonly; |
| 552 |
} |
| 553 |
} |
| 554 |
if (fastargs[3]) { |
| 555 |
context = fastargs[3]; |
| 556 |
if (!--noptargs) { |
| 557 |
goto skip_optional_kwonly; |
| 558 |
} |
| 559 |
} |
| 560 |
eager_start = PyObject_IsTrue(fastargs[4]); |
| 561 |
if (eager_start < 0) { |
| 562 |
goto exit; |
| 563 |
} |
| 564 |
skip_optional_kwonly: |
| 565 |
return_value = _asyncio_Task___init___impl((TaskObj *)self, coro, loop, name, context, eager_start); |
| 566 |
|
| 567 |
exit: |
| 568 |
return return_value; |
| 569 |
} |
| 570 |
|
| 571 |
PyDoc_STRVAR(_asyncio_Task__make_cancelled_error__doc__, |
| 572 |
"_make_cancelled_error($self, /)\n" |
| 573 |
"--\n" |
| 574 |
"\n" |
| 575 |
"Create the CancelledError to raise if the Task is cancelled.\n" |
| 576 |
"\n" |
| 577 |
"This should only be called once when handling a cancellation since\n" |
| 578 |
"it erases the context exception value."); |
| 579 |
|
| 580 |
#define _ASYNCIO_TASK__MAKE_CANCELLED_ERROR_METHODDEF \ |
| 581 |
{"_make_cancelled_error", (PyCFunction)_asyncio_Task__make_cancelled_error, METH_NOARGS, _asyncio_Task__make_cancelled_error__doc__}, |
| 582 |
|
| 583 |
static PyObject * |
| 584 |
_asyncio_Task__make_cancelled_error_impl(TaskObj *self); |
| 585 |
|
| 586 |
static PyObject * |
| 587 |
_asyncio_Task__make_cancelled_error(TaskObj *self, PyObject *Py_UNUSED(ignored)) |
| 588 |
{ |
| 589 |
return _asyncio_Task__make_cancelled_error_impl(self); |
| 590 |
} |
| 591 |
|
| 592 |
PyDoc_STRVAR(_asyncio_Task_cancel__doc__, |
| 593 |
"cancel($self, /, msg=None)\n" |
| 594 |
"--\n" |
| 595 |
"\n" |
| 596 |
"Request that this task cancel itself.\n" |
| 597 |
"\n" |
| 598 |
"This arranges for a CancelledError to be thrown into the\n" |
| 599 |
"wrapped coroutine on the next cycle through the event loop.\n" |
| 600 |
"The coroutine then has a chance to clean up or even deny\n" |
| 601 |
"the request using try/except/finally.\n" |
| 602 |
"\n" |
| 603 |
"Unlike Future.cancel, this does not guarantee that the\n" |
| 604 |
"task will be cancelled: the exception might be caught and\n" |
| 605 |
"acted upon, delaying cancellation of the task or preventing\n" |
| 606 |
"cancellation completely. The task may also return a value or\n" |
| 607 |
"raise a different exception.\n" |
| 608 |
"\n" |
| 609 |
"Immediately after this method is called, Task.cancelled() will\n" |
| 610 |
"not return True (unless the task was already cancelled). A\n" |
| 611 |
"task will be marked as cancelled when the wrapped coroutine\n" |
| 612 |
"terminates with a CancelledError exception (even if cancel()\n" |
| 613 |
"was not called).\n" |
| 614 |
"\n" |
| 615 |
"This also increases the task\'s count of cancellation requests."); |
| 616 |
|
| 617 |
#define _ASYNCIO_TASK_CANCEL_METHODDEF \ |
| 618 |
{"cancel", _PyCFunction_CAST(_asyncio_Task_cancel), METH_FASTCALL|METH_KEYWORDS, _asyncio_Task_cancel__doc__}, |
| 619 |
|
| 620 |
static PyObject * |
| 621 |
_asyncio_Task_cancel_impl(TaskObj *self, PyObject *msg); |
| 622 |
|
| 623 |
static PyObject * |
| 624 |
_asyncio_Task_cancel(TaskObj *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
| 625 |
{ |
| 626 |
PyObject *return_value = NULL; |
| 627 |
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
| 628 |
|
| 629 |
#define NUM_KEYWORDS 1 |
| 630 |
static struct { |
| 631 |
PyGC_Head _this_is_not_used; |
| 632 |
PyObject_VAR_HEAD |
| 633 |
PyObject *ob_item[NUM_KEYWORDS]; |
| 634 |
} _kwtuple = { |
| 635 |
.ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
| 636 |
.ob_item = { &_Py_ID(msg), }, |
| 637 |
}; |
| 638 |
#undef NUM_KEYWORDS |
| 639 |
#define KWTUPLE (&_kwtuple.ob_base.ob_base) |
| 640 |
|
| 641 |
#else // !Py_BUILD_CORE |
| 642 |
# define KWTUPLE NULL |
| 643 |
#endif // !Py_BUILD_CORE |
| 644 |
|
| 645 |
static const char * const _keywords[] = {"msg", NULL}; |
| 646 |
static _PyArg_Parser _parser = { |
| 647 |
.keywords = _keywords, |
| 648 |
.fname = "cancel", |
| 649 |
.kwtuple = KWTUPLE, |
| 650 |
}; |
| 651 |
#undef KWTUPLE |
| 652 |
PyObject *argsbuf[1]; |
| 653 |
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; |
| 654 |
PyObject *msg = Py_None; |
| 655 |
|
| 656 |
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf); |
| 657 |
if (!args) { |
| 658 |
goto exit; |
| 659 |
} |
| 660 |
if (!noptargs) { |
| 661 |
goto skip_optional_pos; |
| 662 |
} |
| 663 |
msg = args[0]; |
| 664 |
skip_optional_pos: |
| 665 |
return_value = _asyncio_Task_cancel_impl(self, msg); |
| 666 |
|
| 667 |
exit: |
| 668 |
return return_value; |
| 669 |
} |
| 670 |
|
| 671 |
PyDoc_STRVAR(_asyncio_Task_cancelling__doc__, |
| 672 |
"cancelling($self, /)\n" |
| 673 |
"--\n" |
| 674 |
"\n" |
| 675 |
"Return the count of the task\'s cancellation requests.\n" |
| 676 |
"\n" |
| 677 |
"This count is incremented when .cancel() is called\n" |
| 678 |
"and may be decremented using .uncancel()."); |
| 679 |
|
| 680 |
#define _ASYNCIO_TASK_CANCELLING_METHODDEF \ |
| 681 |
{"cancelling", (PyCFunction)_asyncio_Task_cancelling, METH_NOARGS, _asyncio_Task_cancelling__doc__}, |
| 682 |
|
| 683 |
static PyObject * |
| 684 |
_asyncio_Task_cancelling_impl(TaskObj *self); |
| 685 |
|
| 686 |
static PyObject * |
| 687 |
_asyncio_Task_cancelling(TaskObj *self, PyObject *Py_UNUSED(ignored)) |
| 688 |
{ |
| 689 |
return _asyncio_Task_cancelling_impl(self); |
| 690 |
} |
| 691 |
|
| 692 |
PyDoc_STRVAR(_asyncio_Task_uncancel__doc__, |
| 693 |
"uncancel($self, /)\n" |
| 694 |
"--\n" |
| 695 |
"\n" |
| 696 |
"Decrement the task\'s count of cancellation requests.\n" |
| 697 |
"\n" |
| 698 |
"This should be used by tasks that catch CancelledError\n" |
| 699 |
"and wish to continue indefinitely until they are cancelled again.\n" |
| 700 |
"\n" |
| 701 |
"Returns the remaining number of cancellation requests."); |
| 702 |
|
| 703 |
#define _ASYNCIO_TASK_UNCANCEL_METHODDEF \ |
| 704 |
{"uncancel", (PyCFunction)_asyncio_Task_uncancel, METH_NOARGS, _asyncio_Task_uncancel__doc__}, |
| 705 |
|
| 706 |
static PyObject * |
| 707 |
_asyncio_Task_uncancel_impl(TaskObj *self); |
| 708 |
|
| 709 |
static PyObject * |
| 710 |
_asyncio_Task_uncancel(TaskObj *self, PyObject *Py_UNUSED(ignored)) |
| 711 |
{ |
| 712 |
return _asyncio_Task_uncancel_impl(self); |
| 713 |
} |
| 714 |
|
| 715 |
PyDoc_STRVAR(_asyncio_Task_get_stack__doc__, |
| 716 |
"get_stack($self, /, *, limit=None)\n" |
| 717 |
"--\n" |
| 718 |
"\n" |
| 719 |
"Return the list of stack frames for this task\'s coroutine.\n" |
| 720 |
"\n" |
| 721 |
"If the coroutine is not done, this returns the stack where it is\n" |
| 722 |
"suspended. If the coroutine has completed successfully or was\n" |
| 723 |
"cancelled, this returns an empty list. If the coroutine was\n" |
| 724 |
"terminated by an exception, this returns the list of traceback\n" |
| 725 |
"frames.\n" |
| 726 |
"\n" |
| 727 |
"The frames are always ordered from oldest to newest.\n" |
| 728 |
"\n" |
| 729 |
"The optional limit gives the maximum number of frames to\n" |
| 730 |
"return; by default all available frames are returned. Its\n" |
| 731 |
"meaning differs depending on whether a stack or a traceback is\n" |
| 732 |
"returned: the newest frames of a stack are returned, but the\n" |
| 733 |
"oldest frames of a traceback are returned. (This matches the\n" |
| 734 |
"behavior of the traceback module.)\n" |
| 735 |
"\n" |
| 736 |
"For reasons beyond our control, only one stack frame is\n" |
| 737 |
"returned for a suspended coroutine."); |
| 738 |
|
| 739 |
#define _ASYNCIO_TASK_GET_STACK_METHODDEF \ |
| 740 |
{"get_stack", _PyCFunction_CAST(_asyncio_Task_get_stack), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _asyncio_Task_get_stack__doc__}, |
| 741 |
|
| 742 |
static PyObject * |
| 743 |
_asyncio_Task_get_stack_impl(TaskObj *self, PyTypeObject *cls, |
| 744 |
PyObject *limit); |
| 745 |
|
| 746 |
static PyObject * |
| 747 |
_asyncio_Task_get_stack(TaskObj *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
| 748 |
{ |
| 749 |
PyObject *return_value = NULL; |
| 750 |
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
| 751 |
|
| 752 |
#define NUM_KEYWORDS 1 |
| 753 |
static struct { |
| 754 |
PyGC_Head _this_is_not_used; |
| 755 |
PyObject_VAR_HEAD |
| 756 |
PyObject *ob_item[NUM_KEYWORDS]; |
| 757 |
} _kwtuple = { |
| 758 |
.ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
| 759 |
.ob_item = { &_Py_ID(limit), }, |
| 760 |
}; |
| 761 |
#undef NUM_KEYWORDS |
| 762 |
#define KWTUPLE (&_kwtuple.ob_base.ob_base) |
| 763 |
|
| 764 |
#else // !Py_BUILD_CORE |
| 765 |
# define KWTUPLE NULL |
| 766 |
#endif // !Py_BUILD_CORE |
| 767 |
|
| 768 |
static const char * const _keywords[] = {"limit", NULL}; |
| 769 |
static _PyArg_Parser _parser = { |
| 770 |
.keywords = _keywords, |
| 771 |
.fname = "get_stack", |
| 772 |
.kwtuple = KWTUPLE, |
| 773 |
}; |
| 774 |
#undef KWTUPLE |
| 775 |
PyObject *argsbuf[1]; |
| 776 |
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; |
| 777 |
PyObject *limit = Py_None; |
| 778 |
|
| 779 |
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf); |
| 780 |
if (!args) { |
| 781 |
goto exit; |
| 782 |
} |
| 783 |
if (!noptargs) { |
| 784 |
goto skip_optional_kwonly; |
| 785 |
} |
| 786 |
limit = args[0]; |
| 787 |
skip_optional_kwonly: |
| 788 |
return_value = _asyncio_Task_get_stack_impl(self, cls, limit); |
| 789 |
|
| 790 |
exit: |
| 791 |
return return_value; |
| 792 |
} |
| 793 |
|
| 794 |
PyDoc_STRVAR(_asyncio_Task_print_stack__doc__, |
| 795 |
"print_stack($self, /, *, limit=None, file=None)\n" |
| 796 |
"--\n" |
| 797 |
"\n" |
| 798 |
"Print the stack or traceback for this task\'s coroutine.\n" |
| 799 |
"\n" |
| 800 |
"This produces output similar to that of the traceback module,\n" |
| 801 |
"for the frames retrieved by get_stack(). The limit argument\n" |
| 802 |
"is passed to get_stack(). The file argument is an I/O stream\n" |
| 803 |
"to which the output is written; by default output is written\n" |
| 804 |
"to sys.stderr."); |
| 805 |
|
| 806 |
#define _ASYNCIO_TASK_PRINT_STACK_METHODDEF \ |
| 807 |
{"print_stack", _PyCFunction_CAST(_asyncio_Task_print_stack), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _asyncio_Task_print_stack__doc__}, |
| 808 |
|
| 809 |
static PyObject * |
| 810 |
_asyncio_Task_print_stack_impl(TaskObj *self, PyTypeObject *cls, |
| 811 |
PyObject *limit, PyObject *file); |
| 812 |
|
| 813 |
static PyObject * |
| 814 |
_asyncio_Task_print_stack(TaskObj *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
| 815 |
{ |
| 816 |
PyObject *return_value = NULL; |
| 817 |
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
| 818 |
|
| 819 |
#define NUM_KEYWORDS 2 |
| 820 |
static struct { |
| 821 |
PyGC_Head _this_is_not_used; |
| 822 |
PyObject_VAR_HEAD |
| 823 |
PyObject *ob_item[NUM_KEYWORDS]; |
| 824 |
} _kwtuple = { |
| 825 |
.ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
| 826 |
.ob_item = { &_Py_ID(limit), &_Py_ID(file), }, |
| 827 |
}; |
| 828 |
#undef NUM_KEYWORDS |
| 829 |
#define KWTUPLE (&_kwtuple.ob_base.ob_base) |
| 830 |
|
| 831 |
#else // !Py_BUILD_CORE |
| 832 |
# define KWTUPLE NULL |
| 833 |
#endif // !Py_BUILD_CORE |
| 834 |
|
| 835 |
static const char * const _keywords[] = {"limit", "file", NULL}; |
| 836 |
static _PyArg_Parser _parser = { |
| 837 |
.keywords = _keywords, |
| 838 |
.fname = "print_stack", |
| 839 |
.kwtuple = KWTUPLE, |
| 840 |
}; |
| 841 |
#undef KWTUPLE |
| 842 |
PyObject *argsbuf[2]; |
| 843 |
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; |
| 844 |
PyObject *limit = Py_None; |
| 845 |
PyObject *file = Py_None; |
| 846 |
|
| 847 |
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf); |
| 848 |
if (!args) { |
| 849 |
goto exit; |
| 850 |
} |
| 851 |
if (!noptargs) { |
| 852 |
goto skip_optional_kwonly; |
| 853 |
} |
| 854 |
if (args[0]) { |
| 855 |
limit = args[0]; |
| 856 |
if (!--noptargs) { |
| 857 |
goto skip_optional_kwonly; |
| 858 |
} |
| 859 |
} |
| 860 |
file = args[1]; |
| 861 |
skip_optional_kwonly: |
| 862 |
return_value = _asyncio_Task_print_stack_impl(self, cls, limit, file); |
| 863 |
|
| 864 |
exit: |
| 865 |
return return_value; |
| 866 |
} |
| 867 |
|
| 868 |
PyDoc_STRVAR(_asyncio_Task_set_result__doc__, |
| 869 |
"set_result($self, result, /)\n" |
| 870 |
"--\n" |
| 871 |
"\n"); |
| 872 |
|
| 873 |
#define _ASYNCIO_TASK_SET_RESULT_METHODDEF \ |
| 874 |
{"set_result", (PyCFunction)_asyncio_Task_set_result, METH_O, _asyncio_Task_set_result__doc__}, |
| 875 |
|
| 876 |
PyDoc_STRVAR(_asyncio_Task_set_exception__doc__, |
| 877 |
"set_exception($self, exception, /)\n" |
| 878 |
"--\n" |
| 879 |
"\n"); |
| 880 |
|
| 881 |
#define _ASYNCIO_TASK_SET_EXCEPTION_METHODDEF \ |
| 882 |
{"set_exception", (PyCFunction)_asyncio_Task_set_exception, METH_O, _asyncio_Task_set_exception__doc__}, |
| 883 |
|
| 884 |
PyDoc_STRVAR(_asyncio_Task_get_coro__doc__, |
| 885 |
"get_coro($self, /)\n" |
| 886 |
"--\n" |
| 887 |
"\n"); |
| 888 |
|
| 889 |
#define _ASYNCIO_TASK_GET_CORO_METHODDEF \ |
| 890 |
{"get_coro", (PyCFunction)_asyncio_Task_get_coro, METH_NOARGS, _asyncio_Task_get_coro__doc__}, |
| 891 |
|
| 892 |
static PyObject * |
| 893 |
_asyncio_Task_get_coro_impl(TaskObj *self); |
| 894 |
|
| 895 |
static PyObject * |
| 896 |
_asyncio_Task_get_coro(TaskObj *self, PyObject *Py_UNUSED(ignored)) |
| 897 |
{ |
| 898 |
return _asyncio_Task_get_coro_impl(self); |
| 899 |
} |
| 900 |
|
| 901 |
PyDoc_STRVAR(_asyncio_Task_get_context__doc__, |
| 902 |
"get_context($self, /)\n" |
| 903 |
"--\n" |
| 904 |
"\n"); |
| 905 |
|
| 906 |
#define _ASYNCIO_TASK_GET_CONTEXT_METHODDEF \ |
| 907 |
{"get_context", (PyCFunction)_asyncio_Task_get_context, METH_NOARGS, _asyncio_Task_get_context__doc__}, |
| 908 |
|
| 909 |
static PyObject * |
| 910 |
_asyncio_Task_get_context_impl(TaskObj *self); |
| 911 |
|
| 912 |
static PyObject * |
| 913 |
_asyncio_Task_get_context(TaskObj *self, PyObject *Py_UNUSED(ignored)) |
| 914 |
{ |
| 915 |
return _asyncio_Task_get_context_impl(self); |
| 916 |
} |
| 917 |
|
| 918 |
PyDoc_STRVAR(_asyncio_Task_get_name__doc__, |
| 919 |
"get_name($self, /)\n" |
| 920 |
"--\n" |
| 921 |
"\n"); |
| 922 |
|
| 923 |
#define _ASYNCIO_TASK_GET_NAME_METHODDEF \ |
| 924 |
{"get_name", (PyCFunction)_asyncio_Task_get_name, METH_NOARGS, _asyncio_Task_get_name__doc__}, |
| 925 |
|
| 926 |
static PyObject * |
| 927 |
_asyncio_Task_get_name_impl(TaskObj *self); |
| 928 |
|
| 929 |
static PyObject * |
| 930 |
_asyncio_Task_get_name(TaskObj *self, PyObject *Py_UNUSED(ignored)) |
| 931 |
{ |
| 932 |
return _asyncio_Task_get_name_impl(self); |
| 933 |
} |
| 934 |
|
| 935 |
PyDoc_STRVAR(_asyncio_Task_set_name__doc__, |
| 936 |
"set_name($self, value, /)\n" |
| 937 |
"--\n" |
| 938 |
"\n"); |
| 939 |
|
| 940 |
#define _ASYNCIO_TASK_SET_NAME_METHODDEF \ |
| 941 |
{"set_name", (PyCFunction)_asyncio_Task_set_name, METH_O, _asyncio_Task_set_name__doc__}, |
| 942 |
|
| 943 |
PyDoc_STRVAR(_asyncio__get_running_loop__doc__, |
| 944 |
"_get_running_loop($module, /)\n" |
| 945 |
"--\n" |
| 946 |
"\n" |
| 947 |
"Return the running event loop or None.\n" |
| 948 |
"\n" |
| 949 |
"This is a low-level function intended to be used by event loops.\n" |
| 950 |
"This function is thread-specific."); |
| 951 |
|
| 952 |
#define _ASYNCIO__GET_RUNNING_LOOP_METHODDEF \ |
| 953 |
{"_get_running_loop", (PyCFunction)_asyncio__get_running_loop, METH_NOARGS, _asyncio__get_running_loop__doc__}, |
| 954 |
|
| 955 |
static PyObject * |
| 956 |
_asyncio__get_running_loop_impl(PyObject *module); |
| 957 |
|
| 958 |
static PyObject * |
| 959 |
_asyncio__get_running_loop(PyObject *module, PyObject *Py_UNUSED(ignored)) |
| 960 |
{ |
| 961 |
return _asyncio__get_running_loop_impl(module); |
| 962 |
} |
| 963 |
|
| 964 |
PyDoc_STRVAR(_asyncio__set_running_loop__doc__, |
| 965 |
"_set_running_loop($module, loop, /)\n" |
| 966 |
"--\n" |
| 967 |
"\n" |
| 968 |
"Set the running event loop.\n" |
| 969 |
"\n" |
| 970 |
"This is a low-level function intended to be used by event loops.\n" |
| 971 |
"This function is thread-specific."); |
| 972 |
|
| 973 |
#define _ASYNCIO__SET_RUNNING_LOOP_METHODDEF \ |
| 974 |
{"_set_running_loop", (PyCFunction)_asyncio__set_running_loop, METH_O, _asyncio__set_running_loop__doc__}, |
| 975 |
|
| 976 |
PyDoc_STRVAR(_asyncio_get_event_loop__doc__, |
| 977 |
"get_event_loop($module, /)\n" |
| 978 |
"--\n" |
| 979 |
"\n" |
| 980 |
"Return an asyncio event loop.\n" |
| 981 |
"\n" |
| 982 |
"When called from a coroutine or a callback (e.g. scheduled with\n" |
| 983 |
"call_soon or similar API), this function will always return the\n" |
| 984 |
"running event loop.\n" |
| 985 |
"\n" |
| 986 |
"If there is no running event loop set, the function will return\n" |
| 987 |
"the result of `get_event_loop_policy().get_event_loop()` call."); |
| 988 |
|
| 989 |
#define _ASYNCIO_GET_EVENT_LOOP_METHODDEF \ |
| 990 |
{"get_event_loop", (PyCFunction)_asyncio_get_event_loop, METH_NOARGS, _asyncio_get_event_loop__doc__}, |
| 991 |
|
| 992 |
static PyObject * |
| 993 |
_asyncio_get_event_loop_impl(PyObject *module); |
| 994 |
|
| 995 |
static PyObject * |
| 996 |
_asyncio_get_event_loop(PyObject *module, PyObject *Py_UNUSED(ignored)) |
| 997 |
{ |
| 998 |
return _asyncio_get_event_loop_impl(module); |
| 999 |
} |
| 1000 |
|
| 1001 |
PyDoc_STRVAR(_asyncio_get_running_loop__doc__, |
| 1002 |
"get_running_loop($module, /)\n" |
| 1003 |
"--\n" |
| 1004 |
"\n" |
| 1005 |
"Return the running event loop. Raise a RuntimeError if there is none.\n" |
| 1006 |
"\n" |
| 1007 |
"This function is thread-specific."); |
| 1008 |
|
| 1009 |
#define _ASYNCIO_GET_RUNNING_LOOP_METHODDEF \ |
| 1010 |
{"get_running_loop", (PyCFunction)_asyncio_get_running_loop, METH_NOARGS, _asyncio_get_running_loop__doc__}, |
| 1011 |
|
| 1012 |
static PyObject * |
| 1013 |
_asyncio_get_running_loop_impl(PyObject *module); |
| 1014 |
|
| 1015 |
static PyObject * |
| 1016 |
_asyncio_get_running_loop(PyObject *module, PyObject *Py_UNUSED(ignored)) |
| 1017 |
{ |
| 1018 |
return _asyncio_get_running_loop_impl(module); |
| 1019 |
} |
| 1020 |
|
| 1021 |
PyDoc_STRVAR(_asyncio__register_task__doc__, |
| 1022 |
"_register_task($module, /, task)\n" |
| 1023 |
"--\n" |
| 1024 |
"\n" |
| 1025 |
"Register a new task in asyncio as executed by loop.\n" |
| 1026 |
"\n" |
| 1027 |
"Returns None."); |
| 1028 |
|
| 1029 |
#define _ASYNCIO__REGISTER_TASK_METHODDEF \ |
| 1030 |
{"_register_task", _PyCFunction_CAST(_asyncio__register_task), METH_FASTCALL|METH_KEYWORDS, _asyncio__register_task__doc__}, |
| 1031 |
|
| 1032 |
static PyObject * |
| 1033 |
_asyncio__register_task_impl(PyObject *module, PyObject *task); |
| 1034 |
|
| 1035 |
static PyObject * |
| 1036 |
_asyncio__register_task(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
| 1037 |
{ |
| 1038 |
PyObject *return_value = NULL; |
| 1039 |
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
| 1040 |
|
| 1041 |
#define NUM_KEYWORDS 1 |
| 1042 |
static struct { |
| 1043 |
PyGC_Head _this_is_not_used; |
| 1044 |
PyObject_VAR_HEAD |
| 1045 |
PyObject *ob_item[NUM_KEYWORDS]; |
| 1046 |
} _kwtuple = { |
| 1047 |
.ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
| 1048 |
.ob_item = { &_Py_ID(task), }, |
| 1049 |
}; |
| 1050 |
#undef NUM_KEYWORDS |
| 1051 |
#define KWTUPLE (&_kwtuple.ob_base.ob_base) |
| 1052 |
|
| 1053 |
#else // !Py_BUILD_CORE |
| 1054 |
# define KWTUPLE NULL |
| 1055 |
#endif // !Py_BUILD_CORE |
| 1056 |
|
| 1057 |
static const char * const _keywords[] = {"task", NULL}; |
| 1058 |
static _PyArg_Parser _parser = { |
| 1059 |
.keywords = _keywords, |
| 1060 |
.fname = "_register_task", |
| 1061 |
.kwtuple = KWTUPLE, |
| 1062 |
}; |
| 1063 |
#undef KWTUPLE |
| 1064 |
PyObject *argsbuf[1]; |
| 1065 |
PyObject *task; |
| 1066 |
|
| 1067 |
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); |
| 1068 |
if (!args) { |
| 1069 |
goto exit; |
| 1070 |
} |
| 1071 |
task = args[0]; |
| 1072 |
return_value = _asyncio__register_task_impl(module, task); |
| 1073 |
|
| 1074 |
exit: |
| 1075 |
return return_value; |
| 1076 |
} |
| 1077 |
|
| 1078 |
PyDoc_STRVAR(_asyncio__register_eager_task__doc__, |
| 1079 |
"_register_eager_task($module, /, task)\n" |
| 1080 |
"--\n" |
| 1081 |
"\n" |
| 1082 |
"Register a new task in asyncio as executed by loop.\n" |
| 1083 |
"\n" |
| 1084 |
"Returns None."); |
| 1085 |
|
| 1086 |
#define _ASYNCIO__REGISTER_EAGER_TASK_METHODDEF \ |
| 1087 |
{"_register_eager_task", _PyCFunction_CAST(_asyncio__register_eager_task), METH_FASTCALL|METH_KEYWORDS, _asyncio__register_eager_task__doc__}, |
| 1088 |
|
| 1089 |
static PyObject * |
| 1090 |
_asyncio__register_eager_task_impl(PyObject *module, PyObject *task); |
| 1091 |
|
| 1092 |
static PyObject * |
| 1093 |
_asyncio__register_eager_task(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
| 1094 |
{ |
| 1095 |
PyObject *return_value = NULL; |
| 1096 |
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
| 1097 |
|
| 1098 |
#define NUM_KEYWORDS 1 |
| 1099 |
static struct { |
| 1100 |
PyGC_Head _this_is_not_used; |
| 1101 |
PyObject_VAR_HEAD |
| 1102 |
PyObject *ob_item[NUM_KEYWORDS]; |
| 1103 |
} _kwtuple = { |
| 1104 |
.ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
| 1105 |
.ob_item = { &_Py_ID(task), }, |
| 1106 |
}; |
| 1107 |
#undef NUM_KEYWORDS |
| 1108 |
#define KWTUPLE (&_kwtuple.ob_base.ob_base) |
| 1109 |
|
| 1110 |
#else // !Py_BUILD_CORE |
| 1111 |
# define KWTUPLE NULL |
| 1112 |
#endif // !Py_BUILD_CORE |
| 1113 |
|
| 1114 |
static const char * const _keywords[] = {"task", NULL}; |
| 1115 |
static _PyArg_Parser _parser = { |
| 1116 |
.keywords = _keywords, |
| 1117 |
.fname = "_register_eager_task", |
| 1118 |
.kwtuple = KWTUPLE, |
| 1119 |
}; |
| 1120 |
#undef KWTUPLE |
| 1121 |
PyObject *argsbuf[1]; |
| 1122 |
PyObject *task; |
| 1123 |
|
| 1124 |
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); |
| 1125 |
if (!args) { |
| 1126 |
goto exit; |
| 1127 |
} |
| 1128 |
task = args[0]; |
| 1129 |
return_value = _asyncio__register_eager_task_impl(module, task); |
| 1130 |
|
| 1131 |
exit: |
| 1132 |
return return_value; |
| 1133 |
} |
| 1134 |
|
| 1135 |
PyDoc_STRVAR(_asyncio__unregister_task__doc__, |
| 1136 |
"_unregister_task($module, /, task)\n" |
| 1137 |
"--\n" |
| 1138 |
"\n" |
| 1139 |
"Unregister a task.\n" |
| 1140 |
"\n" |
| 1141 |
"Returns None."); |
| 1142 |
|
| 1143 |
#define _ASYNCIO__UNREGISTER_TASK_METHODDEF \ |
| 1144 |
{"_unregister_task", _PyCFunction_CAST(_asyncio__unregister_task), METH_FASTCALL|METH_KEYWORDS, _asyncio__unregister_task__doc__}, |
| 1145 |
|
| 1146 |
static PyObject * |
| 1147 |
_asyncio__unregister_task_impl(PyObject *module, PyObject *task); |
| 1148 |
|
| 1149 |
static PyObject * |
| 1150 |
_asyncio__unregister_task(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
| 1151 |
{ |
| 1152 |
PyObject *return_value = NULL; |
| 1153 |
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
| 1154 |
|
| 1155 |
#define NUM_KEYWORDS 1 |
| 1156 |
static struct { |
| 1157 |
PyGC_Head _this_is_not_used; |
| 1158 |
PyObject_VAR_HEAD |
| 1159 |
PyObject *ob_item[NUM_KEYWORDS]; |
| 1160 |
} _kwtuple = { |
| 1161 |
.ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
| 1162 |
.ob_item = { &_Py_ID(task), }, |
| 1163 |
}; |
| 1164 |
#undef NUM_KEYWORDS |
| 1165 |
#define KWTUPLE (&_kwtuple.ob_base.ob_base) |
| 1166 |
|
| 1167 |
#else // !Py_BUILD_CORE |
| 1168 |
# define KWTUPLE NULL |
| 1169 |
#endif // !Py_BUILD_CORE |
| 1170 |
|
| 1171 |
static const char * const _keywords[] = {"task", NULL}; |
| 1172 |
static _PyArg_Parser _parser = { |
| 1173 |
.keywords = _keywords, |
| 1174 |
.fname = "_unregister_task", |
| 1175 |
.kwtuple = KWTUPLE, |
| 1176 |
}; |
| 1177 |
#undef KWTUPLE |
| 1178 |
PyObject *argsbuf[1]; |
| 1179 |
PyObject *task; |
| 1180 |
|
| 1181 |
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); |
| 1182 |
if (!args) { |
| 1183 |
goto exit; |
| 1184 |
} |
| 1185 |
task = args[0]; |
| 1186 |
return_value = _asyncio__unregister_task_impl(module, task); |
| 1187 |
|
| 1188 |
exit: |
| 1189 |
return return_value; |
| 1190 |
} |
| 1191 |
|
| 1192 |
PyDoc_STRVAR(_asyncio__unregister_eager_task__doc__, |
| 1193 |
"_unregister_eager_task($module, /, task)\n" |
| 1194 |
"--\n" |
| 1195 |
"\n" |
| 1196 |
"Unregister a task.\n" |
| 1197 |
"\n" |
| 1198 |
"Returns None."); |
| 1199 |
|
| 1200 |
#define _ASYNCIO__UNREGISTER_EAGER_TASK_METHODDEF \ |
| 1201 |
{"_unregister_eager_task", _PyCFunction_CAST(_asyncio__unregister_eager_task), METH_FASTCALL|METH_KEYWORDS, _asyncio__unregister_eager_task__doc__}, |
| 1202 |
|
| 1203 |
static PyObject * |
| 1204 |
_asyncio__unregister_eager_task_impl(PyObject *module, PyObject *task); |
| 1205 |
|
| 1206 |
static PyObject * |
| 1207 |
_asyncio__unregister_eager_task(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
| 1208 |
{ |
| 1209 |
PyObject *return_value = NULL; |
| 1210 |
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
| 1211 |
|
| 1212 |
#define NUM_KEYWORDS 1 |
| 1213 |
static struct { |
| 1214 |
PyGC_Head _this_is_not_used; |
| 1215 |
PyObject_VAR_HEAD |
| 1216 |
PyObject *ob_item[NUM_KEYWORDS]; |
| 1217 |
} _kwtuple = { |
| 1218 |
.ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
| 1219 |
.ob_item = { &_Py_ID(task), }, |
| 1220 |
}; |
| 1221 |
#undef NUM_KEYWORDS |
| 1222 |
#define KWTUPLE (&_kwtuple.ob_base.ob_base) |
| 1223 |
|
| 1224 |
#else // !Py_BUILD_CORE |
| 1225 |
# define KWTUPLE NULL |
| 1226 |
#endif // !Py_BUILD_CORE |
| 1227 |
|
| 1228 |
static const char * const _keywords[] = {"task", NULL}; |
| 1229 |
static _PyArg_Parser _parser = { |
| 1230 |
.keywords = _keywords, |
| 1231 |
.fname = "_unregister_eager_task", |
| 1232 |
.kwtuple = KWTUPLE, |
| 1233 |
}; |
| 1234 |
#undef KWTUPLE |
| 1235 |
PyObject *argsbuf[1]; |
| 1236 |
PyObject *task; |
| 1237 |
|
| 1238 |
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf); |
| 1239 |
if (!args) { |
| 1240 |
goto exit; |
| 1241 |
} |
| 1242 |
task = args[0]; |
| 1243 |
return_value = _asyncio__unregister_eager_task_impl(module, task); |
| 1244 |
|
| 1245 |
exit: |
| 1246 |
return return_value; |
| 1247 |
} |
| 1248 |
|
| 1249 |
PyDoc_STRVAR(_asyncio__enter_task__doc__, |
| 1250 |
"_enter_task($module, /, loop, task)\n" |
| 1251 |
"--\n" |
| 1252 |
"\n" |
| 1253 |
"Enter into task execution or resume suspended task.\n" |
| 1254 |
"\n" |
| 1255 |
"Task belongs to loop.\n" |
| 1256 |
"\n" |
| 1257 |
"Returns None."); |
| 1258 |
|
| 1259 |
#define _ASYNCIO__ENTER_TASK_METHODDEF \ |
| 1260 |
{"_enter_task", _PyCFunction_CAST(_asyncio__enter_task), METH_FASTCALL|METH_KEYWORDS, _asyncio__enter_task__doc__}, |
| 1261 |
|
| 1262 |
static PyObject * |
| 1263 |
_asyncio__enter_task_impl(PyObject *module, PyObject *loop, PyObject *task); |
| 1264 |
|
| 1265 |
static PyObject * |
| 1266 |
_asyncio__enter_task(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
| 1267 |
{ |
| 1268 |
PyObject *return_value = NULL; |
| 1269 |
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
| 1270 |
|
| 1271 |
#define NUM_KEYWORDS 2 |
| 1272 |
static struct { |
| 1273 |
PyGC_Head _this_is_not_used; |
| 1274 |
PyObject_VAR_HEAD |
| 1275 |
PyObject *ob_item[NUM_KEYWORDS]; |
| 1276 |
} _kwtuple = { |
| 1277 |
.ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
| 1278 |
.ob_item = { &_Py_ID(loop), &_Py_ID(task), }, |
| 1279 |
}; |
| 1280 |
#undef NUM_KEYWORDS |
| 1281 |
#define KWTUPLE (&_kwtuple.ob_base.ob_base) |
| 1282 |
|
| 1283 |
#else // !Py_BUILD_CORE |
| 1284 |
# define KWTUPLE NULL |
| 1285 |
#endif // !Py_BUILD_CORE |
| 1286 |
|
| 1287 |
static const char * const _keywords[] = {"loop", "task", NULL}; |
| 1288 |
static _PyArg_Parser _parser = { |
| 1289 |
.keywords = _keywords, |
| 1290 |
.fname = "_enter_task", |
| 1291 |
.kwtuple = KWTUPLE, |
| 1292 |
}; |
| 1293 |
#undef KWTUPLE |
| 1294 |
PyObject *argsbuf[2]; |
| 1295 |
PyObject *loop; |
| 1296 |
PyObject *task; |
| 1297 |
|
| 1298 |
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf); |
| 1299 |
if (!args) { |
| 1300 |
goto exit; |
| 1301 |
} |
| 1302 |
loop = args[0]; |
| 1303 |
task = args[1]; |
| 1304 |
return_value = _asyncio__enter_task_impl(module, loop, task); |
| 1305 |
|
| 1306 |
exit: |
| 1307 |
return return_value; |
| 1308 |
} |
| 1309 |
|
| 1310 |
PyDoc_STRVAR(_asyncio__leave_task__doc__, |
| 1311 |
"_leave_task($module, /, loop, task)\n" |
| 1312 |
"--\n" |
| 1313 |
"\n" |
| 1314 |
"Leave task execution or suspend a task.\n" |
| 1315 |
"\n" |
| 1316 |
"Task belongs to loop.\n" |
| 1317 |
"\n" |
| 1318 |
"Returns None."); |
| 1319 |
|
| 1320 |
#define _ASYNCIO__LEAVE_TASK_METHODDEF \ |
| 1321 |
{"_leave_task", _PyCFunction_CAST(_asyncio__leave_task), METH_FASTCALL|METH_KEYWORDS, _asyncio__leave_task__doc__}, |
| 1322 |
|
| 1323 |
static PyObject * |
| 1324 |
_asyncio__leave_task_impl(PyObject *module, PyObject *loop, PyObject *task); |
| 1325 |
|
| 1326 |
static PyObject * |
| 1327 |
_asyncio__leave_task(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
| 1328 |
{ |
| 1329 |
PyObject *return_value = NULL; |
| 1330 |
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
| 1331 |
|
| 1332 |
#define NUM_KEYWORDS 2 |
| 1333 |
static struct { |
| 1334 |
PyGC_Head _this_is_not_used; |
| 1335 |
PyObject_VAR_HEAD |
| 1336 |
PyObject *ob_item[NUM_KEYWORDS]; |
| 1337 |
} _kwtuple = { |
| 1338 |
.ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
| 1339 |
.ob_item = { &_Py_ID(loop), &_Py_ID(task), }, |
| 1340 |
}; |
| 1341 |
#undef NUM_KEYWORDS |
| 1342 |
#define KWTUPLE (&_kwtuple.ob_base.ob_base) |
| 1343 |
|
| 1344 |
#else // !Py_BUILD_CORE |
| 1345 |
# define KWTUPLE NULL |
| 1346 |
#endif // !Py_BUILD_CORE |
| 1347 |
|
| 1348 |
static const char * const _keywords[] = {"loop", "task", NULL}; |
| 1349 |
static _PyArg_Parser _parser = { |
| 1350 |
.keywords = _keywords, |
| 1351 |
.fname = "_leave_task", |
| 1352 |
.kwtuple = KWTUPLE, |
| 1353 |
}; |
| 1354 |
#undef KWTUPLE |
| 1355 |
PyObject *argsbuf[2]; |
| 1356 |
PyObject *loop; |
| 1357 |
PyObject *task; |
| 1358 |
|
| 1359 |
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf); |
| 1360 |
if (!args) { |
| 1361 |
goto exit; |
| 1362 |
} |
| 1363 |
loop = args[0]; |
| 1364 |
task = args[1]; |
| 1365 |
return_value = _asyncio__leave_task_impl(module, loop, task); |
| 1366 |
|
| 1367 |
exit: |
| 1368 |
return return_value; |
| 1369 |
} |
| 1370 |
|
| 1371 |
PyDoc_STRVAR(_asyncio__swap_current_task__doc__, |
| 1372 |
"_swap_current_task($module, /, loop, task)\n" |
| 1373 |
"--\n" |
| 1374 |
"\n" |
| 1375 |
"Temporarily swap in the supplied task and return the original one (or None).\n" |
| 1376 |
"\n" |
| 1377 |
"This is intended for use during eager coroutine execution."); |
| 1378 |
|
| 1379 |
#define _ASYNCIO__SWAP_CURRENT_TASK_METHODDEF \ |
| 1380 |
{"_swap_current_task", _PyCFunction_CAST(_asyncio__swap_current_task), METH_FASTCALL|METH_KEYWORDS, _asyncio__swap_current_task__doc__}, |
| 1381 |
|
| 1382 |
static PyObject * |
| 1383 |
_asyncio__swap_current_task_impl(PyObject *module, PyObject *loop, |
| 1384 |
PyObject *task); |
| 1385 |
|
| 1386 |
static PyObject * |
| 1387 |
_asyncio__swap_current_task(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
| 1388 |
{ |
| 1389 |
PyObject *return_value = NULL; |
| 1390 |
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
| 1391 |
|
| 1392 |
#define NUM_KEYWORDS 2 |
| 1393 |
static struct { |
| 1394 |
PyGC_Head _this_is_not_used; |
| 1395 |
PyObject_VAR_HEAD |
| 1396 |
PyObject *ob_item[NUM_KEYWORDS]; |
| 1397 |
} _kwtuple = { |
| 1398 |
.ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
| 1399 |
.ob_item = { &_Py_ID(loop), &_Py_ID(task), }, |
| 1400 |
}; |
| 1401 |
#undef NUM_KEYWORDS |
| 1402 |
#define KWTUPLE (&_kwtuple.ob_base.ob_base) |
| 1403 |
|
| 1404 |
#else // !Py_BUILD_CORE |
| 1405 |
# define KWTUPLE NULL |
| 1406 |
#endif // !Py_BUILD_CORE |
| 1407 |
|
| 1408 |
static const char * const _keywords[] = {"loop", "task", NULL}; |
| 1409 |
static _PyArg_Parser _parser = { |
| 1410 |
.keywords = _keywords, |
| 1411 |
.fname = "_swap_current_task", |
| 1412 |
.kwtuple = KWTUPLE, |
| 1413 |
}; |
| 1414 |
#undef KWTUPLE |
| 1415 |
PyObject *argsbuf[2]; |
| 1416 |
PyObject *loop; |
| 1417 |
PyObject *task; |
| 1418 |
|
| 1419 |
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf); |
| 1420 |
if (!args) { |
| 1421 |
goto exit; |
| 1422 |
} |
| 1423 |
loop = args[0]; |
| 1424 |
task = args[1]; |
| 1425 |
return_value = _asyncio__swap_current_task_impl(module, loop, task); |
| 1426 |
|
| 1427 |
exit: |
| 1428 |
return return_value; |
| 1429 |
} |
| 1430 |
|
| 1431 |
PyDoc_STRVAR(_asyncio_current_task__doc__, |
| 1432 |
"current_task($module, /, loop=None)\n" |
| 1433 |
"--\n" |
| 1434 |
"\n" |
| 1435 |
"Return a currently executed task."); |
| 1436 |
|
| 1437 |
#define _ASYNCIO_CURRENT_TASK_METHODDEF \ |
| 1438 |
{"current_task", _PyCFunction_CAST(_asyncio_current_task), METH_FASTCALL|METH_KEYWORDS, _asyncio_current_task__doc__}, |
| 1439 |
|
| 1440 |
static PyObject * |
| 1441 |
_asyncio_current_task_impl(PyObject *module, PyObject *loop); |
| 1442 |
|
| 1443 |
static PyObject * |
| 1444 |
_asyncio_current_task(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
| 1445 |
{ |
| 1446 |
PyObject *return_value = NULL; |
| 1447 |
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
| 1448 |
|
| 1449 |
#define NUM_KEYWORDS 1 |
| 1450 |
static struct { |
| 1451 |
PyGC_Head _this_is_not_used; |
| 1452 |
PyObject_VAR_HEAD |
| 1453 |
PyObject *ob_item[NUM_KEYWORDS]; |
| 1454 |
} _kwtuple = { |
| 1455 |
.ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
| 1456 |
.ob_item = { &_Py_ID(loop), }, |
| 1457 |
}; |
| 1458 |
#undef NUM_KEYWORDS |
| 1459 |
#define KWTUPLE (&_kwtuple.ob_base.ob_base) |
| 1460 |
|
| 1461 |
#else // !Py_BUILD_CORE |
| 1462 |
# define KWTUPLE NULL |
| 1463 |
#endif // !Py_BUILD_CORE |
| 1464 |
|
| 1465 |
static const char * const _keywords[] = {"loop", NULL}; |
| 1466 |
static _PyArg_Parser _parser = { |
| 1467 |
.keywords = _keywords, |
| 1468 |
.fname = "current_task", |
| 1469 |
.kwtuple = KWTUPLE, |
| 1470 |
}; |
| 1471 |
#undef KWTUPLE |
| 1472 |
PyObject *argsbuf[1]; |
| 1473 |
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; |
| 1474 |
PyObject *loop = Py_None; |
| 1475 |
|
| 1476 |
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf); |
| 1477 |
if (!args) { |
| 1478 |
goto exit; |
| 1479 |
} |
| 1480 |
if (!noptargs) { |
| 1481 |
goto skip_optional_pos; |
| 1482 |
} |
| 1483 |
loop = args[0]; |
| 1484 |
skip_optional_pos: |
| 1485 |
return_value = _asyncio_current_task_impl(module, loop); |
| 1486 |
|
| 1487 |
exit: |
| 1488 |
return return_value; |
| 1489 |
} |
| 1490 |
/*[clinic end generated code: output=b26155080c82c472 input=a9049054013a1b77]*/ |