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