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