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  PyDoc_STRVAR(_io__TextIOBase_detach__doc__,
      12  "detach($self, /)\n"
      13  "--\n"
      14  "\n"
      15  "Separate the underlying buffer from the TextIOBase and return it.\n"
      16  "\n"
      17  "After the underlying buffer has been detached, the TextIO is in an unusable state.");
      18  
      19  #define _IO__TEXTIOBASE_DETACH_METHODDEF    \
      20      {"detach", _PyCFunction_CAST(_io__TextIOBase_detach), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _io__TextIOBase_detach__doc__},
      21  
      22  static PyObject *
      23  _io__TextIOBase_detach_impl(PyObject *self, PyTypeObject *cls);
      24  
      25  static PyObject *
      26  _io__TextIOBase_detach(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
      27  {
      28      if (nargs) {
      29          PyErr_SetString(PyExc_TypeError, "detach() takes no arguments");
      30          return NULL;
      31      }
      32      return _io__TextIOBase_detach_impl(self, cls);
      33  }
      34  
      35  PyDoc_STRVAR(_io__TextIOBase_read__doc__,
      36  "read($self, size=-1, /)\n"
      37  "--\n"
      38  "\n"
      39  "Read at most size characters from stream.\n"
      40  "\n"
      41  "Read from underlying buffer until we have size characters or we hit EOF.\n"
      42  "If size is negative or omitted, read until EOF.");
      43  
      44  #define _IO__TEXTIOBASE_READ_METHODDEF    \
      45      {"read", _PyCFunction_CAST(_io__TextIOBase_read), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _io__TextIOBase_read__doc__},
      46  
      47  static PyObject *
      48  _io__TextIOBase_read_impl(PyObject *self, PyTypeObject *cls,
      49                            int Py_UNUSED(size));
      50  
      51  static PyObject *
      52  _io__TextIOBase_read(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
      53  {
      54      PyObject *return_value = NULL;
      55      #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
      56      #  define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty)
      57      #else
      58      #  define KWTUPLE NULL
      59      #endif
      60  
      61      static const char * const _keywords[] = {"", NULL};
      62      static _PyArg_Parser _parser = {
      63          .keywords = _keywords,
      64          .fname = "read",
      65          .kwtuple = KWTUPLE,
      66      };
      67      #undef KWTUPLE
      68      PyObject *argsbuf[1];
      69      int size = -1;
      70  
      71      args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
      72      if (!args) {
      73          goto exit;
      74      }
      75      if (nargs < 1) {
      76          goto skip_optional_posonly;
      77      }
      78      size = _PyLong_AsInt(args[0]);
      79      if (size == -1 && PyErr_Occurred()) {
      80          goto exit;
      81      }
      82  skip_optional_posonly:
      83      return_value = _io__TextIOBase_read_impl(self, cls, size);
      84  
      85  exit:
      86      return return_value;
      87  }
      88  
      89  PyDoc_STRVAR(_io__TextIOBase_readline__doc__,
      90  "readline($self, size=-1, /)\n"
      91  "--\n"
      92  "\n"
      93  "Read until newline or EOF.\n"
      94  "\n"
      95  "Return an empty string if EOF is hit immediately.\n"
      96  "If size is specified, at most size characters will be read.");
      97  
      98  #define _IO__TEXTIOBASE_READLINE_METHODDEF    \
      99      {"readline", _PyCFunction_CAST(_io__TextIOBase_readline), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _io__TextIOBase_readline__doc__},
     100  
     101  static PyObject *
     102  _io__TextIOBase_readline_impl(PyObject *self, PyTypeObject *cls,
     103                                int Py_UNUSED(size));
     104  
     105  static PyObject *
     106  _io__TextIOBase_readline(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
     107  {
     108      PyObject *return_value = NULL;
     109      #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
     110      #  define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty)
     111      #else
     112      #  define KWTUPLE NULL
     113      #endif
     114  
     115      static const char * const _keywords[] = {"", NULL};
     116      static _PyArg_Parser _parser = {
     117          .keywords = _keywords,
     118          .fname = "readline",
     119          .kwtuple = KWTUPLE,
     120      };
     121      #undef KWTUPLE
     122      PyObject *argsbuf[1];
     123      int size = -1;
     124  
     125      args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
     126      if (!args) {
     127          goto exit;
     128      }
     129      if (nargs < 1) {
     130          goto skip_optional_posonly;
     131      }
     132      size = _PyLong_AsInt(args[0]);
     133      if (size == -1 && PyErr_Occurred()) {
     134          goto exit;
     135      }
     136  skip_optional_posonly:
     137      return_value = _io__TextIOBase_readline_impl(self, cls, size);
     138  
     139  exit:
     140      return return_value;
     141  }
     142  
     143  PyDoc_STRVAR(_io__TextIOBase_write__doc__,
     144  "write($self, s, /)\n"
     145  "--\n"
     146  "\n"
     147  "Write string s to stream.\n"
     148  "\n"
     149  "Return the number of characters written\n"
     150  "(which is always equal to the length of the string).");
     151  
     152  #define _IO__TEXTIOBASE_WRITE_METHODDEF    \
     153      {"write", _PyCFunction_CAST(_io__TextIOBase_write), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _io__TextIOBase_write__doc__},
     154  
     155  static PyObject *
     156  _io__TextIOBase_write_impl(PyObject *self, PyTypeObject *cls,
     157                             const char *Py_UNUSED(s));
     158  
     159  static PyObject *
     160  _io__TextIOBase_write(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
     161  {
     162      PyObject *return_value = NULL;
     163      #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
     164      #  define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty)
     165      #else
     166      #  define KWTUPLE NULL
     167      #endif
     168  
     169      static const char * const _keywords[] = {"", NULL};
     170      static _PyArg_Parser _parser = {
     171          .keywords = _keywords,
     172          .fname = "write",
     173          .kwtuple = KWTUPLE,
     174      };
     175      #undef KWTUPLE
     176      PyObject *argsbuf[1];
     177      const char *s;
     178  
     179      args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
     180      if (!args) {
     181          goto exit;
     182      }
     183      if (!PyUnicode_Check(args[0])) {
     184          _PyArg_BadArgument("write", "argument 1", "str", args[0]);
     185          goto exit;
     186      }
     187      Py_ssize_t s_length;
     188      s = PyUnicode_AsUTF8AndSize(args[0], &s_length);
     189      if (s == NULL) {
     190          goto exit;
     191      }
     192      if (strlen(s) != (size_t)s_length) {
     193          PyErr_SetString(PyExc_ValueError, "embedded null character");
     194          goto exit;
     195      }
     196      return_value = _io__TextIOBase_write_impl(self, cls, s);
     197  
     198  exit:
     199      return return_value;
     200  }
     201  
     202  PyDoc_STRVAR(_io_IncrementalNewlineDecoder___init____doc__,
     203  "IncrementalNewlineDecoder(decoder, translate, errors=\'strict\')\n"
     204  "--\n"
     205  "\n"
     206  "Codec used when reading a file in universal newlines mode.\n"
     207  "\n"
     208  "It wraps another incremental decoder, translating \\r\\n and \\r into \\n.\n"
     209  "It also records the types of newlines encountered.  When used with\n"
     210  "translate=False, it ensures that the newline sequence is returned in\n"
     211  "one piece. When used with decoder=None, it expects unicode strings as\n"
     212  "decode input and translates newlines without first invoking an external\n"
     213  "decoder.");
     214  
     215  static int
     216  _io_IncrementalNewlineDecoder___init___impl(nldecoder_object *self,
     217                                              PyObject *decoder, int translate,
     218                                              PyObject *errors);
     219  
     220  static int
     221  _io_IncrementalNewlineDecoder___init__(PyObject *self, PyObject *args, PyObject *kwargs)
     222  {
     223      int return_value = -1;
     224      #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
     225  
     226      #define NUM_KEYWORDS 3
     227      static struct {
     228          PyGC_Head _this_is_not_used;
     229          PyObject_VAR_HEAD
     230          PyObject *ob_item[NUM_KEYWORDS];
     231      } _kwtuple = {
     232          .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
     233          .ob_item = { &_Py_ID(decoder), &_Py_ID(translate), &_Py_ID(errors), },
     234      };
     235      #undef NUM_KEYWORDS
     236      #define KWTUPLE (&_kwtuple.ob_base.ob_base)
     237  
     238      #else  // !Py_BUILD_CORE
     239      #  define KWTUPLE NULL
     240      #endif  // !Py_BUILD_CORE
     241  
     242      static const char * const _keywords[] = {"decoder", "translate", "errors", NULL};
     243      static _PyArg_Parser _parser = {
     244          .keywords = _keywords,
     245          .fname = "IncrementalNewlineDecoder",
     246          .kwtuple = KWTUPLE,
     247      };
     248      #undef KWTUPLE
     249      PyObject *argsbuf[3];
     250      PyObject * const *fastargs;
     251      Py_ssize_t nargs = PyTuple_GET_SIZE(args);
     252      Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 2;
     253      PyObject *decoder;
     254      int translate;
     255      PyObject *errors = NULL;
     256  
     257      fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 2, 3, 0, argsbuf);
     258      if (!fastargs) {
     259          goto exit;
     260      }
     261      decoder = fastargs[0];
     262      translate = PyObject_IsTrue(fastargs[1]);
     263      if (translate < 0) {
     264          goto exit;
     265      }
     266      if (!noptargs) {
     267          goto skip_optional_pos;
     268      }
     269      errors = fastargs[2];
     270  skip_optional_pos:
     271      return_value = _io_IncrementalNewlineDecoder___init___impl((nldecoder_object *)self, decoder, translate, errors);
     272  
     273  exit:
     274      return return_value;
     275  }
     276  
     277  PyDoc_STRVAR(_io_IncrementalNewlineDecoder_decode__doc__,
     278  "decode($self, /, input, final=False)\n"
     279  "--\n"
     280  "\n");
     281  
     282  #define _IO_INCREMENTALNEWLINEDECODER_DECODE_METHODDEF    \
     283      {"decode", _PyCFunction_CAST(_io_IncrementalNewlineDecoder_decode), METH_FASTCALL|METH_KEYWORDS, _io_IncrementalNewlineDecoder_decode__doc__},
     284  
     285  static PyObject *
     286  _io_IncrementalNewlineDecoder_decode_impl(nldecoder_object *self,
     287                                            PyObject *input, int final);
     288  
     289  static PyObject *
     290  _io_IncrementalNewlineDecoder_decode(nldecoder_object *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
     291  {
     292      PyObject *return_value = NULL;
     293      #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
     294  
     295      #define NUM_KEYWORDS 2
     296      static struct {
     297          PyGC_Head _this_is_not_used;
     298          PyObject_VAR_HEAD
     299          PyObject *ob_item[NUM_KEYWORDS];
     300      } _kwtuple = {
     301          .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
     302          .ob_item = { &_Py_ID(input), &_Py_ID(final), },
     303      };
     304      #undef NUM_KEYWORDS
     305      #define KWTUPLE (&_kwtuple.ob_base.ob_base)
     306  
     307      #else  // !Py_BUILD_CORE
     308      #  define KWTUPLE NULL
     309      #endif  // !Py_BUILD_CORE
     310  
     311      static const char * const _keywords[] = {"input", "final", NULL};
     312      static _PyArg_Parser _parser = {
     313          .keywords = _keywords,
     314          .fname = "decode",
     315          .kwtuple = KWTUPLE,
     316      };
     317      #undef KWTUPLE
     318      PyObject *argsbuf[2];
     319      Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
     320      PyObject *input;
     321      int final = 0;
     322  
     323      args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf);
     324      if (!args) {
     325          goto exit;
     326      }
     327      input = args[0];
     328      if (!noptargs) {
     329          goto skip_optional_pos;
     330      }
     331      final = PyObject_IsTrue(args[1]);
     332      if (final < 0) {
     333          goto exit;
     334      }
     335  skip_optional_pos:
     336      return_value = _io_IncrementalNewlineDecoder_decode_impl(self, input, final);
     337  
     338  exit:
     339      return return_value;
     340  }
     341  
     342  PyDoc_STRVAR(_io_IncrementalNewlineDecoder_getstate__doc__,
     343  "getstate($self, /)\n"
     344  "--\n"
     345  "\n");
     346  
     347  #define _IO_INCREMENTALNEWLINEDECODER_GETSTATE_METHODDEF    \
     348      {"getstate", (PyCFunction)_io_IncrementalNewlineDecoder_getstate, METH_NOARGS, _io_IncrementalNewlineDecoder_getstate__doc__},
     349  
     350  static PyObject *
     351  _io_IncrementalNewlineDecoder_getstate_impl(nldecoder_object *self);
     352  
     353  static PyObject *
     354  _io_IncrementalNewlineDecoder_getstate(nldecoder_object *self, PyObject *Py_UNUSED(ignored))
     355  {
     356      return _io_IncrementalNewlineDecoder_getstate_impl(self);
     357  }
     358  
     359  PyDoc_STRVAR(_io_IncrementalNewlineDecoder_setstate__doc__,
     360  "setstate($self, state, /)\n"
     361  "--\n"
     362  "\n");
     363  
     364  #define _IO_INCREMENTALNEWLINEDECODER_SETSTATE_METHODDEF    \
     365      {"setstate", (PyCFunction)_io_IncrementalNewlineDecoder_setstate, METH_O, _io_IncrementalNewlineDecoder_setstate__doc__},
     366  
     367  PyDoc_STRVAR(_io_IncrementalNewlineDecoder_reset__doc__,
     368  "reset($self, /)\n"
     369  "--\n"
     370  "\n");
     371  
     372  #define _IO_INCREMENTALNEWLINEDECODER_RESET_METHODDEF    \
     373      {"reset", (PyCFunction)_io_IncrementalNewlineDecoder_reset, METH_NOARGS, _io_IncrementalNewlineDecoder_reset__doc__},
     374  
     375  static PyObject *
     376  _io_IncrementalNewlineDecoder_reset_impl(nldecoder_object *self);
     377  
     378  static PyObject *
     379  _io_IncrementalNewlineDecoder_reset(nldecoder_object *self, PyObject *Py_UNUSED(ignored))
     380  {
     381      return _io_IncrementalNewlineDecoder_reset_impl(self);
     382  }
     383  
     384  PyDoc_STRVAR(_io_TextIOWrapper___init____doc__,
     385  "TextIOWrapper(buffer, encoding=None, errors=None, newline=None,\n"
     386  "              line_buffering=False, write_through=False)\n"
     387  "--\n"
     388  "\n"
     389  "Character and line based layer over a BufferedIOBase object, buffer.\n"
     390  "\n"
     391  "encoding gives the name of the encoding that the stream will be\n"
     392  "decoded or encoded with. It defaults to locale.getencoding().\n"
     393  "\n"
     394  "errors determines the strictness of encoding and decoding (see\n"
     395  "help(codecs.Codec) or the documentation for codecs.register) and\n"
     396  "defaults to \"strict\".\n"
     397  "\n"
     398  "newline controls how line endings are handled. It can be None, \'\',\n"
     399  "\'\\n\', \'\\r\', and \'\\r\\n\'.  It works as follows:\n"
     400  "\n"
     401  "* On input, if newline is None, universal newlines mode is\n"
     402  "  enabled. Lines in the input can end in \'\\n\', \'\\r\', or \'\\r\\n\', and\n"
     403  "  these are translated into \'\\n\' before being returned to the\n"
     404  "  caller. If it is \'\', universal newline mode is enabled, but line\n"
     405  "  endings are returned to the caller untranslated. If it has any of\n"
     406  "  the other legal values, input lines are only terminated by the given\n"
     407  "  string, and the line ending is returned to the caller untranslated.\n"
     408  "\n"
     409  "* On output, if newline is None, any \'\\n\' characters written are\n"
     410  "  translated to the system default line separator, os.linesep. If\n"
     411  "  newline is \'\' or \'\\n\', no translation takes place. If newline is any\n"
     412  "  of the other legal values, any \'\\n\' characters written are translated\n"
     413  "  to the given string.\n"
     414  "\n"
     415  "If line_buffering is True, a call to flush is implied when a call to\n"
     416  "write contains a newline character.");
     417  
     418  static int
     419  _io_TextIOWrapper___init___impl(textio *self, PyObject *buffer,
     420                                  const char *encoding, PyObject *errors,
     421                                  const char *newline, int line_buffering,
     422                                  int write_through);
     423  
     424  static int
     425  _io_TextIOWrapper___init__(PyObject *self, PyObject *args, PyObject *kwargs)
     426  {
     427      int return_value = -1;
     428      #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
     429  
     430      #define NUM_KEYWORDS 6
     431      static struct {
     432          PyGC_Head _this_is_not_used;
     433          PyObject_VAR_HEAD
     434          PyObject *ob_item[NUM_KEYWORDS];
     435      } _kwtuple = {
     436          .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
     437          .ob_item = { &_Py_ID(buffer), &_Py_ID(encoding), &_Py_ID(errors), &_Py_ID(newline), &_Py_ID(line_buffering), &_Py_ID(write_through), },
     438      };
     439      #undef NUM_KEYWORDS
     440      #define KWTUPLE (&_kwtuple.ob_base.ob_base)
     441  
     442      #else  // !Py_BUILD_CORE
     443      #  define KWTUPLE NULL
     444      #endif  // !Py_BUILD_CORE
     445  
     446      static const char * const _keywords[] = {"buffer", "encoding", "errors", "newline", "line_buffering", "write_through", NULL};
     447      static _PyArg_Parser _parser = {
     448          .keywords = _keywords,
     449          .fname = "TextIOWrapper",
     450          .kwtuple = KWTUPLE,
     451      };
     452      #undef KWTUPLE
     453      PyObject *argsbuf[6];
     454      PyObject * const *fastargs;
     455      Py_ssize_t nargs = PyTuple_GET_SIZE(args);
     456      Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 1;
     457      PyObject *buffer;
     458      const char *encoding = NULL;
     459      PyObject *errors = Py_None;
     460      const char *newline = NULL;
     461      int line_buffering = 0;
     462      int write_through = 0;
     463  
     464      fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 1, 6, 0, argsbuf);
     465      if (!fastargs) {
     466          goto exit;
     467      }
     468      buffer = fastargs[0];
     469      if (!noptargs) {
     470          goto skip_optional_pos;
     471      }
     472      if (fastargs[1]) {
     473          if (fastargs[1] == Py_None) {
     474              encoding = NULL;
     475          }
     476          else if (PyUnicode_Check(fastargs[1])) {
     477              Py_ssize_t encoding_length;
     478              encoding = PyUnicode_AsUTF8AndSize(fastargs[1], &encoding_length);
     479              if (encoding == NULL) {
     480                  goto exit;
     481              }
     482              if (strlen(encoding) != (size_t)encoding_length) {
     483                  PyErr_SetString(PyExc_ValueError, "embedded null character");
     484                  goto exit;
     485              }
     486          }
     487          else {
     488              _PyArg_BadArgument("TextIOWrapper", "argument 'encoding'", "str or None", fastargs[1]);
     489              goto exit;
     490          }
     491          if (!--noptargs) {
     492              goto skip_optional_pos;
     493          }
     494      }
     495      if (fastargs[2]) {
     496          errors = fastargs[2];
     497          if (!--noptargs) {
     498              goto skip_optional_pos;
     499          }
     500      }
     501      if (fastargs[3]) {
     502          if (fastargs[3] == Py_None) {
     503              newline = NULL;
     504          }
     505          else if (PyUnicode_Check(fastargs[3])) {
     506              Py_ssize_t newline_length;
     507              newline = PyUnicode_AsUTF8AndSize(fastargs[3], &newline_length);
     508              if (newline == NULL) {
     509                  goto exit;
     510              }
     511              if (strlen(newline) != (size_t)newline_length) {
     512                  PyErr_SetString(PyExc_ValueError, "embedded null character");
     513                  goto exit;
     514              }
     515          }
     516          else {
     517              _PyArg_BadArgument("TextIOWrapper", "argument 'newline'", "str or None", fastargs[3]);
     518              goto exit;
     519          }
     520          if (!--noptargs) {
     521              goto skip_optional_pos;
     522          }
     523      }
     524      if (fastargs[4]) {
     525          line_buffering = PyObject_IsTrue(fastargs[4]);
     526          if (line_buffering < 0) {
     527              goto exit;
     528          }
     529          if (!--noptargs) {
     530              goto skip_optional_pos;
     531          }
     532      }
     533      write_through = PyObject_IsTrue(fastargs[5]);
     534      if (write_through < 0) {
     535          goto exit;
     536      }
     537  skip_optional_pos:
     538      return_value = _io_TextIOWrapper___init___impl((textio *)self, buffer, encoding, errors, newline, line_buffering, write_through);
     539  
     540  exit:
     541      return return_value;
     542  }
     543  
     544  PyDoc_STRVAR(_io_TextIOWrapper_reconfigure__doc__,
     545  "reconfigure($self, /, *, encoding=None, errors=None, newline=None,\n"
     546  "            line_buffering=None, write_through=None)\n"
     547  "--\n"
     548  "\n"
     549  "Reconfigure the text stream with new parameters.\n"
     550  "\n"
     551  "This also does an implicit stream flush.");
     552  
     553  #define _IO_TEXTIOWRAPPER_RECONFIGURE_METHODDEF    \
     554      {"reconfigure", _PyCFunction_CAST(_io_TextIOWrapper_reconfigure), METH_FASTCALL|METH_KEYWORDS, _io_TextIOWrapper_reconfigure__doc__},
     555  
     556  static PyObject *
     557  _io_TextIOWrapper_reconfigure_impl(textio *self, PyObject *encoding,
     558                                     PyObject *errors, PyObject *newline_obj,
     559                                     PyObject *line_buffering_obj,
     560                                     PyObject *write_through_obj);
     561  
     562  static PyObject *
     563  _io_TextIOWrapper_reconfigure(textio *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
     564  {
     565      PyObject *return_value = NULL;
     566      #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
     567  
     568      #define NUM_KEYWORDS 5
     569      static struct {
     570          PyGC_Head _this_is_not_used;
     571          PyObject_VAR_HEAD
     572          PyObject *ob_item[NUM_KEYWORDS];
     573      } _kwtuple = {
     574          .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
     575          .ob_item = { &_Py_ID(encoding), &_Py_ID(errors), &_Py_ID(newline), &_Py_ID(line_buffering), &_Py_ID(write_through), },
     576      };
     577      #undef NUM_KEYWORDS
     578      #define KWTUPLE (&_kwtuple.ob_base.ob_base)
     579  
     580      #else  // !Py_BUILD_CORE
     581      #  define KWTUPLE NULL
     582      #endif  // !Py_BUILD_CORE
     583  
     584      static const char * const _keywords[] = {"encoding", "errors", "newline", "line_buffering", "write_through", NULL};
     585      static _PyArg_Parser _parser = {
     586          .keywords = _keywords,
     587          .fname = "reconfigure",
     588          .kwtuple = KWTUPLE,
     589      };
     590      #undef KWTUPLE
     591      PyObject *argsbuf[5];
     592      Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
     593      PyObject *encoding = Py_None;
     594      PyObject *errors = Py_None;
     595      PyObject *newline_obj = NULL;
     596      PyObject *line_buffering_obj = Py_None;
     597      PyObject *write_through_obj = Py_None;
     598  
     599      args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf);
     600      if (!args) {
     601          goto exit;
     602      }
     603      if (!noptargs) {
     604          goto skip_optional_kwonly;
     605      }
     606      if (args[0]) {
     607          encoding = args[0];
     608          if (!--noptargs) {
     609              goto skip_optional_kwonly;
     610          }
     611      }
     612      if (args[1]) {
     613          errors = args[1];
     614          if (!--noptargs) {
     615              goto skip_optional_kwonly;
     616          }
     617      }
     618      if (args[2]) {
     619          newline_obj = args[2];
     620          if (!--noptargs) {
     621              goto skip_optional_kwonly;
     622          }
     623      }
     624      if (args[3]) {
     625          line_buffering_obj = args[3];
     626          if (!--noptargs) {
     627              goto skip_optional_kwonly;
     628          }
     629      }
     630      write_through_obj = args[4];
     631  skip_optional_kwonly:
     632      return_value = _io_TextIOWrapper_reconfigure_impl(self, encoding, errors, newline_obj, line_buffering_obj, write_through_obj);
     633  
     634  exit:
     635      return return_value;
     636  }
     637  
     638  PyDoc_STRVAR(_io_TextIOWrapper_detach__doc__,
     639  "detach($self, /)\n"
     640  "--\n"
     641  "\n");
     642  
     643  #define _IO_TEXTIOWRAPPER_DETACH_METHODDEF    \
     644      {"detach", (PyCFunction)_io_TextIOWrapper_detach, METH_NOARGS, _io_TextIOWrapper_detach__doc__},
     645  
     646  static PyObject *
     647  _io_TextIOWrapper_detach_impl(textio *self);
     648  
     649  static PyObject *
     650  _io_TextIOWrapper_detach(textio *self, PyObject *Py_UNUSED(ignored))
     651  {
     652      return _io_TextIOWrapper_detach_impl(self);
     653  }
     654  
     655  PyDoc_STRVAR(_io_TextIOWrapper_write__doc__,
     656  "write($self, text, /)\n"
     657  "--\n"
     658  "\n");
     659  
     660  #define _IO_TEXTIOWRAPPER_WRITE_METHODDEF    \
     661      {"write", (PyCFunction)_io_TextIOWrapper_write, METH_O, _io_TextIOWrapper_write__doc__},
     662  
     663  static PyObject *
     664  _io_TextIOWrapper_write_impl(textio *self, PyObject *text);
     665  
     666  static PyObject *
     667  _io_TextIOWrapper_write(textio *self, PyObject *arg)
     668  {
     669      PyObject *return_value = NULL;
     670      PyObject *text;
     671  
     672      if (!PyUnicode_Check(arg)) {
     673          _PyArg_BadArgument("write", "argument", "str", arg);
     674          goto exit;
     675      }
     676      if (PyUnicode_READY(arg) == -1) {
     677          goto exit;
     678      }
     679      text = arg;
     680      return_value = _io_TextIOWrapper_write_impl(self, text);
     681  
     682  exit:
     683      return return_value;
     684  }
     685  
     686  PyDoc_STRVAR(_io_TextIOWrapper_read__doc__,
     687  "read($self, size=-1, /)\n"
     688  "--\n"
     689  "\n");
     690  
     691  #define _IO_TEXTIOWRAPPER_READ_METHODDEF    \
     692      {"read", _PyCFunction_CAST(_io_TextIOWrapper_read), METH_FASTCALL, _io_TextIOWrapper_read__doc__},
     693  
     694  static PyObject *
     695  _io_TextIOWrapper_read_impl(textio *self, Py_ssize_t n);
     696  
     697  static PyObject *
     698  _io_TextIOWrapper_read(textio *self, PyObject *const *args, Py_ssize_t nargs)
     699  {
     700      PyObject *return_value = NULL;
     701      Py_ssize_t n = -1;
     702  
     703      if (!_PyArg_CheckPositional("read", nargs, 0, 1)) {
     704          goto exit;
     705      }
     706      if (nargs < 1) {
     707          goto skip_optional;
     708      }
     709      if (!_Py_convert_optional_to_ssize_t(args[0], &n)) {
     710          goto exit;
     711      }
     712  skip_optional:
     713      return_value = _io_TextIOWrapper_read_impl(self, n);
     714  
     715  exit:
     716      return return_value;
     717  }
     718  
     719  PyDoc_STRVAR(_io_TextIOWrapper_readline__doc__,
     720  "readline($self, size=-1, /)\n"
     721  "--\n"
     722  "\n");
     723  
     724  #define _IO_TEXTIOWRAPPER_READLINE_METHODDEF    \
     725      {"readline", _PyCFunction_CAST(_io_TextIOWrapper_readline), METH_FASTCALL, _io_TextIOWrapper_readline__doc__},
     726  
     727  static PyObject *
     728  _io_TextIOWrapper_readline_impl(textio *self, Py_ssize_t size);
     729  
     730  static PyObject *
     731  _io_TextIOWrapper_readline(textio *self, PyObject *const *args, Py_ssize_t nargs)
     732  {
     733      PyObject *return_value = NULL;
     734      Py_ssize_t size = -1;
     735  
     736      if (!_PyArg_CheckPositional("readline", nargs, 0, 1)) {
     737          goto exit;
     738      }
     739      if (nargs < 1) {
     740          goto skip_optional;
     741      }
     742      {
     743          Py_ssize_t ival = -1;
     744          PyObject *iobj = _PyNumber_Index(args[0]);
     745          if (iobj != NULL) {
     746              ival = PyLong_AsSsize_t(iobj);
     747              Py_DECREF(iobj);
     748          }
     749          if (ival == -1 && PyErr_Occurred()) {
     750              goto exit;
     751          }
     752          size = ival;
     753      }
     754  skip_optional:
     755      return_value = _io_TextIOWrapper_readline_impl(self, size);
     756  
     757  exit:
     758      return return_value;
     759  }
     760  
     761  PyDoc_STRVAR(_io_TextIOWrapper_seek__doc__,
     762  "seek($self, cookie, whence=os.SEEK_SET, /)\n"
     763  "--\n"
     764  "\n"
     765  "Set the stream position, and return the new stream position.\n"
     766  "\n"
     767  "  cookie\n"
     768  "    Zero or an opaque number returned by tell().\n"
     769  "  whence\n"
     770  "    The relative position to seek from.\n"
     771  "\n"
     772  "Four operations are supported, given by the following argument\n"
     773  "combinations:\n"
     774  "\n"
     775  "- seek(0, SEEK_SET): Rewind to the start of the stream.\n"
     776  "- seek(cookie, SEEK_SET): Restore a previous position;\n"
     777  "  \'cookie\' must be a number returned by tell().\n"
     778  "- seek(0, SEEK_END): Fast-forward to the end of the stream.\n"
     779  "- seek(0, SEEK_CUR): Leave the current stream position unchanged.\n"
     780  "\n"
     781  "Any other argument combinations are invalid,\n"
     782  "and may raise exceptions.");
     783  
     784  #define _IO_TEXTIOWRAPPER_SEEK_METHODDEF    \
     785      {"seek", _PyCFunction_CAST(_io_TextIOWrapper_seek), METH_FASTCALL, _io_TextIOWrapper_seek__doc__},
     786  
     787  static PyObject *
     788  _io_TextIOWrapper_seek_impl(textio *self, PyObject *cookieObj, int whence);
     789  
     790  static PyObject *
     791  _io_TextIOWrapper_seek(textio *self, PyObject *const *args, Py_ssize_t nargs)
     792  {
     793      PyObject *return_value = NULL;
     794      PyObject *cookieObj;
     795      int whence = 0;
     796  
     797      if (!_PyArg_CheckPositional("seek", nargs, 1, 2)) {
     798          goto exit;
     799      }
     800      cookieObj = args[0];
     801      if (nargs < 2) {
     802          goto skip_optional;
     803      }
     804      whence = _PyLong_AsInt(args[1]);
     805      if (whence == -1 && PyErr_Occurred()) {
     806          goto exit;
     807      }
     808  skip_optional:
     809      return_value = _io_TextIOWrapper_seek_impl(self, cookieObj, whence);
     810  
     811  exit:
     812      return return_value;
     813  }
     814  
     815  PyDoc_STRVAR(_io_TextIOWrapper_tell__doc__,
     816  "tell($self, /)\n"
     817  "--\n"
     818  "\n"
     819  "Return the stream position as an opaque number.\n"
     820  "\n"
     821  "The return value of tell() can be given as input to seek(), to restore a\n"
     822  "previous stream position.");
     823  
     824  #define _IO_TEXTIOWRAPPER_TELL_METHODDEF    \
     825      {"tell", (PyCFunction)_io_TextIOWrapper_tell, METH_NOARGS, _io_TextIOWrapper_tell__doc__},
     826  
     827  static PyObject *
     828  _io_TextIOWrapper_tell_impl(textio *self);
     829  
     830  static PyObject *
     831  _io_TextIOWrapper_tell(textio *self, PyObject *Py_UNUSED(ignored))
     832  {
     833      return _io_TextIOWrapper_tell_impl(self);
     834  }
     835  
     836  PyDoc_STRVAR(_io_TextIOWrapper_truncate__doc__,
     837  "truncate($self, pos=None, /)\n"
     838  "--\n"
     839  "\n");
     840  
     841  #define _IO_TEXTIOWRAPPER_TRUNCATE_METHODDEF    \
     842      {"truncate", _PyCFunction_CAST(_io_TextIOWrapper_truncate), METH_FASTCALL, _io_TextIOWrapper_truncate__doc__},
     843  
     844  static PyObject *
     845  _io_TextIOWrapper_truncate_impl(textio *self, PyObject *pos);
     846  
     847  static PyObject *
     848  _io_TextIOWrapper_truncate(textio *self, PyObject *const *args, Py_ssize_t nargs)
     849  {
     850      PyObject *return_value = NULL;
     851      PyObject *pos = Py_None;
     852  
     853      if (!_PyArg_CheckPositional("truncate", nargs, 0, 1)) {
     854          goto exit;
     855      }
     856      if (nargs < 1) {
     857          goto skip_optional;
     858      }
     859      pos = args[0];
     860  skip_optional:
     861      return_value = _io_TextIOWrapper_truncate_impl(self, pos);
     862  
     863  exit:
     864      return return_value;
     865  }
     866  
     867  PyDoc_STRVAR(_io_TextIOWrapper_fileno__doc__,
     868  "fileno($self, /)\n"
     869  "--\n"
     870  "\n");
     871  
     872  #define _IO_TEXTIOWRAPPER_FILENO_METHODDEF    \
     873      {"fileno", (PyCFunction)_io_TextIOWrapper_fileno, METH_NOARGS, _io_TextIOWrapper_fileno__doc__},
     874  
     875  static PyObject *
     876  _io_TextIOWrapper_fileno_impl(textio *self);
     877  
     878  static PyObject *
     879  _io_TextIOWrapper_fileno(textio *self, PyObject *Py_UNUSED(ignored))
     880  {
     881      return _io_TextIOWrapper_fileno_impl(self);
     882  }
     883  
     884  PyDoc_STRVAR(_io_TextIOWrapper_seekable__doc__,
     885  "seekable($self, /)\n"
     886  "--\n"
     887  "\n");
     888  
     889  #define _IO_TEXTIOWRAPPER_SEEKABLE_METHODDEF    \
     890      {"seekable", (PyCFunction)_io_TextIOWrapper_seekable, METH_NOARGS, _io_TextIOWrapper_seekable__doc__},
     891  
     892  static PyObject *
     893  _io_TextIOWrapper_seekable_impl(textio *self);
     894  
     895  static PyObject *
     896  _io_TextIOWrapper_seekable(textio *self, PyObject *Py_UNUSED(ignored))
     897  {
     898      return _io_TextIOWrapper_seekable_impl(self);
     899  }
     900  
     901  PyDoc_STRVAR(_io_TextIOWrapper_readable__doc__,
     902  "readable($self, /)\n"
     903  "--\n"
     904  "\n");
     905  
     906  #define _IO_TEXTIOWRAPPER_READABLE_METHODDEF    \
     907      {"readable", (PyCFunction)_io_TextIOWrapper_readable, METH_NOARGS, _io_TextIOWrapper_readable__doc__},
     908  
     909  static PyObject *
     910  _io_TextIOWrapper_readable_impl(textio *self);
     911  
     912  static PyObject *
     913  _io_TextIOWrapper_readable(textio *self, PyObject *Py_UNUSED(ignored))
     914  {
     915      return _io_TextIOWrapper_readable_impl(self);
     916  }
     917  
     918  PyDoc_STRVAR(_io_TextIOWrapper_writable__doc__,
     919  "writable($self, /)\n"
     920  "--\n"
     921  "\n");
     922  
     923  #define _IO_TEXTIOWRAPPER_WRITABLE_METHODDEF    \
     924      {"writable", (PyCFunction)_io_TextIOWrapper_writable, METH_NOARGS, _io_TextIOWrapper_writable__doc__},
     925  
     926  static PyObject *
     927  _io_TextIOWrapper_writable_impl(textio *self);
     928  
     929  static PyObject *
     930  _io_TextIOWrapper_writable(textio *self, PyObject *Py_UNUSED(ignored))
     931  {
     932      return _io_TextIOWrapper_writable_impl(self);
     933  }
     934  
     935  PyDoc_STRVAR(_io_TextIOWrapper_isatty__doc__,
     936  "isatty($self, /)\n"
     937  "--\n"
     938  "\n");
     939  
     940  #define _IO_TEXTIOWRAPPER_ISATTY_METHODDEF    \
     941      {"isatty", (PyCFunction)_io_TextIOWrapper_isatty, METH_NOARGS, _io_TextIOWrapper_isatty__doc__},
     942  
     943  static PyObject *
     944  _io_TextIOWrapper_isatty_impl(textio *self);
     945  
     946  static PyObject *
     947  _io_TextIOWrapper_isatty(textio *self, PyObject *Py_UNUSED(ignored))
     948  {
     949      return _io_TextIOWrapper_isatty_impl(self);
     950  }
     951  
     952  PyDoc_STRVAR(_io_TextIOWrapper_flush__doc__,
     953  "flush($self, /)\n"
     954  "--\n"
     955  "\n");
     956  
     957  #define _IO_TEXTIOWRAPPER_FLUSH_METHODDEF    \
     958      {"flush", (PyCFunction)_io_TextIOWrapper_flush, METH_NOARGS, _io_TextIOWrapper_flush__doc__},
     959  
     960  static PyObject *
     961  _io_TextIOWrapper_flush_impl(textio *self);
     962  
     963  static PyObject *
     964  _io_TextIOWrapper_flush(textio *self, PyObject *Py_UNUSED(ignored))
     965  {
     966      return _io_TextIOWrapper_flush_impl(self);
     967  }
     968  
     969  PyDoc_STRVAR(_io_TextIOWrapper_close__doc__,
     970  "close($self, /)\n"
     971  "--\n"
     972  "\n");
     973  
     974  #define _IO_TEXTIOWRAPPER_CLOSE_METHODDEF    \
     975      {"close", (PyCFunction)_io_TextIOWrapper_close, METH_NOARGS, _io_TextIOWrapper_close__doc__},
     976  
     977  static PyObject *
     978  _io_TextIOWrapper_close_impl(textio *self);
     979  
     980  static PyObject *
     981  _io_TextIOWrapper_close(textio *self, PyObject *Py_UNUSED(ignored))
     982  {
     983      return _io_TextIOWrapper_close_impl(self);
     984  }
     985  /*[clinic end generated code: output=a3614e1c64747ff5 input=a9049054013a1b77]*/