winconsoleio.c.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468
  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. #if defined(HAVE_WINDOWS_CONSOLE_IO)
  9. PyDoc_STRVAR(_io__WindowsConsoleIO_close__doc__,
  10. "close($self, /)\n"
  11. "--\n"
  12. "\n"
  13. "Close the console object.\n"
  14. "\n"
  15. "A closed console object cannot be used for further I/O operations.\n"
  16. "close() may be called more than once without error.");
  17. #define _IO__WINDOWSCONSOLEIO_CLOSE_METHODDEF \
  18. {"close", _PyCFunction_CAST(_io__WindowsConsoleIO_close), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _io__WindowsConsoleIO_close__doc__},
  19. static PyObject *
  20. _io__WindowsConsoleIO_close_impl(winconsoleio *self, PyTypeObject *cls);
  21. static PyObject *
  22. _io__WindowsConsoleIO_close(winconsoleio *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  23. {
  24. if (nargs || (kwnames && PyTuple_GET_SIZE(kwnames))) {
  25. PyErr_SetString(PyExc_TypeError, "close() takes no arguments");
  26. return NULL;
  27. }
  28. return _io__WindowsConsoleIO_close_impl(self, cls);
  29. }
  30. #endif /* defined(HAVE_WINDOWS_CONSOLE_IO) */
  31. #if defined(HAVE_WINDOWS_CONSOLE_IO)
  32. PyDoc_STRVAR(_io__WindowsConsoleIO___init____doc__,
  33. "_WindowsConsoleIO(file, mode=\'r\', closefd=True, opener=None)\n"
  34. "--\n"
  35. "\n"
  36. "Open a console buffer by file descriptor.\n"
  37. "\n"
  38. "The mode can be \'rb\' (default), or \'wb\' for reading or writing bytes. All\n"
  39. "other mode characters will be ignored. Mode \'b\' will be assumed if it is\n"
  40. "omitted. The *opener* parameter is always ignored.");
  41. static int
  42. _io__WindowsConsoleIO___init___impl(winconsoleio *self, PyObject *nameobj,
  43. const char *mode, int closefd,
  44. PyObject *opener);
  45. static int
  46. _io__WindowsConsoleIO___init__(PyObject *self, PyObject *args, PyObject *kwargs)
  47. {
  48. int return_value = -1;
  49. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  50. #define NUM_KEYWORDS 4
  51. static struct {
  52. PyGC_Head _this_is_not_used;
  53. PyObject_VAR_HEAD
  54. PyObject *ob_item[NUM_KEYWORDS];
  55. } _kwtuple = {
  56. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  57. .ob_item = { &_Py_ID(file), &_Py_ID(mode), &_Py_ID(closefd), &_Py_ID(opener), },
  58. };
  59. #undef NUM_KEYWORDS
  60. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  61. #else // !Py_BUILD_CORE
  62. # define KWTUPLE NULL
  63. #endif // !Py_BUILD_CORE
  64. static const char * const _keywords[] = {"file", "mode", "closefd", "opener", NULL};
  65. static _PyArg_Parser _parser = {
  66. .keywords = _keywords,
  67. .fname = "_WindowsConsoleIO",
  68. .kwtuple = KWTUPLE,
  69. };
  70. #undef KWTUPLE
  71. PyObject *argsbuf[4];
  72. PyObject * const *fastargs;
  73. Py_ssize_t nargs = PyTuple_GET_SIZE(args);
  74. Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 1;
  75. PyObject *nameobj;
  76. const char *mode = "r";
  77. int closefd = 1;
  78. PyObject *opener = Py_None;
  79. fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 1, 4, 0, argsbuf);
  80. if (!fastargs) {
  81. goto exit;
  82. }
  83. nameobj = fastargs[0];
  84. if (!noptargs) {
  85. goto skip_optional_pos;
  86. }
  87. if (fastargs[1]) {
  88. if (!PyUnicode_Check(fastargs[1])) {
  89. _PyArg_BadArgument("_WindowsConsoleIO", "argument 'mode'", "str", fastargs[1]);
  90. goto exit;
  91. }
  92. Py_ssize_t mode_length;
  93. mode = PyUnicode_AsUTF8AndSize(fastargs[1], &mode_length);
  94. if (mode == NULL) {
  95. goto exit;
  96. }
  97. if (strlen(mode) != (size_t)mode_length) {
  98. PyErr_SetString(PyExc_ValueError, "embedded null character");
  99. goto exit;
  100. }
  101. if (!--noptargs) {
  102. goto skip_optional_pos;
  103. }
  104. }
  105. if (fastargs[2]) {
  106. closefd = PyObject_IsTrue(fastargs[2]);
  107. if (closefd < 0) {
  108. goto exit;
  109. }
  110. if (!--noptargs) {
  111. goto skip_optional_pos;
  112. }
  113. }
  114. opener = fastargs[3];
  115. skip_optional_pos:
  116. return_value = _io__WindowsConsoleIO___init___impl((winconsoleio *)self, nameobj, mode, closefd, opener);
  117. exit:
  118. return return_value;
  119. }
  120. #endif /* defined(HAVE_WINDOWS_CONSOLE_IO) */
  121. #if defined(HAVE_WINDOWS_CONSOLE_IO)
  122. PyDoc_STRVAR(_io__WindowsConsoleIO_fileno__doc__,
  123. "fileno($self, /)\n"
  124. "--\n"
  125. "\n"
  126. "Return the underlying file descriptor (an integer).");
  127. #define _IO__WINDOWSCONSOLEIO_FILENO_METHODDEF \
  128. {"fileno", (PyCFunction)_io__WindowsConsoleIO_fileno, METH_NOARGS, _io__WindowsConsoleIO_fileno__doc__},
  129. static PyObject *
  130. _io__WindowsConsoleIO_fileno_impl(winconsoleio *self);
  131. static PyObject *
  132. _io__WindowsConsoleIO_fileno(winconsoleio *self, PyObject *Py_UNUSED(ignored))
  133. {
  134. return _io__WindowsConsoleIO_fileno_impl(self);
  135. }
  136. #endif /* defined(HAVE_WINDOWS_CONSOLE_IO) */
  137. #if defined(HAVE_WINDOWS_CONSOLE_IO)
  138. PyDoc_STRVAR(_io__WindowsConsoleIO_readable__doc__,
  139. "readable($self, /)\n"
  140. "--\n"
  141. "\n"
  142. "True if console is an input buffer.");
  143. #define _IO__WINDOWSCONSOLEIO_READABLE_METHODDEF \
  144. {"readable", (PyCFunction)_io__WindowsConsoleIO_readable, METH_NOARGS, _io__WindowsConsoleIO_readable__doc__},
  145. static PyObject *
  146. _io__WindowsConsoleIO_readable_impl(winconsoleio *self);
  147. static PyObject *
  148. _io__WindowsConsoleIO_readable(winconsoleio *self, PyObject *Py_UNUSED(ignored))
  149. {
  150. return _io__WindowsConsoleIO_readable_impl(self);
  151. }
  152. #endif /* defined(HAVE_WINDOWS_CONSOLE_IO) */
  153. #if defined(HAVE_WINDOWS_CONSOLE_IO)
  154. PyDoc_STRVAR(_io__WindowsConsoleIO_writable__doc__,
  155. "writable($self, /)\n"
  156. "--\n"
  157. "\n"
  158. "True if console is an output buffer.");
  159. #define _IO__WINDOWSCONSOLEIO_WRITABLE_METHODDEF \
  160. {"writable", (PyCFunction)_io__WindowsConsoleIO_writable, METH_NOARGS, _io__WindowsConsoleIO_writable__doc__},
  161. static PyObject *
  162. _io__WindowsConsoleIO_writable_impl(winconsoleio *self);
  163. static PyObject *
  164. _io__WindowsConsoleIO_writable(winconsoleio *self, PyObject *Py_UNUSED(ignored))
  165. {
  166. return _io__WindowsConsoleIO_writable_impl(self);
  167. }
  168. #endif /* defined(HAVE_WINDOWS_CONSOLE_IO) */
  169. #if defined(HAVE_WINDOWS_CONSOLE_IO)
  170. PyDoc_STRVAR(_io__WindowsConsoleIO_readinto__doc__,
  171. "readinto($self, buffer, /)\n"
  172. "--\n"
  173. "\n"
  174. "Same as RawIOBase.readinto().");
  175. #define _IO__WINDOWSCONSOLEIO_READINTO_METHODDEF \
  176. {"readinto", _PyCFunction_CAST(_io__WindowsConsoleIO_readinto), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _io__WindowsConsoleIO_readinto__doc__},
  177. static PyObject *
  178. _io__WindowsConsoleIO_readinto_impl(winconsoleio *self, PyTypeObject *cls,
  179. Py_buffer *buffer);
  180. static PyObject *
  181. _io__WindowsConsoleIO_readinto(winconsoleio *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  182. {
  183. PyObject *return_value = NULL;
  184. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  185. # define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty)
  186. #else
  187. # define KWTUPLE NULL
  188. #endif
  189. static const char * const _keywords[] = {"", NULL};
  190. static _PyArg_Parser _parser = {
  191. .keywords = _keywords,
  192. .fname = "readinto",
  193. .kwtuple = KWTUPLE,
  194. };
  195. #undef KWTUPLE
  196. PyObject *argsbuf[1];
  197. Py_buffer buffer = {NULL, NULL};
  198. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
  199. if (!args) {
  200. goto exit;
  201. }
  202. if (PyObject_GetBuffer(args[0], &buffer, PyBUF_WRITABLE) < 0) {
  203. PyErr_Clear();
  204. _PyArg_BadArgument("readinto", "argument 1", "read-write bytes-like object", args[0]);
  205. goto exit;
  206. }
  207. if (!PyBuffer_IsContiguous(&buffer, 'C')) {
  208. _PyArg_BadArgument("readinto", "argument 1", "contiguous buffer", args[0]);
  209. goto exit;
  210. }
  211. return_value = _io__WindowsConsoleIO_readinto_impl(self, cls, &buffer);
  212. exit:
  213. /* Cleanup for buffer */
  214. if (buffer.obj) {
  215. PyBuffer_Release(&buffer);
  216. }
  217. return return_value;
  218. }
  219. #endif /* defined(HAVE_WINDOWS_CONSOLE_IO) */
  220. #if defined(HAVE_WINDOWS_CONSOLE_IO)
  221. PyDoc_STRVAR(_io__WindowsConsoleIO_readall__doc__,
  222. "readall($self, /)\n"
  223. "--\n"
  224. "\n"
  225. "Read all data from the console, returned as bytes.\n"
  226. "\n"
  227. "Return an empty bytes object at EOF.");
  228. #define _IO__WINDOWSCONSOLEIO_READALL_METHODDEF \
  229. {"readall", (PyCFunction)_io__WindowsConsoleIO_readall, METH_NOARGS, _io__WindowsConsoleIO_readall__doc__},
  230. static PyObject *
  231. _io__WindowsConsoleIO_readall_impl(winconsoleio *self);
  232. static PyObject *
  233. _io__WindowsConsoleIO_readall(winconsoleio *self, PyObject *Py_UNUSED(ignored))
  234. {
  235. return _io__WindowsConsoleIO_readall_impl(self);
  236. }
  237. #endif /* defined(HAVE_WINDOWS_CONSOLE_IO) */
  238. #if defined(HAVE_WINDOWS_CONSOLE_IO)
  239. PyDoc_STRVAR(_io__WindowsConsoleIO_read__doc__,
  240. "read($self, size=-1, /)\n"
  241. "--\n"
  242. "\n"
  243. "Read at most size bytes, returned as bytes.\n"
  244. "\n"
  245. "Only makes one system call when size is a positive integer,\n"
  246. "so less data may be returned than requested.\n"
  247. "Return an empty bytes object at EOF.");
  248. #define _IO__WINDOWSCONSOLEIO_READ_METHODDEF \
  249. {"read", _PyCFunction_CAST(_io__WindowsConsoleIO_read), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _io__WindowsConsoleIO_read__doc__},
  250. static PyObject *
  251. _io__WindowsConsoleIO_read_impl(winconsoleio *self, PyTypeObject *cls,
  252. Py_ssize_t size);
  253. static PyObject *
  254. _io__WindowsConsoleIO_read(winconsoleio *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  255. {
  256. PyObject *return_value = NULL;
  257. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  258. # define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty)
  259. #else
  260. # define KWTUPLE NULL
  261. #endif
  262. static const char * const _keywords[] = {"", NULL};
  263. static _PyArg_Parser _parser = {
  264. .keywords = _keywords,
  265. .fname = "read",
  266. .kwtuple = KWTUPLE,
  267. };
  268. #undef KWTUPLE
  269. PyObject *argsbuf[1];
  270. Py_ssize_t size = -1;
  271. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
  272. if (!args) {
  273. goto exit;
  274. }
  275. if (nargs < 1) {
  276. goto skip_optional_posonly;
  277. }
  278. if (!_Py_convert_optional_to_ssize_t(args[0], &size)) {
  279. goto exit;
  280. }
  281. skip_optional_posonly:
  282. return_value = _io__WindowsConsoleIO_read_impl(self, cls, size);
  283. exit:
  284. return return_value;
  285. }
  286. #endif /* defined(HAVE_WINDOWS_CONSOLE_IO) */
  287. #if defined(HAVE_WINDOWS_CONSOLE_IO)
  288. PyDoc_STRVAR(_io__WindowsConsoleIO_write__doc__,
  289. "write($self, b, /)\n"
  290. "--\n"
  291. "\n"
  292. "Write buffer b to file, return number of bytes written.\n"
  293. "\n"
  294. "Only makes one system call, so not all of the data may be written.\n"
  295. "The number of bytes actually written is returned.");
  296. #define _IO__WINDOWSCONSOLEIO_WRITE_METHODDEF \
  297. {"write", _PyCFunction_CAST(_io__WindowsConsoleIO_write), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _io__WindowsConsoleIO_write__doc__},
  298. static PyObject *
  299. _io__WindowsConsoleIO_write_impl(winconsoleio *self, PyTypeObject *cls,
  300. Py_buffer *b);
  301. static PyObject *
  302. _io__WindowsConsoleIO_write(winconsoleio *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  303. {
  304. PyObject *return_value = NULL;
  305. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  306. # define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty)
  307. #else
  308. # define KWTUPLE NULL
  309. #endif
  310. static const char * const _keywords[] = {"", NULL};
  311. static _PyArg_Parser _parser = {
  312. .keywords = _keywords,
  313. .fname = "write",
  314. .kwtuple = KWTUPLE,
  315. };
  316. #undef KWTUPLE
  317. PyObject *argsbuf[1];
  318. Py_buffer b = {NULL, NULL};
  319. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
  320. if (!args) {
  321. goto exit;
  322. }
  323. if (PyObject_GetBuffer(args[0], &b, PyBUF_SIMPLE) != 0) {
  324. goto exit;
  325. }
  326. if (!PyBuffer_IsContiguous(&b, 'C')) {
  327. _PyArg_BadArgument("write", "argument 1", "contiguous buffer", args[0]);
  328. goto exit;
  329. }
  330. return_value = _io__WindowsConsoleIO_write_impl(self, cls, &b);
  331. exit:
  332. /* Cleanup for b */
  333. if (b.obj) {
  334. PyBuffer_Release(&b);
  335. }
  336. return return_value;
  337. }
  338. #endif /* defined(HAVE_WINDOWS_CONSOLE_IO) */
  339. #if defined(HAVE_WINDOWS_CONSOLE_IO)
  340. PyDoc_STRVAR(_io__WindowsConsoleIO_isatty__doc__,
  341. "isatty($self, /)\n"
  342. "--\n"
  343. "\n"
  344. "Always True.");
  345. #define _IO__WINDOWSCONSOLEIO_ISATTY_METHODDEF \
  346. {"isatty", (PyCFunction)_io__WindowsConsoleIO_isatty, METH_NOARGS, _io__WindowsConsoleIO_isatty__doc__},
  347. static PyObject *
  348. _io__WindowsConsoleIO_isatty_impl(winconsoleio *self);
  349. static PyObject *
  350. _io__WindowsConsoleIO_isatty(winconsoleio *self, PyObject *Py_UNUSED(ignored))
  351. {
  352. return _io__WindowsConsoleIO_isatty_impl(self);
  353. }
  354. #endif /* defined(HAVE_WINDOWS_CONSOLE_IO) */
  355. #ifndef _IO__WINDOWSCONSOLEIO_CLOSE_METHODDEF
  356. #define _IO__WINDOWSCONSOLEIO_CLOSE_METHODDEF
  357. #endif /* !defined(_IO__WINDOWSCONSOLEIO_CLOSE_METHODDEF) */
  358. #ifndef _IO__WINDOWSCONSOLEIO_FILENO_METHODDEF
  359. #define _IO__WINDOWSCONSOLEIO_FILENO_METHODDEF
  360. #endif /* !defined(_IO__WINDOWSCONSOLEIO_FILENO_METHODDEF) */
  361. #ifndef _IO__WINDOWSCONSOLEIO_READABLE_METHODDEF
  362. #define _IO__WINDOWSCONSOLEIO_READABLE_METHODDEF
  363. #endif /* !defined(_IO__WINDOWSCONSOLEIO_READABLE_METHODDEF) */
  364. #ifndef _IO__WINDOWSCONSOLEIO_WRITABLE_METHODDEF
  365. #define _IO__WINDOWSCONSOLEIO_WRITABLE_METHODDEF
  366. #endif /* !defined(_IO__WINDOWSCONSOLEIO_WRITABLE_METHODDEF) */
  367. #ifndef _IO__WINDOWSCONSOLEIO_READINTO_METHODDEF
  368. #define _IO__WINDOWSCONSOLEIO_READINTO_METHODDEF
  369. #endif /* !defined(_IO__WINDOWSCONSOLEIO_READINTO_METHODDEF) */
  370. #ifndef _IO__WINDOWSCONSOLEIO_READALL_METHODDEF
  371. #define _IO__WINDOWSCONSOLEIO_READALL_METHODDEF
  372. #endif /* !defined(_IO__WINDOWSCONSOLEIO_READALL_METHODDEF) */
  373. #ifndef _IO__WINDOWSCONSOLEIO_READ_METHODDEF
  374. #define _IO__WINDOWSCONSOLEIO_READ_METHODDEF
  375. #endif /* !defined(_IO__WINDOWSCONSOLEIO_READ_METHODDEF) */
  376. #ifndef _IO__WINDOWSCONSOLEIO_WRITE_METHODDEF
  377. #define _IO__WINDOWSCONSOLEIO_WRITE_METHODDEF
  378. #endif /* !defined(_IO__WINDOWSCONSOLEIO_WRITE_METHODDEF) */
  379. #ifndef _IO__WINDOWSCONSOLEIO_ISATTY_METHODDEF
  380. #define _IO__WINDOWSCONSOLEIO_ISATTY_METHODDEF
  381. #endif /* !defined(_IO__WINDOWSCONSOLEIO_ISATTY_METHODDEF) */
  382. /*[clinic end generated code: output=9a9f95a1b52c95f9 input=a9049054013a1b77]*/