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