_asynciomodule.c.h 44 KB

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