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