diff --git a/Modules/_io/clinic/textio.c.h b/Modules/_io/clinic/textio.c.h index db968e884cc805..01965013ec6abc 100644 --- a/Modules/_io/clinic/textio.c.h +++ b/Modules/_io/clinic/textio.c.h @@ -8,6 +8,171 @@ preserve #endif +PyDoc_STRVAR(_io__TextIOBase_detach__doc__, +"detach($self, /)\n" +"--\n" +"\n" +"Separate the underlying buffer from the TextIOBase and return it.\n" +"\n" +"After the underlying buffer has been detached, the TextIO is in an unusable state."); + +#define _IO__TEXTIOBASE_DETACH_METHODDEF \ + {"detach", _PyCFunction_CAST(_io__TextIOBase_detach), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _io__TextIOBase_detach__doc__}, + +static PyObject * +_io__TextIOBase_detach_impl(PyObject *self, PyTypeObject *cls); + +static PyObject * +_io__TextIOBase_detach(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +{ + if (nargs) { + PyErr_SetString(PyExc_TypeError, "detach() takes no arguments"); + return NULL; + } + return _io__TextIOBase_detach_impl(self, cls); +} + +PyDoc_STRVAR(_io__TextIOBase_read__doc__, +"read($self, /, *args)\n" +"--\n" +"\n" +"Read at most size characters from stream.\n" +"\n" +"Read from underlying buffer until we have size characters or we hit EOF.\n" +"If size is negative or omitted, read until EOF."); + +#define _IO__TEXTIOBASE_READ_METHODDEF \ + {"read", _PyCFunction_CAST(_io__TextIOBase_read), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _io__TextIOBase_read__doc__}, + +static PyObject * +_io__TextIOBase_read_impl(PyObject *self, PyTypeObject *cls, PyObject *args); + +static PyObject * +_io__TextIOBase_read(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +{ + PyObject *return_value = NULL; + #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) + # define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty) + #else + # define KWTUPLE NULL + #endif + + static const char * const _keywords[] = { NULL}; + static _PyArg_Parser _parser = { + .keywords = _keywords, + .fname = "read", + .kwtuple = KWTUPLE, + }; + #undef KWTUPLE + PyObject *argsbuf[1]; + PyObject *__clinic_args = NULL; + + args = _PyArg_UnpackKeywordsWithVararg(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, 0, argsbuf); + if (!args) { + goto exit; + } + __clinic_args = args[0]; + return_value = _io__TextIOBase_read_impl(self, cls, __clinic_args); + +exit: + Py_XDECREF(__clinic_args); + return return_value; +} + +PyDoc_STRVAR(_io__TextIOBase_readline__doc__, +"readline($self, /, *args)\n" +"--\n" +"\n" +"Read until newline or EOF.\n" +"\n" +"Return an empty string if EOF is hit immediately."); + +#define _IO__TEXTIOBASE_READLINE_METHODDEF \ + {"readline", _PyCFunction_CAST(_io__TextIOBase_readline), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _io__TextIOBase_readline__doc__}, + +static PyObject * +_io__TextIOBase_readline_impl(PyObject *self, PyTypeObject *cls, + PyObject *args); + +static PyObject * +_io__TextIOBase_readline(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +{ + PyObject *return_value = NULL; + #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) + # define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty) + #else + # define KWTUPLE NULL + #endif + + static const char * const _keywords[] = { NULL}; + static _PyArg_Parser _parser = { + .keywords = _keywords, + .fname = "readline", + .kwtuple = KWTUPLE, + }; + #undef KWTUPLE + PyObject *argsbuf[1]; + PyObject *__clinic_args = NULL; + + args = _PyArg_UnpackKeywordsWithVararg(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, 0, argsbuf); + if (!args) { + goto exit; + } + __clinic_args = args[0]; + return_value = _io__TextIOBase_readline_impl(self, cls, __clinic_args); + +exit: + Py_XDECREF(__clinic_args); + return return_value; +} + +PyDoc_STRVAR(_io__TextIOBase_write__doc__, +"write($self, /, *args)\n" +"--\n" +"\n" +"Write string to stream.\n" +"\n" +"Return the number of characters written\n" +"(which is always equal to the length of the string)."); + +#define _IO__TEXTIOBASE_WRITE_METHODDEF \ + {"write", _PyCFunction_CAST(_io__TextIOBase_write), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _io__TextIOBase_write__doc__}, + +static PyObject * +_io__TextIOBase_write_impl(PyObject *self, PyTypeObject *cls, PyObject *args); + +static PyObject * +_io__TextIOBase_write(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +{ + PyObject *return_value = NULL; + #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) + # define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty) + #else + # define KWTUPLE NULL + #endif + + static const char * const _keywords[] = { NULL}; + static _PyArg_Parser _parser = { + .keywords = _keywords, + .fname = "write", + .kwtuple = KWTUPLE, + }; + #undef KWTUPLE + PyObject *argsbuf[1]; + PyObject *__clinic_args = NULL; + + args = _PyArg_UnpackKeywordsWithVararg(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, 0, argsbuf); + if (!args) { + goto exit; + } + __clinic_args = args[0]; + return_value = _io__TextIOBase_write_impl(self, cls, __clinic_args); + +exit: + Py_XDECREF(__clinic_args); + return return_value; +} + PyDoc_STRVAR(_io_IncrementalNewlineDecoder___init____doc__, "IncrementalNewlineDecoder(decoder, translate, errors=\'strict\')\n" "--\n" @@ -769,4 +934,4 @@ _io_TextIOWrapper_close(textio *self, PyObject *Py_UNUSED(ignored)) { return _io_TextIOWrapper_close_impl(self); } -/*[clinic end generated code: output=73f84b13c343b34b input=a9049054013a1b77]*/ +/*[clinic end generated code: output=d800e5a8a50d6720 input=a9049054013a1b77]*/ diff --git a/Modules/_io/textio.c b/Modules/_io/textio.c index 070687a83d1bc2..96f5e0c45f51b8 100644 --- a/Modules/_io/textio.c +++ b/Modules/_io/textio.c @@ -20,8 +20,16 @@ module _io class _io.IncrementalNewlineDecoder "nldecoder_object *" "clinic_state()->PyIncrementalNewlineDecoder_Type" class _io.TextIOWrapper "textio *" "clinic_state()->TextIOWrapper_Type" +class _io._TextIOBase "PyObject *" "&PyTextIOBase_Type" [clinic start generated code]*/ -/*[clinic end generated code: output=da39a3ee5e6b4b0d input=81f67cf54eaa6001]*/ +/*[clinic end generated code: output=da39a3ee5e6b4b0d input=8b7f24fa13bfdd7f]*/ + +typedef struct nldecoder_object nldecoder_object; +typedef struct textio textio; + +#define clinic_state() (find_io_state_by_def(Py_TYPE(self))) +#include "clinic/textio.c.h" +#undef clinic_state /* TextIOBase */ @@ -42,52 +50,76 @@ _unsupported(const char *message) return NULL; } -PyDoc_STRVAR(textiobase_detach_doc, - "Separate the underlying buffer from the TextIOBase and return it.\n" - "\n" - "After the underlying buffer has been detached, the TextIO is in an\n" - "unusable state.\n" - ); +/*[clinic input] +_io._TextIOBase.detach + cls: defining_class + / + +Separate the underlying buffer from the TextIOBase and return it. + +After the underlying buffer has been detached, the TextIO is in an unusable state. +[clinic start generated code]*/ static PyObject * -textiobase_detach(PyObject *self, PyObject *Py_UNUSED(ignored)) +_io__TextIOBase_detach_impl(PyObject *self, PyTypeObject *cls) +/*[clinic end generated code: output=50915f40c609eaa4 input=987ca3640d0a3776]*/ { return _unsupported("detach"); } -PyDoc_STRVAR(textiobase_read_doc, - "Read at most size characters from stream.\n" - "\n" - "Read from underlying buffer until we have size characters or we hit EOF.\n" - "If size is negative or omitted, read until EOF.\n" - ); +/*[clinic input] +_io._TextIOBase.read + cls: defining_class + / + *args: object + +Read at most size characters from stream. + +Read from underlying buffer until we have size characters or we hit EOF. +If size is negative or omitted, read until EOF. +[clinic start generated code]*/ static PyObject * -textiobase_read(PyObject *self, PyObject *args) +_io__TextIOBase_read_impl(PyObject *self, PyTypeObject *cls, PyObject *args) +/*[clinic end generated code: output=3adf28998831f461 input=cee1e84664a20de0]*/ { return _unsupported("read"); } -PyDoc_STRVAR(textiobase_readline_doc, - "Read until newline or EOF.\n" - "\n" - "Returns an empty string if EOF is hit immediately.\n" - ); +/*[clinic input] +_io._TextIOBase.readline + cls: defining_class + / + *args: object + +Read until newline or EOF. + +Return an empty string if EOF is hit immediately. +[clinic start generated code]*/ static PyObject * -textiobase_readline(PyObject *self, PyObject *args) +_io__TextIOBase_readline_impl(PyObject *self, PyTypeObject *cls, + PyObject *args) +/*[clinic end generated code: output=3073a948d02319f3 input=58f801259f7ff3ef]*/ { return _unsupported("readline"); } -PyDoc_STRVAR(textiobase_write_doc, - "Write string to stream.\n" - "Returns the number of characters written (which is always equal to\n" - "the length of the string).\n" - ); +/*[clinic input] +_io._TextIOBase.write + cls: defining_class + / + *args: object + +Write string to stream. + +Return the number of characters written +(which is always equal to the length of the string). +[clinic start generated code]*/ static PyObject * -textiobase_write(PyObject *self, PyObject *args) +_io__TextIOBase_write_impl(PyObject *self, PyTypeObject *cls, PyObject *args) +/*[clinic end generated code: output=5d985eb529472bc4 input=21b6961b5cba9496]*/ { return _unsupported("write"); } @@ -132,10 +164,10 @@ textiobase_errors_get(PyObject *self, void *context) static PyMethodDef textiobase_methods[] = { - {"detach", textiobase_detach, METH_NOARGS, textiobase_detach_doc}, - {"read", textiobase_read, METH_VARARGS, textiobase_read_doc}, - {"readline", textiobase_readline, METH_VARARGS, textiobase_readline_doc}, - {"write", textiobase_write, METH_VARARGS, textiobase_write_doc}, + _IO__TEXTIOBASE_DETACH_METHODDEF + _IO__TEXTIOBASE_READ_METHODDEF + _IO__TEXTIOBASE_READLINE_METHODDEF + _IO__TEXTIOBASE_WRITE_METHODDEF {NULL, NULL} }; @@ -200,14 +232,14 @@ PyTypeObject PyTextIOBase_Type = { /* IncrementalNewlineDecoder */ -typedef struct { +struct nldecoder_object { PyObject_HEAD PyObject *decoder; PyObject *errors; unsigned int pendingcr: 1; unsigned int translate: 1; unsigned int seennl: 3; -} nldecoder_object; +}; /*[clinic input] _io.IncrementalNewlineDecoder.__init__ @@ -645,7 +677,7 @@ incrementalnewlinedecoder_newlines_get(nldecoder_object *self, void *context) typedef PyObject * (*encodefunc_t)(PyObject *, PyObject *); -typedef struct +struct textio { PyObject_HEAD int ok; /* initialized? */ @@ -704,7 +736,7 @@ typedef struct PyObject *dict; _PyIO_State *state; -} textio; +}; static void textiowrapper_set_decoded_chars(textio *self, PyObject *chars); @@ -3179,10 +3211,6 @@ textiowrapper_chunk_size_set(textio *self, PyObject *arg, void *context) return 0; } -#define clinic_state() (find_io_state_by_def(Py_TYPE(self))) -#include "clinic/textio.c.h" -#undef clinic_state - static PyMethodDef incrementalnewlinedecoder_methods[] = { _IO_INCREMENTALNEWLINEDECODER_DECODE_METHODDEF _IO_INCREMENTALNEWLINEDECODER_GETSTATE_METHODDEF