#include "Python.h" #include <stddef.h> // offsetof() #include "pycore_object.h" #include "_iomodule.h" /* Implementation note: the buffer is always at least one character longer than the enclosed string, for proper functioning of _PyIO_find_line_ending. */ #define STATE_REALIZED … #define STATE_ACCUMULATING … /*[clinic input] module _io class _io.StringIO "stringio *" "clinic_state()->PyStringIO_Type" [clinic start generated code]*/ /*[clinic end generated code: output=da39a3ee5e6b4b0d input=2693eada0658d470]*/ stringio; #define clinic_state … #include "clinic/stringio.c.h" #undef clinic_state static int _io_StringIO___init__(PyObject *self, PyObject *args, PyObject *kwargs); #define CHECK_INITIALIZED(self) … #define CHECK_CLOSED(self) … #define ENSURE_REALIZED(self) … /* Internal routine for changing the size, in terms of characters, of the buffer of StringIO objects. The caller should ensure that the 'size' argument is non-negative. Returns 0 on success, -1 otherwise. */ static int resize_buffer(stringio *self, size_t size) { … } static PyObject * make_intermediate(stringio *self) { … } static int realize(stringio *self) { … } /* Internal routine for writing a whole PyUnicode object to the buffer of a StringIO object. Returns 0 on success, or -1 on error. */ static Py_ssize_t write_str(stringio *self, PyObject *obj) { … } /*[clinic input] @critical_section _io.StringIO.getvalue Retrieve the entire contents of the object. [clinic start generated code]*/ static PyObject * _io_StringIO_getvalue_impl(stringio *self) /*[clinic end generated code: output=27b6a7bfeaebce01 input=fb5dee06b8d467f3]*/ { … } /*[clinic input] @critical_section _io.StringIO.tell Tell the current file position. [clinic start generated code]*/ static PyObject * _io_StringIO_tell_impl(stringio *self) /*[clinic end generated code: output=2e87ac67b116c77b input=98a08f3e2dae3550]*/ { … } /*[clinic input] @critical_section _io.StringIO.read size: Py_ssize_t(accept={int, NoneType}) = -1 / Read at most size characters, returned as a string. If the argument is negative or omitted, read until EOF is reached. Return an empty string at EOF. [clinic start generated code]*/ static PyObject * _io_StringIO_read_impl(stringio *self, Py_ssize_t size) /*[clinic end generated code: output=ae8cf6002f71626c input=9fbef45d8aece8e7]*/ { … } /* Internal helper, used by stringio_readline and stringio_iternext */ static PyObject * _stringio_readline(stringio *self, Py_ssize_t limit) { … } /*[clinic input] @critical_section _io.StringIO.readline size: Py_ssize_t(accept={int, NoneType}) = -1 / Read until newline or EOF. Returns an empty string if EOF is hit immediately. [clinic start generated code]*/ static PyObject * _io_StringIO_readline_impl(stringio *self, Py_ssize_t size) /*[clinic end generated code: output=cabd6452f1b7e85d input=4d14b8495dea1d98]*/ { … } static PyObject * stringio_iternext(stringio *self) { … } /*[clinic input] @critical_section _io.StringIO.truncate pos as size: Py_ssize_t(accept={int, NoneType}, c_default="self->pos") = None / Truncate size to pos. The pos argument defaults to the current file position, as returned by tell(). The current file position is unchanged. Returns the new absolute position. [clinic start generated code]*/ static PyObject * _io_StringIO_truncate_impl(stringio *self, Py_ssize_t size) /*[clinic end generated code: output=eb3aef8e06701365 input=461b872dce238452]*/ { … } /*[clinic input] @critical_section _io.StringIO.seek pos: Py_ssize_t whence: int = 0 / Change stream position. Seek to character offset pos relative to position indicated by whence: 0 Start of stream (the default). pos should be >= 0; 1 Current position - pos must be 0; 2 End of stream - pos must be 0. Returns the new absolute position. [clinic start generated code]*/ static PyObject * _io_StringIO_seek_impl(stringio *self, Py_ssize_t pos, int whence) /*[clinic end generated code: output=e9e0ac9a8ae71c25 input=c75ced09343a00d7]*/ { … } /*[clinic input] @critical_section _io.StringIO.write s as obj: object / Write string to file. Returns the number of characters written, which is always equal to the length of the string. [clinic start generated code]*/ static PyObject * _io_StringIO_write_impl(stringio *self, PyObject *obj) /*[clinic end generated code: output=d53b1d841d7db288 input=1561272c0da4651f]*/ { … } /*[clinic input] @critical_section _io.StringIO.close Close the IO object. Attempting any further operation after the object is closed will raise a ValueError. This method has no effect if the file is already closed. [clinic start generated code]*/ static PyObject * _io_StringIO_close_impl(stringio *self) /*[clinic end generated code: output=04399355cbe518f1 input=305d19aa29cc40b9]*/ { … } static int stringio_traverse(stringio *self, visitproc visit, void *arg) { … } static int stringio_clear(stringio *self) { … } static void stringio_dealloc(stringio *self) { … } static PyObject * stringio_new(PyTypeObject *type, PyObject *args, PyObject *kwds) { … } /*[clinic input] _io.StringIO.__init__ initial_value as value: object(c_default="NULL") = '' newline as newline_obj: object(c_default="NULL") = '\n' Text I/O implementation using an in-memory buffer. The initial_value argument sets the value of object. The newline argument is like the one of TextIOWrapper's constructor. [clinic start generated code]*/ static int _io_StringIO___init___impl(stringio *self, PyObject *value, PyObject *newline_obj) /*[clinic end generated code: output=a421ea023b22ef4e input=cee2d9181b2577a3]*/ { … } /* Properties and pseudo-properties */ /*[clinic input] @critical_section _io.StringIO.readable Returns True if the IO object can be read. [clinic start generated code]*/ static PyObject * _io_StringIO_readable_impl(stringio *self) /*[clinic end generated code: output=b19d44dd8b1ceb99 input=6cd2ffd65a8e8763]*/ { … } /*[clinic input] @critical_section _io.StringIO.writable Returns True if the IO object can be written. [clinic start generated code]*/ static PyObject * _io_StringIO_writable_impl(stringio *self) /*[clinic end generated code: output=13e4dd77187074ca input=1b3c63dbaa761c69]*/ { … } /*[clinic input] @critical_section _io.StringIO.seekable Returns True if the IO object can be seeked. [clinic start generated code]*/ static PyObject * _io_StringIO_seekable_impl(stringio *self) /*[clinic end generated code: output=4d20b4641c756879 input=a820fad2cf085fc3]*/ { … } /* Pickling support. The implementation of __getstate__ is similar to the one for BytesIO, except that we also save the newline parameter. For __setstate__ and unlike BytesIO, we call __init__ to restore the object's state. Doing so allows us to avoid decoding the complex newline state while keeping the object representation compact. See comment in bytesio.c regarding why only pickle protocols and onward are supported. */ /*[clinic input] @critical_section _io.StringIO.__getstate__ [clinic start generated code]*/ static PyObject * _io_StringIO___getstate___impl(stringio *self) /*[clinic end generated code: output=780be4a996410199 input=76f27255ef83bb92]*/ { … } /*[clinic input] @critical_section _io.StringIO.__setstate__ state: object / [clinic start generated code]*/ static PyObject * _io_StringIO___setstate___impl(stringio *self, PyObject *state) /*[clinic end generated code: output=cb3962bc6d5c5609 input=8a27784b11b82e47]*/ { … } /*[clinic input] @critical_section @getter _io.StringIO.closed [clinic start generated code]*/ static PyObject * _io_StringIO_closed_get_impl(stringio *self) /*[clinic end generated code: output=531ddca7954331d6 input=178d2ef24395fd49]*/ { … } /*[clinic input] @critical_section @getter _io.StringIO.line_buffering [clinic start generated code]*/ static PyObject * _io_StringIO_line_buffering_get_impl(stringio *self) /*[clinic end generated code: output=360710e0112966ae input=6a7634e7f890745e]*/ { … } /*[clinic input] @critical_section @getter _io.StringIO.newlines [clinic start generated code]*/ static PyObject * _io_StringIO_newlines_get_impl(stringio *self) /*[clinic end generated code: output=35d7c0b66d7e0160 input=092a14586718244b]*/ { … } static struct PyMethodDef stringio_methods[] = …; static PyGetSetDef stringio_getset[] = …; static struct PyMemberDef stringio_members[] = …; static PyType_Slot stringio_slots[] = …; PyType_Spec stringio_spec = …;