Debian Codegraph @

Modules/_io/clinic/winconsoleio.c.h

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