Issue #20175: Converted the _io module to Argument Clinic.

This commit is contained in:
Serhiy Storchaka 2015-04-16 11:19:43 +03:00
parent 7f90cba7f3
commit f24131ff31
16 changed files with 4209 additions and 1372 deletions

View File

@ -190,9 +190,9 @@ class AutoFileTests:
self.assertTrue(f.closed)
def testMethods(self):
methods = ['fileno', 'isatty', 'read',
'tell', 'truncate', 'seekable',
'readable', 'writable']
methods = ['fileno', 'isatty', 'seekable', 'readable', 'writable',
'read', 'readall', 'readline', 'readlines',
'tell', 'truncate', 'flush']
self.f.close()
self.assertTrue(self.f.closed)
@ -201,9 +201,15 @@ class AutoFileTests:
method = getattr(self.f, methodname)
# should raise on closed file
self.assertRaises(ValueError, method)
self.assertRaises(ValueError, self.f.readinto, bytearray())
self.assertRaises(ValueError, self.f.seek, 0, os.SEEK_CUR)
self.assertRaises(TypeError, self.f.readinto)
self.assertRaises(ValueError, self.f.readinto, bytearray(1))
self.assertRaises(TypeError, self.f.seek)
self.assertRaises(ValueError, self.f.seek, 0)
self.assertRaises(TypeError, self.f.write)
self.assertRaises(ValueError, self.f.write, b'')
self.assertRaises(TypeError, self.f.writelines)
self.assertRaises(ValueError, self.f.writelines, b'')
def testOpendir(self):
# Issue 3703: opening a directory should fill the errno

View File

@ -2163,6 +2163,17 @@ class TextIOWrapperTest(unittest.TestCase):
self.assertRaises(TypeError, t.__init__, b, newline=42)
self.assertRaises(ValueError, t.__init__, b, newline='xyzzy')
def test_uninitialized(self):
t = self.TextIOWrapper.__new__(self.TextIOWrapper)
del t
t = self.TextIOWrapper.__new__(self.TextIOWrapper)
self.assertRaises(Exception, repr, t)
self.assertRaisesRegex((ValueError, AttributeError),
'uninitialized|has no attribute',
t.read, 0)
t.__init__(self.MockRawIO())
self.assertEqual(t.read(0), '')
def test_non_text_encoding_codecs_are_rejected(self):
# Ensure the constructor complains if passed a codec that isn't
# marked as a text encoding
@ -3024,8 +3035,6 @@ class CTextIOWrapperTest(TextIOWrapperTest):
r = self.BytesIO(b"\xc3\xa9\n\n")
b = self.BufferedReader(r, 1000)
t = self.TextIOWrapper(b)
self.assertRaises(TypeError, t.__init__, b, newline=42)
self.assertRaises(ValueError, t.read)
self.assertRaises(ValueError, t.__init__, b, newline='xyzzy')
self.assertRaises(ValueError, t.read)

View File

@ -93,140 +93,145 @@ PyDoc_STRVAR(module_doc,
/*
* The main open() function
*/
PyDoc_STRVAR(open_doc,
"open(file, mode='r', buffering=-1, encoding=None,\n"
" errors=None, newline=None, closefd=True, opener=None) -> file object\n"
"\n"
"Open file and return a stream. Raise IOError upon failure.\n"
"\n"
"file is either a text or byte string giving the name (and the path\n"
"if the file isn't in the current working directory) of the file to\n"
"be opened or an integer file descriptor of the file to be\n"
"wrapped. (If a file descriptor is given, it is closed when the\n"
"returned I/O object is closed, unless closefd is set to False.)\n"
"\n"
"mode is an optional string that specifies the mode in which the file\n"
"is opened. It defaults to 'r' which means open for reading in text\n"
"mode. Other common values are 'w' for writing (truncating the file if\n"
"it already exists), 'x' for creating and writing to a new file, and\n"
"'a' for appending (which on some Unix systems, means that all writes\n"
"append to the end of the file regardless of the current seek position).\n"
"In text mode, if encoding is not specified the encoding used is platform\n"
"dependent: locale.getpreferredencoding(False) is called to get the\n"
"current locale encoding. (For reading and writing raw bytes use binary\n"
"mode and leave encoding unspecified.) The available modes are:\n"
"\n"
"========= ===============================================================\n"
"Character Meaning\n"
"--------- ---------------------------------------------------------------\n"
"'r' open for reading (default)\n"
"'w' open for writing, truncating the file first\n"
"'x' create a new file and open it for writing\n"
"'a' open for writing, appending to the end of the file if it exists\n"
"'b' binary mode\n"
"'t' text mode (default)\n"
"'+' open a disk file for updating (reading and writing)\n"
"'U' universal newline mode (deprecated)\n"
"========= ===============================================================\n"
"\n"
"The default mode is 'rt' (open for reading text). For binary random\n"
"access, the mode 'w+b' opens and truncates the file to 0 bytes, while\n"
"'r+b' opens the file without truncation. The 'x' mode implies 'w' and\n"
"raises an `FileExistsError` if the file already exists.\n"
"\n"
"Python distinguishes between files opened in binary and text modes,\n"
"even when the underlying operating system doesn't. Files opened in\n"
"binary mode (appending 'b' to the mode argument) return contents as\n"
"bytes objects without any decoding. In text mode (the default, or when\n"
"'t' is appended to the mode argument), the contents of the file are\n"
"returned as strings, the bytes having been first decoded using a\n"
"platform-dependent encoding or using the specified encoding if given.\n"
"\n"
"'U' mode is deprecated and will raise an exception in future versions\n"
"of Python. It has no effect in Python 3. Use newline to control\n"
"universal newlines mode.\n"
"\n"
"buffering is an optional integer used to set the buffering policy.\n"
"Pass 0 to switch buffering off (only allowed in binary mode), 1 to select\n"
"line buffering (only usable in text mode), and an integer > 1 to indicate\n"
"the size of a fixed-size chunk buffer. When no buffering argument is\n"
"given, the default buffering policy works as follows:\n"
"\n"
"* Binary files are buffered in fixed-size chunks; the size of the buffer\n"
" is chosen using a heuristic trying to determine the underlying device's\n"
" \"block size\" and falling back on `io.DEFAULT_BUFFER_SIZE`.\n"
" On many systems, the buffer will typically be 4096 or 8192 bytes long.\n"
"\n"
"* \"Interactive\" text files (files for which isatty() returns True)\n"
" use line buffering. Other text files use the policy described above\n"
" for binary files.\n"
"\n"
"encoding is the name of the encoding used to decode or encode the\n"
"file. This should only be used in text mode. The default encoding is\n"
"platform dependent, but any encoding supported by Python can be\n"
"passed. See the codecs module for the list of supported encodings.\n"
"\n"
"errors is an optional string that specifies how encoding errors are to\n"
"be handled---this argument should not be used in binary mode. Pass\n"
"'strict' to raise a ValueError exception if there is an encoding error\n"
"(the default of None has the same effect), or pass 'ignore' to ignore\n"
"errors. (Note that ignoring encoding errors can lead to data loss.)\n"
"See the documentation for codecs.register or run 'help(codecs.Codec)'\n"
"for a list of the permitted encoding error strings.\n"
"\n"
"newline controls how universal newlines works (it only applies to text\n"
"mode). It can be None, '', '\\n', '\\r', and '\\r\\n'. It works as\n"
"follows:\n"
"\n"
"* On input, if newline is None, universal newlines mode is\n"
" enabled. Lines in the input can end in '\\n', '\\r', or '\\r\\n', and\n"
" these are translated into '\\n' before being returned to the\n"
" caller. If it is '', universal newline mode is enabled, but line\n"
" endings are returned to the caller untranslated. If it has any of\n"
" the other legal values, input lines are only terminated by the given\n"
" string, and the line ending is returned to the caller untranslated.\n"
"\n"
"* On output, if newline is None, any '\\n' characters written are\n"
" translated to the system default line separator, os.linesep. If\n"
" newline is '' or '\\n', no translation takes place. If newline is any\n"
" of the other legal values, any '\\n' characters written are translated\n"
" to the given string.\n"
"\n"
"If closefd is False, the underlying file descriptor will be kept open\n"
"when the file is closed. This does not work when a file name is given\n"
"and must be True in that case.\n"
"\n"
"A custom opener can be used by passing a callable as *opener*. The\n"
"underlying file descriptor for the file object is then obtained by\n"
"calling *opener* with (*file*, *flags*). *opener* must return an open\n"
"file descriptor (passing os.open as *opener* results in functionality\n"
"similar to passing None).\n"
"\n"
"open() returns a file object whose type depends on the mode, and\n"
"through which the standard file operations such as reading and writing\n"
"are performed. When open() is used to open a file in a text mode ('w',\n"
"'r', 'wt', 'rt', etc.), it returns a TextIOWrapper. When used to open\n"
"a file in a binary mode, the returned class varies: in read binary\n"
"mode, it returns a BufferedReader; in write binary and append binary\n"
"modes, it returns a BufferedWriter, and in read/write mode, it returns\n"
"a BufferedRandom.\n"
"\n"
"It is also possible to use a string or bytearray as a file for both\n"
"reading and writing. For strings StringIO can be used like a file\n"
"opened in a text mode, and for bytes a BytesIO can be used like a file\n"
"opened in a binary mode.\n"
);
/*[clinic input]
module _io
_io.open
file: object
mode: str = "r"
buffering: int = -1
encoding: str(nullable=True) = NULL
errors: str(nullable=True) = NULL
newline: str(nullable=True) = NULL
closefd: int(c_default="1") = True
opener: object = None
Open file and return a stream. Raise IOError upon failure.
file is either a text or byte string giving the name (and the path
if the file isn't in the current working directory) of the file to
be opened or an integer file descriptor of the file to be
wrapped. (If a file descriptor is given, it is closed when the
returned I/O object is closed, unless closefd is set to False.)
mode is an optional string that specifies the mode in which the file
is opened. It defaults to 'r' which means open for reading in text
mode. Other common values are 'w' for writing (truncating the file if
it already exists), 'x' for creating and writing to a new file, and
'a' for appending (which on some Unix systems, means that all writes
append to the end of the file regardless of the current seek position).
In text mode, if encoding is not specified the encoding used is platform
dependent: locale.getpreferredencoding(False) is called to get the
current locale encoding. (For reading and writing raw bytes use binary
mode and leave encoding unspecified.) The available modes are:
========= ===============================================================
Character Meaning
--------- ---------------------------------------------------------------
'r' open for reading (default)
'w' open for writing, truncating the file first
'x' create a new file and open it for writing
'a' open for writing, appending to the end of the file if it exists
'b' binary mode
't' text mode (default)
'+' open a disk file for updating (reading and writing)
'U' universal newline mode (deprecated)
========= ===============================================================
The default mode is 'rt' (open for reading text). For binary random
access, the mode 'w+b' opens and truncates the file to 0 bytes, while
'r+b' opens the file without truncation. The 'x' mode implies 'w' and
raises an `FileExistsError` if the file already exists.
Python distinguishes between files opened in binary and text modes,
even when the underlying operating system doesn't. Files opened in
binary mode (appending 'b' to the mode argument) return contents as
bytes objects without any decoding. In text mode (the default, or when
't' is appended to the mode argument), the contents of the file are
returned as strings, the bytes having been first decoded using a
platform-dependent encoding or using the specified encoding if given.
'U' mode is deprecated and will raise an exception in future versions
of Python. It has no effect in Python 3. Use newline to control
universal newlines mode.
buffering is an optional integer used to set the buffering policy.
Pass 0 to switch buffering off (only allowed in binary mode), 1 to select
line buffering (only usable in text mode), and an integer > 1 to indicate
the size of a fixed-size chunk buffer. When no buffering argument is
given, the default buffering policy works as follows:
* Binary files are buffered in fixed-size chunks; the size of the buffer
is chosen using a heuristic trying to determine the underlying device's
"block size" and falling back on `io.DEFAULT_BUFFER_SIZE`.
On many systems, the buffer will typically be 4096 or 8192 bytes long.
* "Interactive" text files (files for which isatty() returns True)
use line buffering. Other text files use the policy described above
for binary files.
encoding is the name of the encoding used to decode or encode the
file. This should only be used in text mode. The default encoding is
platform dependent, but any encoding supported by Python can be
passed. See the codecs module for the list of supported encodings.
errors is an optional string that specifies how encoding errors are to
be handled---this argument should not be used in binary mode. Pass
'strict' to raise a ValueError exception if there is an encoding error
(the default of None has the same effect), or pass 'ignore' to ignore
errors. (Note that ignoring encoding errors can lead to data loss.)
See the documentation for codecs.register or run 'help(codecs.Codec)'
for a list of the permitted encoding error strings.
newline controls how universal newlines works (it only applies to text
mode). It can be None, '', '\n', '\r', and '\r\n'. It works as
follows:
* On input, if newline is None, universal newlines mode is
enabled. Lines in the input can end in '\n', '\r', or '\r\n', and
these are translated into '\n' before being returned to the
caller. If it is '', universal newline mode is enabled, but line
endings are returned to the caller untranslated. If it has any of
the other legal values, input lines are only terminated by the given
string, and the line ending is returned to the caller untranslated.
* On output, if newline is None, any '\n' characters written are
translated to the system default line separator, os.linesep. If
newline is '' or '\n', no translation takes place. If newline is any
of the other legal values, any '\n' characters written are translated
to the given string.
If closefd is False, the underlying file descriptor will be kept open
when the file is closed. This does not work when a file name is given
and must be True in that case.
A custom opener can be used by passing a callable as *opener*. The
underlying file descriptor for the file object is then obtained by
calling *opener* with (*file*, *flags*). *opener* must return an open
file descriptor (passing os.open as *opener* results in functionality
similar to passing None).
open() returns a file object whose type depends on the mode, and
through which the standard file operations such as reading and writing
are performed. When open() is used to open a file in a text mode ('w',
'r', 'wt', 'rt', etc.), it returns a TextIOWrapper. When used to open
a file in a binary mode, the returned class varies: in read binary
mode, it returns a BufferedReader; in write binary and append binary
modes, it returns a BufferedWriter, and in read/write mode, it returns
a BufferedRandom.
It is also possible to use a string or bytearray as a file for both
reading and writing. For strings StringIO can be used like a file
opened in a text mode, and for bytes a BytesIO can be used like a file
opened in a binary mode.
[clinic start generated code]*/
static PyObject *
io_open(PyObject *self, PyObject *args, PyObject *kwds)
_io_open_impl(PyModuleDef *module, PyObject *file, const char *mode,
int buffering, const char *encoding, const char *errors,
const char *newline, int closefd, PyObject *opener)
/*[clinic end generated code: output=7615d0d746eb14d2 input=0541ce15691a82f2]*/
{
char *kwlist[] = {"file", "mode", "buffering",
"encoding", "errors", "newline",
"closefd", "opener", NULL};
PyObject *file, *opener = Py_None;
char *mode = "r";
int buffering = -1, closefd = 1;
char *encoding = NULL, *errors = NULL, *newline = NULL;
unsigned i;
int creating = 0, reading = 0, writing = 0, appending = 0, updating = 0;
@ -242,13 +247,6 @@ io_open(PyObject *self, PyObject *args, PyObject *kwds)
_Py_IDENTIFIER(mode);
_Py_IDENTIFIER(close);
if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|sizzziO:open", kwlist,
&file, &mode, &buffering,
&encoding, &errors, &newline,
&closefd, &opener)) {
return NULL;
}
if (!PyUnicode_Check(file) &&
!PyBytes_Check(file) &&
!PyNumber_Check(file)) {
@ -611,8 +609,10 @@ iomodule_free(PyObject *mod) {
* Module definition
*/
#include "clinic/_iomodule.c.h"
static PyMethodDef module_methods[] = {
{"open", (PyCFunction)io_open, METH_VARARGS|METH_KEYWORDS, open_doc},
_IO_OPEN_METHODDEF
{NULL, NULL}
};

File diff suppressed because it is too large Load Diff

View File

@ -2,6 +2,12 @@
#include "structmember.h" /* for offsetof() */
#include "_iomodule.h"
/*[clinic input]
module _io
class _io.BytesIO "bytesio *" "&PyBytesIO_Type"
[clinic start generated code]*/
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=7f50ec034f5c0b26]*/
typedef struct {
PyObject_HEAD
PyObject *buf;
@ -203,40 +209,71 @@ bytesio_get_closed(bytesio *self)
}
}
PyDoc_STRVAR(readable_doc,
"readable() -> bool. Returns True if the IO object can be read.");
/*[clinic input]
_io.BytesIO.readable
PyDoc_STRVAR(writable_doc,
"writable() -> bool. Returns True if the IO object can be written.");
Returns True if the IO object can be read.
[clinic start generated code]*/
PyDoc_STRVAR(seekable_doc,
"seekable() -> bool. Returns True if the IO object can be seeked.");
/* Generic getter for the writable, readable and seekable properties */
static PyObject *
return_not_closed(bytesio *self)
_io_BytesIO_readable_impl(bytesio *self)
/*[clinic end generated code: output=4e93822ad5b62263 input=96c5d0cccfb29f5c]*/
{
CHECK_CLOSED(self);
Py_RETURN_TRUE;
}
PyDoc_STRVAR(flush_doc,
"flush() -> None. Does nothing.");
/*[clinic input]
_io.BytesIO.writable
Returns True if the IO object can be written.
[clinic start generated code]*/
static PyObject *
bytesio_flush(bytesio *self)
_io_BytesIO_writable_impl(bytesio *self)
/*[clinic end generated code: output=64ff6a254b1150b8 input=700eed808277560a]*/
{
CHECK_CLOSED(self);
Py_RETURN_TRUE;
}
/*[clinic input]
_io.BytesIO.seekable
Returns True if the IO object can be seeked.
[clinic start generated code]*/
static PyObject *
_io_BytesIO_seekable_impl(bytesio *self)
/*[clinic end generated code: output=6b417f46dcc09b56 input=9421f65627a344dd]*/
{
CHECK_CLOSED(self);
Py_RETURN_TRUE;
}
/*[clinic input]
_io.BytesIO.flush
Does nothing.
[clinic start generated code]*/
static PyObject *
_io_BytesIO_flush_impl(bytesio *self)
/*[clinic end generated code: output=187e3d781ca134a0 input=561ea490be4581a7]*/
{
CHECK_CLOSED(self);
Py_RETURN_NONE;
}
PyDoc_STRVAR(getbuffer_doc,
"getbuffer() -> bytes.\n"
"\n"
"Get a read-write view over the contents of the BytesIO object.");
/*[clinic input]
_io.BytesIO.getbuffer
Get a read-write view over the contents of the BytesIO object.
[clinic start generated code]*/
static PyObject *
bytesio_getbuffer(bytesio *self)
_io_BytesIO_getbuffer_impl(bytesio *self)
/*[clinic end generated code: output=72cd7c6e13aa09ed input=8f738ef615865176]*/
{
PyTypeObject *type = &_PyBytesIOBuffer_Type;
bytesiobuf *buf;
@ -254,13 +291,15 @@ bytesio_getbuffer(bytesio *self)
return view;
}
PyDoc_STRVAR(getval_doc,
"getvalue() -> bytes.\n"
"\n"
"Retrieve the entire contents of the BytesIO object.");
/*[clinic input]
_io.BytesIO.getvalue
Retrieve the entire contents of the BytesIO object.
[clinic start generated code]*/
static PyObject *
bytesio_getvalue(bytesio *self)
_io_BytesIO_getvalue_impl(bytesio *self)
/*[clinic end generated code: output=b3f6a3233c8fd628 input=4b403ac0af3973ed]*/
{
CHECK_CLOSED(self);
if (self->string_size <= 1 || self->exports > 0)
@ -281,24 +320,31 @@ bytesio_getvalue(bytesio *self)
return self->buf;
}
PyDoc_STRVAR(isatty_doc,
"isatty() -> False.\n"
"\n"
"Always returns False since BytesIO objects are not connected\n"
"to a tty-like device.");
/*[clinic input]
_io.BytesIO.isatty
Always returns False.
BytesIO objects are not connected to a TTY-like device.
[clinic start generated code]*/
static PyObject *
bytesio_isatty(bytesio *self)
_io_BytesIO_isatty_impl(bytesio *self)
/*[clinic end generated code: output=df67712e669f6c8f input=6f97f0985d13f827]*/
{
CHECK_CLOSED(self);
Py_RETURN_FALSE;
}
PyDoc_STRVAR(tell_doc,
"tell() -> current file position, an integer\n");
/*[clinic input]
_io.BytesIO.tell
Current file position, an integer.
[clinic start generated code]*/
static PyObject *
bytesio_tell(bytesio *self)
_io_BytesIO_tell_impl(bytesio *self)
/*[clinic end generated code: output=b54b0f93cd0e5e1d input=b106adf099cb3657]*/
{
CHECK_CLOSED(self);
return PyLong_FromSsize_t(self->pos);
@ -324,23 +370,25 @@ read_bytes(bytesio *self, Py_ssize_t size)
return PyBytes_FromStringAndSize(output, size);
}
PyDoc_STRVAR(read_doc,
"read([size]) -> read at most size bytes, returned as a bytes object.\n"
"\n"
"If the size argument is negative, read until EOF is reached.\n"
"Return an empty bytes object at EOF.");
/*[clinic input]
_io.BytesIO.read
size as arg: object = None
/
Read at most size bytes, returned as a bytes object.
If the size argument is negative, read until EOF is reached.
Return an empty bytes object at EOF.
[clinic start generated code]*/
static PyObject *
bytesio_read(bytesio *self, PyObject *args)
_io_BytesIO_read_impl(bytesio *self, PyObject *arg)
/*[clinic end generated code: output=85dacb535c1e1781 input=cc7ba4a797bb1555]*/
{
Py_ssize_t size, n;
PyObject *arg = Py_None;
CHECK_CLOSED(self);
if (!PyArg_ParseTuple(args, "|O:read", &arg))
return NULL;
if (PyLong_Check(arg)) {
size = PyLong_AsSsize_t(arg);
if (size == -1 && PyErr_Occurred())
@ -368,43 +416,44 @@ bytesio_read(bytesio *self, PyObject *args)
}
PyDoc_STRVAR(read1_doc,
"read1(size) -> read at most size bytes, returned as a bytes object.\n"
"\n"
"If the size argument is negative or omitted, read until EOF is reached.\n"
"Return an empty bytes object at EOF.");
/*[clinic input]
_io.BytesIO.read1
size: object
/
Read at most size bytes, returned as a bytes object.
If the size argument is negative or omitted, read until EOF is reached.
Return an empty bytes object at EOF.
[clinic start generated code]*/
static PyObject *
bytesio_read1(bytesio *self, PyObject *n)
_io_BytesIO_read1(bytesio *self, PyObject *size)
/*[clinic end generated code: output=16021f5d0ac3d4e2 input=d4f40bb8f2f99418]*/
{
PyObject *arg, *res;
arg = PyTuple_Pack(1, n);
if (arg == NULL)
return NULL;
res = bytesio_read(self, arg);
Py_DECREF(arg);
return res;
return _io_BytesIO_read_impl(self, size);
}
PyDoc_STRVAR(readline_doc,
"readline([size]) -> next line from the file, as a bytes object.\n"
"\n"
"Retain newline. A non-negative size argument limits the maximum\n"
"number of bytes to return (an incomplete line may be returned then).\n"
"Return an empty bytes object at EOF.\n");
/*[clinic input]
_io.BytesIO.readline
size as arg: object = None
/
Next line from the file, as a bytes object.
Retain newline. A non-negative size argument limits the maximum
number of bytes to return (an incomplete line may be returned then).
Return an empty bytes object at EOF.
[clinic start generated code]*/
static PyObject *
bytesio_readline(bytesio *self, PyObject *args)
_io_BytesIO_readline_impl(bytesio *self, PyObject *arg)
/*[clinic end generated code: output=1c2115534a4f9276 input=ca31f06de6eab257]*/
{
Py_ssize_t size, n;
PyObject *arg = Py_None;
CHECK_CLOSED(self);
if (!PyArg_ParseTuple(args, "|O:readline", &arg))
return NULL;
if (PyLong_Check(arg)) {
size = PyLong_AsSsize_t(arg);
if (size == -1 && PyErr_Occurred())
@ -425,26 +474,28 @@ bytesio_readline(bytesio *self, PyObject *args)
return read_bytes(self, n);
}
PyDoc_STRVAR(readlines_doc,
"readlines([size]) -> list of strings, each a line from the file.\n"
"\n"
"Call readline() repeatedly and return a list of the lines so read.\n"
"The optional size argument, if given, is an approximate bound on the\n"
"total number of bytes in the lines returned.\n");
/*[clinic input]
_io.BytesIO.readlines
size as arg: object = None
/
List of bytes objects, each a line from the file.
Call readline() repeatedly and return a list of the lines so read.
The optional size argument, if given, is an approximate bound on the
total number of bytes in the lines returned.
[clinic start generated code]*/
static PyObject *
bytesio_readlines(bytesio *self, PyObject *args)
_io_BytesIO_readlines_impl(bytesio *self, PyObject *arg)
/*[clinic end generated code: output=09b8e34c880808ff input=691aa1314f2c2a87]*/
{
Py_ssize_t maxsize, size, n;
PyObject *result, *line;
char *output;
PyObject *arg = Py_None;
CHECK_CLOSED(self);
if (!PyArg_ParseTuple(args, "|O:readlines", &arg))
return NULL;
if (PyLong_Check(arg)) {
maxsize = PyLong_AsSsize_t(arg);
if (maxsize == -1 && PyErr_Occurred())
@ -488,25 +539,27 @@ bytesio_readlines(bytesio *self, PyObject *args)
return NULL;
}
PyDoc_STRVAR(readinto_doc,
"readinto(bytearray) -> int. Read up to len(b) bytes into b.\n"
"\n"
"Returns number of bytes read (0 for EOF), or None if the object\n"
"is set not to block as has no data to read.");
/*[clinic input]
_io.BytesIO.readinto
buffer: Py_buffer(types={'rwbuffer'})
/
Read up to len(buffer) bytes into buffer.
Returns number of bytes read (0 for EOF), or None if the object
is set not to block as has no data to read.
[clinic start generated code]*/
static PyObject *
bytesio_readinto(bytesio *self, PyObject *arg)
_io_BytesIO_readinto_impl(bytesio *self, Py_buffer *buffer)
/*[clinic end generated code: output=a5d407217dcf0639 input=d289da851c7c4159]*/
{
Py_buffer buffer;
Py_ssize_t len, n;
CHECK_CLOSED(self);
if (!PyArg_Parse(arg, "w*", &buffer))
return NULL;
/* adjust invalid sizes */
len = buffer.len;
len = buffer->len;
n = self->string_size - self->pos;
if (len > n) {
len = n;
@ -514,33 +567,34 @@ bytesio_readinto(bytesio *self, PyObject *arg)
len = 0;
}
memcpy(buffer.buf, PyBytes_AS_STRING(self->buf) + self->pos, len);
memcpy(buffer->buf, PyBytes_AS_STRING(self->buf) + self->pos, len);
assert(self->pos + len < PY_SSIZE_T_MAX);
assert(len >= 0);
self->pos += len;
PyBuffer_Release(&buffer);
return PyLong_FromSsize_t(len);
}
PyDoc_STRVAR(truncate_doc,
"truncate([size]) -> int. Truncate the file to at most size bytes.\n"
"\n"
"Size defaults to the current file position, as returned by tell().\n"
"The current file position is unchanged. Returns the new size.\n");
/*[clinic input]
_io.BytesIO.truncate
size as arg: object = None
/
Truncate the file to at most size bytes.
Size defaults to the current file position, as returned by tell().
The current file position is unchanged. Returns the new size.
[clinic start generated code]*/
static PyObject *
bytesio_truncate(bytesio *self, PyObject *args)
_io_BytesIO_truncate_impl(bytesio *self, PyObject *arg)
/*[clinic end generated code: output=81e6be60e67ddd66 input=11ed1966835462ba]*/
{
Py_ssize_t size;
PyObject *arg = Py_None;
CHECK_CLOSED(self);
CHECK_EXPORTS(self);
if (!PyArg_ParseTuple(args, "|O:truncate", &arg))
return NULL;
if (PyLong_Check(arg)) {
size = PyLong_AsSsize_t(arg);
if (size == -1 && PyErr_Occurred())
@ -586,36 +640,37 @@ bytesio_iternext(bytesio *self)
return read_bytes(self, n);
}
PyDoc_STRVAR(seek_doc,
"seek(pos, whence=0) -> int. Change stream position.\n"
"\n"
"Seek to byte offset pos relative to position indicated by whence:\n"
" 0 Start of stream (the default). pos should be >= 0;\n"
" 1 Current position - pos may be negative;\n"
" 2 End of stream - pos usually negative.\n"
"Returns the new absolute position.");
/*[clinic input]
_io.BytesIO.seek
pos: Py_ssize_t
whence: int = 0
/
Change stream position.
Seek to byte offset pos relative to position indicated by whence:
0 Start of stream (the default). pos should be >= 0;
1 Current position - pos may be negative;
2 End of stream - pos usually negative.
Returns the new absolute position.
[clinic start generated code]*/
static PyObject *
bytesio_seek(bytesio *self, PyObject *args)
_io_BytesIO_seek_impl(bytesio *self, Py_ssize_t pos, int whence)
/*[clinic end generated code: output=c26204a68e9190e4 input=1e875e6ebc652948]*/
{
Py_ssize_t pos;
int mode = 0;
CHECK_CLOSED(self);
if (!PyArg_ParseTuple(args, "n|i:seek", &pos, &mode))
return NULL;
if (pos < 0 && mode == 0) {
if (pos < 0 && whence == 0) {
PyErr_Format(PyExc_ValueError,
"negative seek value %zd", pos);
return NULL;
}
/* mode 0: offset relative to beginning of the string.
mode 1: offset relative to current position.
mode 2: offset relative the end of the string. */
if (mode == 1) {
/* whence = 0: offset relative to beginning of the string.
whence = 1: offset relative to current position.
whence = 2: offset relative the end of the string. */
if (whence == 1) {
if (pos > PY_SSIZE_T_MAX - self->pos) {
PyErr_SetString(PyExc_OverflowError,
"new position too large");
@ -623,7 +678,7 @@ bytesio_seek(bytesio *self, PyObject *args)
}
pos += self->pos;
}
else if (mode == 2) {
else if (whence == 2) {
if (pos > PY_SSIZE_T_MAX - self->string_size) {
PyErr_SetString(PyExc_OverflowError,
"new position too large");
@ -631,9 +686,9 @@ bytesio_seek(bytesio *self, PyObject *args)
}
pos += self->string_size;
}
else if (mode != 0) {
else if (whence != 0) {
PyErr_Format(PyExc_ValueError,
"invalid whence (%i, should be 0, 1 or 2)", mode);
"invalid whence (%i, should be 0, 1 or 2)", whence);
return NULL;
}
@ -644,54 +699,63 @@ bytesio_seek(bytesio *self, PyObject *args)
return PyLong_FromSsize_t(self->pos);
}
PyDoc_STRVAR(write_doc,
"write(bytes) -> int. Write bytes to file.\n"
"\n"
"Return the number of bytes written.");
/*[clinic input]
_io.BytesIO.write
b: object
/
Write bytes to file.
Return the number of bytes written.
[clinic start generated code]*/
static PyObject *
bytesio_write(bytesio *self, PyObject *obj)
_io_BytesIO_write(bytesio *self, PyObject *b)
/*[clinic end generated code: output=53316d99800a0b95 input=f5ec7c8c64ed720a]*/
{
Py_ssize_t n = 0;
Py_buffer buf;
PyObject *result = NULL;
CHECK_CLOSED(self);
CHECK_EXPORTS(self);
if (PyObject_GetBuffer(obj, &buf, PyBUF_CONTIG_RO) < 0)
if (PyObject_GetBuffer(b, &buf, PyBUF_CONTIG_RO) < 0)
return NULL;
if (buf.len != 0)
n = write_bytes(self, buf.buf, buf.len);
if (n >= 0)
result = PyLong_FromSsize_t(n);
PyBuffer_Release(&buf);
return result;
return n >= 0 ? PyLong_FromSsize_t(n) : NULL;
}
PyDoc_STRVAR(writelines_doc,
"writelines(lines) -> None. Write bytes objects to the file.\n"
"\n"
"Note that newlines are not added. The argument can be any iterable\n"
"object producing bytes objects. This is equivalent to calling write() for\n"
"each bytes object.");
/*[clinic input]
_io.BytesIO.writelines
lines: object
/
Write lines to the file.
Note that newlines are not added. lines can be any iterable object
producing bytes-like objects. This is equivalent to calling write() for
each element.
[clinic start generated code]*/
static PyObject *
bytesio_writelines(bytesio *self, PyObject *v)
_io_BytesIO_writelines(bytesio *self, PyObject *lines)
/*[clinic end generated code: output=7f33aa3271c91752 input=e972539176fc8fc1]*/
{
PyObject *it, *item;
PyObject *ret;
CHECK_CLOSED(self);
it = PyObject_GetIter(v);
it = PyObject_GetIter(lines);
if (it == NULL)
return NULL;
while ((item = PyIter_Next(it)) != NULL) {
ret = bytesio_write(self, item);
ret = _io_BytesIO_write(self, item);
Py_DECREF(item);
if (ret == NULL) {
Py_DECREF(it);
@ -708,11 +772,15 @@ bytesio_writelines(bytesio *self, PyObject *v)
Py_RETURN_NONE;
}
PyDoc_STRVAR(close_doc,
"close() -> None. Disable all I/O operations.");
/*[clinic input]
_io.BytesIO.close
Disable all I/O operations.
[clinic start generated code]*/
static PyObject *
bytesio_close(bytesio *self)
_io_BytesIO_close_impl(bytesio *self)
/*[clinic end generated code: output=1471bb9411af84a0 input=37e1f55556e61f60]*/
{
CHECK_EXPORTS(self);
Py_CLEAR(self->buf);
@ -737,7 +805,7 @@ bytesio_close(bytesio *self)
static PyObject *
bytesio_getstate(bytesio *self)
{
PyObject *initvalue = bytesio_getvalue(self);
PyObject *initvalue = _io_BytesIO_getvalue_impl(self);
PyObject *dict;
PyObject *state;
@ -787,7 +855,7 @@ bytesio_setstate(bytesio *self, PyObject *state)
/* Set the value of the internal buffer. If state[0] does not support the
buffer protocol, bytesio_write will raise the appropriate TypeError. */
result = bytesio_write(self, PyTuple_GET_ITEM(state, 0));
result = _io_BytesIO_write(self, PyTuple_GET_ITEM(state, 0));
if (result == NULL)
return NULL;
Py_DECREF(result);
@ -874,16 +942,17 @@ bytesio_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
return (PyObject *)self;
}
/*[clinic input]
_io.BytesIO.__init__
initial_bytes as initvalue: object(c_default="NULL") = b''
Buffered I/O implementation using an in-memory bytes buffer.
[clinic start generated code]*/
static int
bytesio_init(bytesio *self, PyObject *args, PyObject *kwds)
_io_BytesIO___init___impl(bytesio *self, PyObject *initvalue)
/*[clinic end generated code: output=65c0c51e24c5b621 input=aac7f31b67bf0fb6]*/
{
char *kwlist[] = {"initial_bytes", NULL};
PyObject *initvalue = NULL;
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O:BytesIO", kwlist,
&initvalue))
return -1;
/* In case, __init__ is called multiple times. */
self->string_size = 0;
self->pos = 0;
@ -902,7 +971,7 @@ bytesio_init(bytesio *self, PyObject *args, PyObject *kwds)
}
else {
PyObject *res;
res = bytesio_write(self, initvalue);
res = _io_BytesIO_write(self, initvalue);
if (res == NULL)
return -1;
Py_DECREF(res);
@ -939,6 +1008,8 @@ bytesio_clear(bytesio *self)
}
#include "clinic/bytesio.c.h"
static PyGetSetDef bytesio_getsetlist[] = {
{"closed", (getter)bytesio_get_closed, NULL,
"True if the file is closed."},
@ -946,36 +1017,30 @@ static PyGetSetDef bytesio_getsetlist[] = {
};
static struct PyMethodDef bytesio_methods[] = {
{"readable", (PyCFunction)return_not_closed, METH_NOARGS, readable_doc},
{"seekable", (PyCFunction)return_not_closed, METH_NOARGS, seekable_doc},
{"writable", (PyCFunction)return_not_closed, METH_NOARGS, writable_doc},
{"close", (PyCFunction)bytesio_close, METH_NOARGS, close_doc},
{"flush", (PyCFunction)bytesio_flush, METH_NOARGS, flush_doc},
{"isatty", (PyCFunction)bytesio_isatty, METH_NOARGS, isatty_doc},
{"tell", (PyCFunction)bytesio_tell, METH_NOARGS, tell_doc},
{"write", (PyCFunction)bytesio_write, METH_O, write_doc},
{"writelines", (PyCFunction)bytesio_writelines, METH_O, writelines_doc},
{"read1", (PyCFunction)bytesio_read1, METH_O, read1_doc},
{"readinto", (PyCFunction)bytesio_readinto, METH_O, readinto_doc},
{"readline", (PyCFunction)bytesio_readline, METH_VARARGS, readline_doc},
{"readlines", (PyCFunction)bytesio_readlines, METH_VARARGS, readlines_doc},
{"read", (PyCFunction)bytesio_read, METH_VARARGS, read_doc},
{"getbuffer", (PyCFunction)bytesio_getbuffer, METH_NOARGS, getbuffer_doc},
{"getvalue", (PyCFunction)bytesio_getvalue, METH_NOARGS, getval_doc},
{"seek", (PyCFunction)bytesio_seek, METH_VARARGS, seek_doc},
{"truncate", (PyCFunction)bytesio_truncate, METH_VARARGS, truncate_doc},
_IO_BYTESIO_READABLE_METHODDEF
_IO_BYTESIO_SEEKABLE_METHODDEF
_IO_BYTESIO_WRITABLE_METHODDEF
_IO_BYTESIO_CLOSE_METHODDEF
_IO_BYTESIO_FLUSH_METHODDEF
_IO_BYTESIO_ISATTY_METHODDEF
_IO_BYTESIO_TELL_METHODDEF
_IO_BYTESIO_WRITE_METHODDEF
_IO_BYTESIO_WRITELINES_METHODDEF
_IO_BYTESIO_READ1_METHODDEF
_IO_BYTESIO_READINTO_METHODDEF
_IO_BYTESIO_READLINE_METHODDEF
_IO_BYTESIO_READLINES_METHODDEF
_IO_BYTESIO_READ_METHODDEF
_IO_BYTESIO_GETBUFFER_METHODDEF
_IO_BYTESIO_GETVALUE_METHODDEF
_IO_BYTESIO_SEEK_METHODDEF
_IO_BYTESIO_TRUNCATE_METHODDEF
{"__getstate__", (PyCFunction)bytesio_getstate, METH_NOARGS, NULL},
{"__setstate__", (PyCFunction)bytesio_setstate, METH_O, NULL},
{"__sizeof__", (PyCFunction)bytesio_sizeof, METH_NOARGS, NULL},
{NULL, NULL} /* sentinel */
};
PyDoc_STRVAR(bytesio_doc,
"BytesIO([buffer]) -> object\n"
"\n"
"Create a buffered I/O implementation using an in-memory bytes\n"
"buffer, ready for reading and writing.");
PyTypeObject PyBytesIO_Type = {
PyVarObject_HEAD_INIT(NULL, 0)
"_io.BytesIO", /*tp_name*/
@ -998,7 +1063,7 @@ PyTypeObject PyBytesIO_Type = {
0, /*tp_as_buffer*/
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE |
Py_TPFLAGS_HAVE_GC, /*tp_flags*/
bytesio_doc, /*tp_doc*/
_io_BytesIO___init____doc__, /*tp_doc*/
(traverseproc)bytesio_traverse, /*tp_traverse*/
(inquiry)bytesio_clear, /*tp_clear*/
0, /*tp_richcompare*/
@ -1013,7 +1078,7 @@ PyTypeObject PyBytesIO_Type = {
0, /*tp_descr_get*/
0, /*tp_descr_set*/
offsetof(bytesio, dict), /*tp_dictoffset*/
(initproc)bytesio_init, /*tp_init*/
_io_BytesIO___init__, /*tp_init*/
0, /*tp_alloc*/
bytesio_new, /*tp_new*/
};

View File

@ -0,0 +1,160 @@
/*[clinic input]
preserve
[clinic start generated code]*/
PyDoc_STRVAR(_io_open__doc__,
"open($module, /, file, mode=\'r\', buffering=-1, encoding=None,\n"
" errors=None, newline=None, closefd=True, opener=None)\n"
"--\n"
"\n"
"Open file and return a stream. Raise IOError upon failure.\n"
"\n"
"file is either a text or byte string giving the name (and the path\n"
"if the file isn\'t in the current working directory) of the file to\n"
"be opened or an integer file descriptor of the file to be\n"
"wrapped. (If a file descriptor is given, it is closed when the\n"
"returned I/O object is closed, unless closefd is set to False.)\n"
"\n"
"mode is an optional string that specifies the mode in which the file\n"
"is opened. It defaults to \'r\' which means open for reading in text\n"
"mode. Other common values are \'w\' for writing (truncating the file if\n"
"it already exists), \'x\' for creating and writing to a new file, and\n"
"\'a\' for appending (which on some Unix systems, means that all writes\n"
"append to the end of the file regardless of the current seek position).\n"
"In text mode, if encoding is not specified the encoding used is platform\n"
"dependent: locale.getpreferredencoding(False) is called to get the\n"
"current locale encoding. (For reading and writing raw bytes use binary\n"
"mode and leave encoding unspecified.) The available modes are:\n"
"\n"
"========= ===============================================================\n"
"Character Meaning\n"
"--------- ---------------------------------------------------------------\n"
"\'r\' open for reading (default)\n"
"\'w\' open for writing, truncating the file first\n"
"\'x\' create a new file and open it for writing\n"
"\'a\' open for writing, appending to the end of the file if it exists\n"
"\'b\' binary mode\n"
"\'t\' text mode (default)\n"
"\'+\' open a disk file for updating (reading and writing)\n"
"\'U\' universal newline mode (deprecated)\n"
"========= ===============================================================\n"
"\n"
"The default mode is \'rt\' (open for reading text). For binary random\n"
"access, the mode \'w+b\' opens and truncates the file to 0 bytes, while\n"
"\'r+b\' opens the file without truncation. The \'x\' mode implies \'w\' and\n"
"raises an `FileExistsError` if the file already exists.\n"
"\n"
"Python distinguishes between files opened in binary and text modes,\n"
"even when the underlying operating system doesn\'t. Files opened in\n"
"binary mode (appending \'b\' to the mode argument) return contents as\n"
"bytes objects without any decoding. In text mode (the default, or when\n"
"\'t\' is appended to the mode argument), the contents of the file are\n"
"returned as strings, the bytes having been first decoded using a\n"
"platform-dependent encoding or using the specified encoding if given.\n"
"\n"
"\'U\' mode is deprecated and will raise an exception in future versions\n"
"of Python. It has no effect in Python 3. Use newline to control\n"
"universal newlines mode.\n"
"\n"
"buffering is an optional integer used to set the buffering policy.\n"
"Pass 0 to switch buffering off (only allowed in binary mode), 1 to select\n"
"line buffering (only usable in text mode), and an integer > 1 to indicate\n"
"the size of a fixed-size chunk buffer. When no buffering argument is\n"
"given, the default buffering policy works as follows:\n"
"\n"
"* Binary files are buffered in fixed-size chunks; the size of the buffer\n"
" is chosen using a heuristic trying to determine the underlying device\'s\n"
" \"block size\" and falling back on `io.DEFAULT_BUFFER_SIZE`.\n"
" On many systems, the buffer will typically be 4096 or 8192 bytes long.\n"
"\n"
"* \"Interactive\" text files (files for which isatty() returns True)\n"
" use line buffering. Other text files use the policy described above\n"
" for binary files.\n"
"\n"
"encoding is the name of the encoding used to decode or encode the\n"
"file. This should only be used in text mode. The default encoding is\n"
"platform dependent, but any encoding supported by Python can be\n"
"passed. See the codecs module for the list of supported encodings.\n"
"\n"
"errors is an optional string that specifies how encoding errors are to\n"
"be handled---this argument should not be used in binary mode. Pass\n"
"\'strict\' to raise a ValueError exception if there is an encoding error\n"
"(the default of None has the same effect), or pass \'ignore\' to ignore\n"
"errors. (Note that ignoring encoding errors can lead to data loss.)\n"
"See the documentation for codecs.register or run \'help(codecs.Codec)\'\n"
"for a list of the permitted encoding error strings.\n"
"\n"
"newline controls how universal newlines works (it only applies to text\n"
"mode). It can be None, \'\', \'\\n\', \'\\r\', and \'\\r\\n\'. It works as\n"
"follows:\n"
"\n"
"* On input, if newline is None, universal newlines mode is\n"
" enabled. Lines in the input can end in \'\\n\', \'\\r\', or \'\\r\\n\', and\n"
" these are translated into \'\\n\' before being returned to the\n"
" caller. If it is \'\', universal newline mode is enabled, but line\n"
" endings are returned to the caller untranslated. If it has any of\n"
" the other legal values, input lines are only terminated by the given\n"
" string, and the line ending is returned to the caller untranslated.\n"
"\n"
"* On output, if newline is None, any \'\\n\' characters written are\n"
" translated to the system default line separator, os.linesep. If\n"
" newline is \'\' or \'\\n\', no translation takes place. If newline is any\n"
" of the other legal values, any \'\\n\' characters written are translated\n"
" to the given string.\n"
"\n"
"If closefd is False, the underlying file descriptor will be kept open\n"
"when the file is closed. This does not work when a file name is given\n"
"and must be True in that case.\n"
"\n"
"A custom opener can be used by passing a callable as *opener*. The\n"
"underlying file descriptor for the file object is then obtained by\n"
"calling *opener* with (*file*, *flags*). *opener* must return an open\n"
"file descriptor (passing os.open as *opener* results in functionality\n"
"similar to passing None).\n"
"\n"
"open() returns a file object whose type depends on the mode, and\n"
"through which the standard file operations such as reading and writing\n"
"are performed. When open() is used to open a file in a text mode (\'w\',\n"
"\'r\', \'wt\', \'rt\', etc.), it returns a TextIOWrapper. When used to open\n"
"a file in a binary mode, the returned class varies: in read binary\n"
"mode, it returns a BufferedReader; in write binary and append binary\n"
"modes, it returns a BufferedWriter, and in read/write mode, it returns\n"
"a BufferedRandom.\n"
"\n"
"It is also possible to use a string or bytearray as a file for both\n"
"reading and writing. For strings StringIO can be used like a file\n"
"opened in a text mode, and for bytes a BytesIO can be used like a file\n"
"opened in a binary mode.");
#define _IO_OPEN_METHODDEF \
{"open", (PyCFunction)_io_open, METH_VARARGS|METH_KEYWORDS, _io_open__doc__},
static PyObject *
_io_open_impl(PyModuleDef *module, PyObject *file, const char *mode,
int buffering, const char *encoding, const char *errors,
const char *newline, int closefd, PyObject *opener);
static PyObject *
_io_open(PyModuleDef *module, PyObject *args, PyObject *kwargs)
{
PyObject *return_value = NULL;
static char *_keywords[] = {"file", "mode", "buffering", "encoding", "errors", "newline", "closefd", "opener", NULL};
PyObject *file;
const char *mode = "r";
int buffering = -1;
const char *encoding = NULL;
const char *errors = NULL;
const char *newline = NULL;
int closefd = 1;
PyObject *opener = Py_None;
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"O|sizzziO:open", _keywords,
&file, &mode, &buffering, &encoding, &errors, &newline, &closefd, &opener))
goto exit;
return_value = _io_open_impl(module, file, mode, buffering, encoding, errors, newline, closefd, opener);
exit:
return return_value;
}
/*[clinic end generated code: output=c51a5a443c11f02b input=a9049054013a1b77]*/

View File

@ -0,0 +1,474 @@
/*[clinic input]
preserve
[clinic start generated code]*/
PyDoc_STRVAR(_io__BufferedIOBase_readinto__doc__,
"readinto($self, buffer, /)\n"
"--\n"
"\n");
#define _IO__BUFFEREDIOBASE_READINTO_METHODDEF \
{"readinto", (PyCFunction)_io__BufferedIOBase_readinto, METH_O, _io__BufferedIOBase_readinto__doc__},
static PyObject *
_io__BufferedIOBase_readinto_impl(PyObject *self, Py_buffer *buffer);
static PyObject *
_io__BufferedIOBase_readinto(PyObject *self, PyObject *arg)
{
PyObject *return_value = NULL;
Py_buffer buffer = {NULL, NULL};
if (!PyArg_Parse(arg,
"w*:readinto",
&buffer))
goto exit;
return_value = _io__BufferedIOBase_readinto_impl(self, &buffer);
exit:
/* Cleanup for buffer */
if (buffer.obj)
PyBuffer_Release(&buffer);
return return_value;
}
PyDoc_STRVAR(_io__BufferedIOBase_readinto1__doc__,
"readinto1($self, buffer, /)\n"
"--\n"
"\n");
#define _IO__BUFFEREDIOBASE_READINTO1_METHODDEF \
{"readinto1", (PyCFunction)_io__BufferedIOBase_readinto1, METH_O, _io__BufferedIOBase_readinto1__doc__},
static PyObject *
_io__BufferedIOBase_readinto1_impl(PyObject *self, Py_buffer *buffer);
static PyObject *
_io__BufferedIOBase_readinto1(PyObject *self, PyObject *arg)
{
PyObject *return_value = NULL;
Py_buffer buffer = {NULL, NULL};
if (!PyArg_Parse(arg,
"w*:readinto1",
&buffer))
goto exit;
return_value = _io__BufferedIOBase_readinto1_impl(self, &buffer);
exit:
/* Cleanup for buffer */
if (buffer.obj)
PyBuffer_Release(&buffer);
return return_value;
}
PyDoc_STRVAR(_io__BufferedIOBase_detach__doc__,
"detach($self, /)\n"
"--\n"
"\n"
"Disconnect this buffer from its underlying raw stream and return it.\n"
"\n"
"After the raw stream has been detached, the buffer is in an unusable\n"
"state.");
#define _IO__BUFFEREDIOBASE_DETACH_METHODDEF \
{"detach", (PyCFunction)_io__BufferedIOBase_detach, METH_NOARGS, _io__BufferedIOBase_detach__doc__},
static PyObject *
_io__BufferedIOBase_detach_impl(PyObject *self);
static PyObject *
_io__BufferedIOBase_detach(PyObject *self, PyObject *Py_UNUSED(ignored))
{
return _io__BufferedIOBase_detach_impl(self);
}
PyDoc_STRVAR(_io__Buffered_peek__doc__,
"peek($self, size=0, /)\n"
"--\n"
"\n");
#define _IO__BUFFERED_PEEK_METHODDEF \
{"peek", (PyCFunction)_io__Buffered_peek, METH_VARARGS, _io__Buffered_peek__doc__},
static PyObject *
_io__Buffered_peek_impl(buffered *self, Py_ssize_t size);
static PyObject *
_io__Buffered_peek(buffered *self, PyObject *args)
{
PyObject *return_value = NULL;
Py_ssize_t size = 0;
if (!PyArg_ParseTuple(args,
"|n:peek",
&size))
goto exit;
return_value = _io__Buffered_peek_impl(self, size);
exit:
return return_value;
}
PyDoc_STRVAR(_io__Buffered_read__doc__,
"read($self, size=-1, /)\n"
"--\n"
"\n");
#define _IO__BUFFERED_READ_METHODDEF \
{"read", (PyCFunction)_io__Buffered_read, METH_VARARGS, _io__Buffered_read__doc__},
static PyObject *
_io__Buffered_read_impl(buffered *self, Py_ssize_t n);
static PyObject *
_io__Buffered_read(buffered *self, PyObject *args)
{
PyObject *return_value = NULL;
Py_ssize_t n = -1;
if (!PyArg_ParseTuple(args,
"|O&:read",
_PyIO_ConvertSsize_t, &n))
goto exit;
return_value = _io__Buffered_read_impl(self, n);
exit:
return return_value;
}
PyDoc_STRVAR(_io__Buffered_read1__doc__,
"read1($self, size, /)\n"
"--\n"
"\n");
#define _IO__BUFFERED_READ1_METHODDEF \
{"read1", (PyCFunction)_io__Buffered_read1, METH_O, _io__Buffered_read1__doc__},
static PyObject *
_io__Buffered_read1_impl(buffered *self, Py_ssize_t n);
static PyObject *
_io__Buffered_read1(buffered *self, PyObject *arg)
{
PyObject *return_value = NULL;
Py_ssize_t n;
if (!PyArg_Parse(arg,
"n:read1",
&n))
goto exit;
return_value = _io__Buffered_read1_impl(self, n);
exit:
return return_value;
}
PyDoc_STRVAR(_io__Buffered_readinto__doc__,
"readinto($self, buffer, /)\n"
"--\n"
"\n");
#define _IO__BUFFERED_READINTO_METHODDEF \
{"readinto", (PyCFunction)_io__Buffered_readinto, METH_O, _io__Buffered_readinto__doc__},
static PyObject *
_io__Buffered_readinto_impl(buffered *self, Py_buffer *buffer);
static PyObject *
_io__Buffered_readinto(buffered *self, PyObject *arg)
{
PyObject *return_value = NULL;
Py_buffer buffer = {NULL, NULL};
if (!PyArg_Parse(arg,
"w*:readinto",
&buffer))
goto exit;
return_value = _io__Buffered_readinto_impl(self, &buffer);
exit:
/* Cleanup for buffer */
if (buffer.obj)
PyBuffer_Release(&buffer);
return return_value;
}
PyDoc_STRVAR(_io__Buffered_readinto1__doc__,
"readinto1($self, buffer, /)\n"
"--\n"
"\n");
#define _IO__BUFFERED_READINTO1_METHODDEF \
{"readinto1", (PyCFunction)_io__Buffered_readinto1, METH_O, _io__Buffered_readinto1__doc__},
static PyObject *
_io__Buffered_readinto1_impl(buffered *self, Py_buffer *buffer);
static PyObject *
_io__Buffered_readinto1(buffered *self, PyObject *arg)
{
PyObject *return_value = NULL;
Py_buffer buffer = {NULL, NULL};
if (!PyArg_Parse(arg,
"w*:readinto1",
&buffer))
goto exit;
return_value = _io__Buffered_readinto1_impl(self, &buffer);
exit:
/* Cleanup for buffer */
if (buffer.obj)
PyBuffer_Release(&buffer);
return return_value;
}
PyDoc_STRVAR(_io__Buffered_readline__doc__,
"readline($self, size=-1, /)\n"
"--\n"
"\n");
#define _IO__BUFFERED_READLINE_METHODDEF \
{"readline", (PyCFunction)_io__Buffered_readline, METH_VARARGS, _io__Buffered_readline__doc__},
static PyObject *
_io__Buffered_readline_impl(buffered *self, Py_ssize_t size);
static PyObject *
_io__Buffered_readline(buffered *self, PyObject *args)
{
PyObject *return_value = NULL;
Py_ssize_t size = -1;
if (!PyArg_ParseTuple(args,
"|O&:readline",
_PyIO_ConvertSsize_t, &size))
goto exit;
return_value = _io__Buffered_readline_impl(self, size);
exit:
return return_value;
}
PyDoc_STRVAR(_io__Buffered_seek__doc__,
"seek($self, target, whence=0, /)\n"
"--\n"
"\n");
#define _IO__BUFFERED_SEEK_METHODDEF \
{"seek", (PyCFunction)_io__Buffered_seek, METH_VARARGS, _io__Buffered_seek__doc__},
static PyObject *
_io__Buffered_seek_impl(buffered *self, PyObject *targetobj, int whence);
static PyObject *
_io__Buffered_seek(buffered *self, PyObject *args)
{
PyObject *return_value = NULL;
PyObject *targetobj;
int whence = 0;
if (!PyArg_ParseTuple(args,
"O|i:seek",
&targetobj, &whence))
goto exit;
return_value = _io__Buffered_seek_impl(self, targetobj, whence);
exit:
return return_value;
}
PyDoc_STRVAR(_io__Buffered_truncate__doc__,
"truncate($self, pos=None, /)\n"
"--\n"
"\n");
#define _IO__BUFFERED_TRUNCATE_METHODDEF \
{"truncate", (PyCFunction)_io__Buffered_truncate, METH_VARARGS, _io__Buffered_truncate__doc__},
static PyObject *
_io__Buffered_truncate_impl(buffered *self, PyObject *pos);
static PyObject *
_io__Buffered_truncate(buffered *self, PyObject *args)
{
PyObject *return_value = NULL;
PyObject *pos = Py_None;
if (!PyArg_UnpackTuple(args, "truncate",
0, 1,
&pos))
goto exit;
return_value = _io__Buffered_truncate_impl(self, pos);
exit:
return return_value;
}
PyDoc_STRVAR(_io_BufferedReader___init____doc__,
"BufferedReader(raw, buffer_size=DEFAULT_BUFFER_SIZE)\n"
"--\n"
"\n"
"Create a new buffered reader using the given readable raw IO object.");
static int
_io_BufferedReader___init___impl(buffered *self, PyObject *raw,
Py_ssize_t buffer_size);
static int
_io_BufferedReader___init__(PyObject *self, PyObject *args, PyObject *kwargs)
{
int return_value = -1;
static char *_keywords[] = {"raw", "buffer_size", NULL};
PyObject *raw;
Py_ssize_t buffer_size = DEFAULT_BUFFER_SIZE;
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"O|n:BufferedReader", _keywords,
&raw, &buffer_size))
goto exit;
return_value = _io_BufferedReader___init___impl((buffered *)self, raw, buffer_size);
exit:
return return_value;
}
PyDoc_STRVAR(_io_BufferedWriter___init____doc__,
"BufferedWriter(raw, buffer_size=DEFAULT_BUFFER_SIZE)\n"
"--\n"
"\n"
"A buffer for a writeable sequential RawIO object.\n"
"\n"
"The constructor creates a BufferedWriter for the given writeable raw\n"
"stream. If the buffer_size is not given, it defaults to\n"
"DEFAULT_BUFFER_SIZE.");
static int
_io_BufferedWriter___init___impl(buffered *self, PyObject *raw,
Py_ssize_t buffer_size);
static int
_io_BufferedWriter___init__(PyObject *self, PyObject *args, PyObject *kwargs)
{
int return_value = -1;
static char *_keywords[] = {"raw", "buffer_size", NULL};
PyObject *raw;
Py_ssize_t buffer_size = DEFAULT_BUFFER_SIZE;
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"O|n:BufferedWriter", _keywords,
&raw, &buffer_size))
goto exit;
return_value = _io_BufferedWriter___init___impl((buffered *)self, raw, buffer_size);
exit:
return return_value;
}
PyDoc_STRVAR(_io_BufferedWriter_write__doc__,
"write($self, buffer, /)\n"
"--\n"
"\n");
#define _IO_BUFFEREDWRITER_WRITE_METHODDEF \
{"write", (PyCFunction)_io_BufferedWriter_write, METH_O, _io_BufferedWriter_write__doc__},
static PyObject *
_io_BufferedWriter_write_impl(buffered *self, Py_buffer *buffer);
static PyObject *
_io_BufferedWriter_write(buffered *self, PyObject *arg)
{
PyObject *return_value = NULL;
Py_buffer buffer = {NULL, NULL};
if (!PyArg_Parse(arg,
"y*:write",
&buffer))
goto exit;
return_value = _io_BufferedWriter_write_impl(self, &buffer);
exit:
/* Cleanup for buffer */
if (buffer.obj)
PyBuffer_Release(&buffer);
return return_value;
}
PyDoc_STRVAR(_io_BufferedRWPair___init____doc__,
"BufferedRWPair(reader, writer, buffer_size=DEFAULT_BUFFER_SIZE, /)\n"
"--\n"
"\n"
"A buffered reader and writer object together.\n"
"\n"
"A buffered reader object and buffered writer object put together to\n"
"form a sequential IO object that can read and write. This is typically\n"
"used with a socket or two-way pipe.\n"
"\n"
"reader and writer are RawIOBase objects that are readable and\n"
"writeable respectively. If the buffer_size is omitted it defaults to\n"
"DEFAULT_BUFFER_SIZE.");
static int
_io_BufferedRWPair___init___impl(rwpair *self, PyObject *reader,
PyObject *writer, Py_ssize_t buffer_size);
static int
_io_BufferedRWPair___init__(PyObject *self, PyObject *args, PyObject *kwargs)
{
int return_value = -1;
PyObject *reader;
PyObject *writer;
Py_ssize_t buffer_size = DEFAULT_BUFFER_SIZE;
if ((Py_TYPE(self) == &PyBufferedRWPair_Type) &&
!_PyArg_NoKeywords("BufferedRWPair", kwargs))
goto exit;
if (!PyArg_ParseTuple(args,
"OO|n:BufferedRWPair",
&reader, &writer, &buffer_size))
goto exit;
return_value = _io_BufferedRWPair___init___impl((rwpair *)self, reader, writer, buffer_size);
exit:
return return_value;
}
PyDoc_STRVAR(_io_BufferedRandom___init____doc__,
"BufferedRandom(raw, buffer_size=DEFAULT_BUFFER_SIZE)\n"
"--\n"
"\n"
"A buffered interface to random access streams.\n"
"\n"
"The constructor creates a reader and writer for a seekable stream,\n"
"raw, given in the first argument. If the buffer_size is omitted it\n"
"defaults to DEFAULT_BUFFER_SIZE.");
static int
_io_BufferedRandom___init___impl(buffered *self, PyObject *raw,
Py_ssize_t buffer_size);
static int
_io_BufferedRandom___init__(PyObject *self, PyObject *args, PyObject *kwargs)
{
int return_value = -1;
static char *_keywords[] = {"raw", "buffer_size", NULL};
PyObject *raw;
Py_ssize_t buffer_size = DEFAULT_BUFFER_SIZE;
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"O|n:BufferedRandom", _keywords,
&raw, &buffer_size))
goto exit;
return_value = _io_BufferedRandom___init___impl((buffered *)self, raw, buffer_size);
exit:
return return_value;
}
/*[clinic end generated code: output=78808e39f36e3fa9 input=a9049054013a1b77]*/

View File

@ -0,0 +1,426 @@
/*[clinic input]
preserve
[clinic start generated code]*/
PyDoc_STRVAR(_io_BytesIO_readable__doc__,
"readable($self, /)\n"
"--\n"
"\n"
"Returns True if the IO object can be read.");
#define _IO_BYTESIO_READABLE_METHODDEF \
{"readable", (PyCFunction)_io_BytesIO_readable, METH_NOARGS, _io_BytesIO_readable__doc__},
static PyObject *
_io_BytesIO_readable_impl(bytesio *self);
static PyObject *
_io_BytesIO_readable(bytesio *self, PyObject *Py_UNUSED(ignored))
{
return _io_BytesIO_readable_impl(self);
}
PyDoc_STRVAR(_io_BytesIO_writable__doc__,
"writable($self, /)\n"
"--\n"
"\n"
"Returns True if the IO object can be written.");
#define _IO_BYTESIO_WRITABLE_METHODDEF \
{"writable", (PyCFunction)_io_BytesIO_writable, METH_NOARGS, _io_BytesIO_writable__doc__},
static PyObject *
_io_BytesIO_writable_impl(bytesio *self);
static PyObject *
_io_BytesIO_writable(bytesio *self, PyObject *Py_UNUSED(ignored))
{
return _io_BytesIO_writable_impl(self);
}
PyDoc_STRVAR(_io_BytesIO_seekable__doc__,
"seekable($self, /)\n"
"--\n"
"\n"
"Returns True if the IO object can be seeked.");
#define _IO_BYTESIO_SEEKABLE_METHODDEF \
{"seekable", (PyCFunction)_io_BytesIO_seekable, METH_NOARGS, _io_BytesIO_seekable__doc__},
static PyObject *
_io_BytesIO_seekable_impl(bytesio *self);
static PyObject *
_io_BytesIO_seekable(bytesio *self, PyObject *Py_UNUSED(ignored))
{
return _io_BytesIO_seekable_impl(self);
}
PyDoc_STRVAR(_io_BytesIO_flush__doc__,
"flush($self, /)\n"
"--\n"
"\n"
"Does nothing.");
#define _IO_BYTESIO_FLUSH_METHODDEF \
{"flush", (PyCFunction)_io_BytesIO_flush, METH_NOARGS, _io_BytesIO_flush__doc__},
static PyObject *
_io_BytesIO_flush_impl(bytesio *self);
static PyObject *
_io_BytesIO_flush(bytesio *self, PyObject *Py_UNUSED(ignored))
{
return _io_BytesIO_flush_impl(self);
}
PyDoc_STRVAR(_io_BytesIO_getbuffer__doc__,
"getbuffer($self, /)\n"
"--\n"
"\n"
"Get a read-write view over the contents of the BytesIO object.");
#define _IO_BYTESIO_GETBUFFER_METHODDEF \
{"getbuffer", (PyCFunction)_io_BytesIO_getbuffer, METH_NOARGS, _io_BytesIO_getbuffer__doc__},
static PyObject *
_io_BytesIO_getbuffer_impl(bytesio *self);
static PyObject *
_io_BytesIO_getbuffer(bytesio *self, PyObject *Py_UNUSED(ignored))
{
return _io_BytesIO_getbuffer_impl(self);
}
PyDoc_STRVAR(_io_BytesIO_getvalue__doc__,
"getvalue($self, /)\n"
"--\n"
"\n"
"Retrieve the entire contents of the BytesIO object.");
#define _IO_BYTESIO_GETVALUE_METHODDEF \
{"getvalue", (PyCFunction)_io_BytesIO_getvalue, METH_NOARGS, _io_BytesIO_getvalue__doc__},
static PyObject *
_io_BytesIO_getvalue_impl(bytesio *self);
static PyObject *
_io_BytesIO_getvalue(bytesio *self, PyObject *Py_UNUSED(ignored))
{
return _io_BytesIO_getvalue_impl(self);
}
PyDoc_STRVAR(_io_BytesIO_isatty__doc__,
"isatty($self, /)\n"
"--\n"
"\n"
"Always returns False.\n"
"\n"
"BytesIO objects are not connected to a TTY-like device.");
#define _IO_BYTESIO_ISATTY_METHODDEF \
{"isatty", (PyCFunction)_io_BytesIO_isatty, METH_NOARGS, _io_BytesIO_isatty__doc__},
static PyObject *
_io_BytesIO_isatty_impl(bytesio *self);
static PyObject *
_io_BytesIO_isatty(bytesio *self, PyObject *Py_UNUSED(ignored))
{
return _io_BytesIO_isatty_impl(self);
}
PyDoc_STRVAR(_io_BytesIO_tell__doc__,
"tell($self, /)\n"
"--\n"
"\n"
"Current file position, an integer.");
#define _IO_BYTESIO_TELL_METHODDEF \
{"tell", (PyCFunction)_io_BytesIO_tell, METH_NOARGS, _io_BytesIO_tell__doc__},
static PyObject *
_io_BytesIO_tell_impl(bytesio *self);
static PyObject *
_io_BytesIO_tell(bytesio *self, PyObject *Py_UNUSED(ignored))
{
return _io_BytesIO_tell_impl(self);
}
PyDoc_STRVAR(_io_BytesIO_read__doc__,
"read($self, size=None, /)\n"
"--\n"
"\n"
"Read at most size bytes, returned as a bytes object.\n"
"\n"
"If the size argument is negative, read until EOF is reached.\n"
"Return an empty bytes object at EOF.");
#define _IO_BYTESIO_READ_METHODDEF \
{"read", (PyCFunction)_io_BytesIO_read, METH_VARARGS, _io_BytesIO_read__doc__},
static PyObject *
_io_BytesIO_read_impl(bytesio *self, PyObject *arg);
static PyObject *
_io_BytesIO_read(bytesio *self, PyObject *args)
{
PyObject *return_value = NULL;
PyObject *arg = Py_None;
if (!PyArg_UnpackTuple(args, "read",
0, 1,
&arg))
goto exit;
return_value = _io_BytesIO_read_impl(self, arg);
exit:
return return_value;
}
PyDoc_STRVAR(_io_BytesIO_read1__doc__,
"read1($self, size, /)\n"
"--\n"
"\n"
"Read at most size bytes, returned as a bytes object.\n"
"\n"
"If the size argument is negative or omitted, read until EOF is reached.\n"
"Return an empty bytes object at EOF.");
#define _IO_BYTESIO_READ1_METHODDEF \
{"read1", (PyCFunction)_io_BytesIO_read1, METH_O, _io_BytesIO_read1__doc__},
PyDoc_STRVAR(_io_BytesIO_readline__doc__,
"readline($self, size=None, /)\n"
"--\n"
"\n"
"Next line from the file, as a bytes object.\n"
"\n"
"Retain newline. A non-negative size argument limits the maximum\n"
"number of bytes to return (an incomplete line may be returned then).\n"
"Return an empty bytes object at EOF.");
#define _IO_BYTESIO_READLINE_METHODDEF \
{"readline", (PyCFunction)_io_BytesIO_readline, METH_VARARGS, _io_BytesIO_readline__doc__},
static PyObject *
_io_BytesIO_readline_impl(bytesio *self, PyObject *arg);
static PyObject *
_io_BytesIO_readline(bytesio *self, PyObject *args)
{
PyObject *return_value = NULL;
PyObject *arg = Py_None;
if (!PyArg_UnpackTuple(args, "readline",
0, 1,
&arg))
goto exit;
return_value = _io_BytesIO_readline_impl(self, arg);
exit:
return return_value;
}
PyDoc_STRVAR(_io_BytesIO_readlines__doc__,
"readlines($self, size=None, /)\n"
"--\n"
"\n"
"List of bytes objects, each a line from the file.\n"
"\n"
"Call readline() repeatedly and return a list of the lines so read.\n"
"The optional size argument, if given, is an approximate bound on the\n"
"total number of bytes in the lines returned.");
#define _IO_BYTESIO_READLINES_METHODDEF \
{"readlines", (PyCFunction)_io_BytesIO_readlines, METH_VARARGS, _io_BytesIO_readlines__doc__},
static PyObject *
_io_BytesIO_readlines_impl(bytesio *self, PyObject *arg);
static PyObject *
_io_BytesIO_readlines(bytesio *self, PyObject *args)
{
PyObject *return_value = NULL;
PyObject *arg = Py_None;
if (!PyArg_UnpackTuple(args, "readlines",
0, 1,
&arg))
goto exit;
return_value = _io_BytesIO_readlines_impl(self, arg);
exit:
return return_value;
}
PyDoc_STRVAR(_io_BytesIO_readinto__doc__,
"readinto($self, buffer, /)\n"
"--\n"
"\n"
"Read up to len(buffer) bytes into buffer.\n"
"\n"
"Returns number of bytes read (0 for EOF), or None if the object\n"
"is set not to block as has no data to read.");
#define _IO_BYTESIO_READINTO_METHODDEF \
{"readinto", (PyCFunction)_io_BytesIO_readinto, METH_O, _io_BytesIO_readinto__doc__},
static PyObject *
_io_BytesIO_readinto_impl(bytesio *self, Py_buffer *buffer);
static PyObject *
_io_BytesIO_readinto(bytesio *self, PyObject *arg)
{
PyObject *return_value = NULL;
Py_buffer buffer = {NULL, NULL};
if (!PyArg_Parse(arg,
"w*:readinto",
&buffer))
goto exit;
return_value = _io_BytesIO_readinto_impl(self, &buffer);
exit:
/* Cleanup for buffer */
if (buffer.obj)
PyBuffer_Release(&buffer);
return return_value;
}
PyDoc_STRVAR(_io_BytesIO_truncate__doc__,
"truncate($self, size=None, /)\n"
"--\n"
"\n"
"Truncate the file to at most size bytes.\n"
"\n"
"Size defaults to the current file position, as returned by tell().\n"
"The current file position is unchanged. Returns the new size.");
#define _IO_BYTESIO_TRUNCATE_METHODDEF \
{"truncate", (PyCFunction)_io_BytesIO_truncate, METH_VARARGS, _io_BytesIO_truncate__doc__},
static PyObject *
_io_BytesIO_truncate_impl(bytesio *self, PyObject *arg);
static PyObject *
_io_BytesIO_truncate(bytesio *self, PyObject *args)
{
PyObject *return_value = NULL;
PyObject *arg = Py_None;
if (!PyArg_UnpackTuple(args, "truncate",
0, 1,
&arg))
goto exit;
return_value = _io_BytesIO_truncate_impl(self, arg);
exit:
return return_value;
}
PyDoc_STRVAR(_io_BytesIO_seek__doc__,
"seek($self, pos, whence=0, /)\n"
"--\n"
"\n"
"Change stream position.\n"
"\n"
"Seek to byte offset pos relative to position indicated by whence:\n"
" 0 Start of stream (the default). pos should be >= 0;\n"
" 1 Current position - pos may be negative;\n"
" 2 End of stream - pos usually negative.\n"
"Returns the new absolute position.");
#define _IO_BYTESIO_SEEK_METHODDEF \
{"seek", (PyCFunction)_io_BytesIO_seek, METH_VARARGS, _io_BytesIO_seek__doc__},
static PyObject *
_io_BytesIO_seek_impl(bytesio *self, Py_ssize_t pos, int whence);
static PyObject *
_io_BytesIO_seek(bytesio *self, PyObject *args)
{
PyObject *return_value = NULL;
Py_ssize_t pos;
int whence = 0;
if (!PyArg_ParseTuple(args,
"n|i:seek",
&pos, &whence))
goto exit;
return_value = _io_BytesIO_seek_impl(self, pos, whence);
exit:
return return_value;
}
PyDoc_STRVAR(_io_BytesIO_write__doc__,
"write($self, b, /)\n"
"--\n"
"\n"
"Write bytes to file.\n"
"\n"
"Return the number of bytes written.");
#define _IO_BYTESIO_WRITE_METHODDEF \
{"write", (PyCFunction)_io_BytesIO_write, METH_O, _io_BytesIO_write__doc__},
PyDoc_STRVAR(_io_BytesIO_writelines__doc__,
"writelines($self, lines, /)\n"
"--\n"
"\n"
"Write lines to the file.\n"
"\n"
"Note that newlines are not added. lines can be any iterable object\n"
"producing bytes-like objects. This is equivalent to calling write() for\n"
"each element.");
#define _IO_BYTESIO_WRITELINES_METHODDEF \
{"writelines", (PyCFunction)_io_BytesIO_writelines, METH_O, _io_BytesIO_writelines__doc__},
PyDoc_STRVAR(_io_BytesIO_close__doc__,
"close($self, /)\n"
"--\n"
"\n"
"Disable all I/O operations.");
#define _IO_BYTESIO_CLOSE_METHODDEF \
{"close", (PyCFunction)_io_BytesIO_close, METH_NOARGS, _io_BytesIO_close__doc__},
static PyObject *
_io_BytesIO_close_impl(bytesio *self);
static PyObject *
_io_BytesIO_close(bytesio *self, PyObject *Py_UNUSED(ignored))
{
return _io_BytesIO_close_impl(self);
}
PyDoc_STRVAR(_io_BytesIO___init____doc__,
"BytesIO(initial_bytes=b\'\')\n"
"--\n"
"\n"
"Buffered I/O implementation using an in-memory bytes buffer.");
static int
_io_BytesIO___init___impl(bytesio *self, PyObject *initvalue);
static int
_io_BytesIO___init__(PyObject *self, PyObject *args, PyObject *kwargs)
{
int return_value = -1;
static char *_keywords[] = {"initial_bytes", NULL};
PyObject *initvalue = NULL;
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"|O:BytesIO", _keywords,
&initvalue))
goto exit;
return_value = _io_BytesIO___init___impl((bytesio *)self, initvalue);
exit:
return return_value;
}
/*[clinic end generated code: output=e22697ada514f4eb input=a9049054013a1b77]*/

View File

@ -0,0 +1,374 @@
/*[clinic input]
preserve
[clinic start generated code]*/
PyDoc_STRVAR(_io_FileIO_close__doc__,
"close($self, /)\n"
"--\n"
"\n"
"Close the file.\n"
"\n"
"A closed file cannot be used for further I/O operations. close() may be\n"
"called more than once without error.");
#define _IO_FILEIO_CLOSE_METHODDEF \
{"close", (PyCFunction)_io_FileIO_close, METH_NOARGS, _io_FileIO_close__doc__},
static PyObject *
_io_FileIO_close_impl(fileio *self);
static PyObject *
_io_FileIO_close(fileio *self, PyObject *Py_UNUSED(ignored))
{
return _io_FileIO_close_impl(self);
}
PyDoc_STRVAR(_io_FileIO___init____doc__,
"FileIO(file, mode=\'r\', closefd=True, opener=None)\n"
"--\n"
"\n"
"Open a file.\n"
"\n"
"The mode can be \'r\' (default), \'w\', \'x\' or \'a\' for reading,\n"
"writing, exclusive creation or appending. The file will be created if it\n"
"doesn\'t exist when opened for writing or appending; it will be truncated\n"
"when opened for writing. A FileExistsError will be raised if it already\n"
"exists when opened for creating. Opening a file for creating implies\n"
"writing so this mode behaves in a similar way to \'w\'.Add a \'+\' to the mode\n"
"to allow simultaneous reading and writing. A custom opener can be used by\n"
"passing a callable as *opener*. The underlying file descriptor for the file\n"
"object is then obtained by calling opener with (*name*, *flags*).\n"
"*opener* must return an open file descriptor (passing os.open as *opener*\n"
"results in functionality similar to passing None).");
static int
_io_FileIO___init___impl(fileio *self, PyObject *nameobj, const char *mode,
int closefd, PyObject *opener);
static int
_io_FileIO___init__(PyObject *self, PyObject *args, PyObject *kwargs)
{
int return_value = -1;
static char *_keywords[] = {"file", "mode", "closefd", "opener", NULL};
PyObject *nameobj;
const char *mode = "r";
int closefd = 1;
PyObject *opener = Py_None;
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"O|siO:FileIO", _keywords,
&nameobj, &mode, &closefd, &opener))
goto exit;
return_value = _io_FileIO___init___impl((fileio *)self, nameobj, mode, closefd, opener);
exit:
return return_value;
}
PyDoc_STRVAR(_io_FileIO_fileno__doc__,
"fileno($self, /)\n"
"--\n"
"\n"
"Return the underlying file descriptor (an integer).");
#define _IO_FILEIO_FILENO_METHODDEF \
{"fileno", (PyCFunction)_io_FileIO_fileno, METH_NOARGS, _io_FileIO_fileno__doc__},
static PyObject *
_io_FileIO_fileno_impl(fileio *self);
static PyObject *
_io_FileIO_fileno(fileio *self, PyObject *Py_UNUSED(ignored))
{
return _io_FileIO_fileno_impl(self);
}
PyDoc_STRVAR(_io_FileIO_readable__doc__,
"readable($self, /)\n"
"--\n"
"\n"
"True if file was opened in a read mode.");
#define _IO_FILEIO_READABLE_METHODDEF \
{"readable", (PyCFunction)_io_FileIO_readable, METH_NOARGS, _io_FileIO_readable__doc__},
static PyObject *
_io_FileIO_readable_impl(fileio *self);
static PyObject *
_io_FileIO_readable(fileio *self, PyObject *Py_UNUSED(ignored))
{
return _io_FileIO_readable_impl(self);
}
PyDoc_STRVAR(_io_FileIO_writable__doc__,
"writable($self, /)\n"
"--\n"
"\n"
"True if file was opened in a write mode.");
#define _IO_FILEIO_WRITABLE_METHODDEF \
{"writable", (PyCFunction)_io_FileIO_writable, METH_NOARGS, _io_FileIO_writable__doc__},
static PyObject *
_io_FileIO_writable_impl(fileio *self);
static PyObject *
_io_FileIO_writable(fileio *self, PyObject *Py_UNUSED(ignored))
{
return _io_FileIO_writable_impl(self);
}
PyDoc_STRVAR(_io_FileIO_seekable__doc__,
"seekable($self, /)\n"
"--\n"
"\n"
"True if file supports random-access.");
#define _IO_FILEIO_SEEKABLE_METHODDEF \
{"seekable", (PyCFunction)_io_FileIO_seekable, METH_NOARGS, _io_FileIO_seekable__doc__},
static PyObject *
_io_FileIO_seekable_impl(fileio *self);
static PyObject *
_io_FileIO_seekable(fileio *self, PyObject *Py_UNUSED(ignored))
{
return _io_FileIO_seekable_impl(self);
}
PyDoc_STRVAR(_io_FileIO_readinto__doc__,
"readinto($self, buffer, /)\n"
"--\n"
"\n"
"Same as RawIOBase.readinto().");
#define _IO_FILEIO_READINTO_METHODDEF \
{"readinto", (PyCFunction)_io_FileIO_readinto, METH_O, _io_FileIO_readinto__doc__},
static PyObject *
_io_FileIO_readinto_impl(fileio *self, Py_buffer *buffer);
static PyObject *
_io_FileIO_readinto(fileio *self, PyObject *arg)
{
PyObject *return_value = NULL;
Py_buffer buffer = {NULL, NULL};
if (!PyArg_Parse(arg,
"w*:readinto",
&buffer))
goto exit;
return_value = _io_FileIO_readinto_impl(self, &buffer);
exit:
/* Cleanup for buffer */
if (buffer.obj)
PyBuffer_Release(&buffer);
return return_value;
}
PyDoc_STRVAR(_io_FileIO_readall__doc__,
"readall($self, /)\n"
"--\n"
"\n"
"Read all data from the file, returned as bytes.\n"
"\n"
"In non-blocking mode, returns as much as is immediately available,\n"
"or None if no data is available. Return an empty bytes object at EOF.");
#define _IO_FILEIO_READALL_METHODDEF \
{"readall", (PyCFunction)_io_FileIO_readall, METH_NOARGS, _io_FileIO_readall__doc__},
static PyObject *
_io_FileIO_readall_impl(fileio *self);
static PyObject *
_io_FileIO_readall(fileio *self, PyObject *Py_UNUSED(ignored))
{
return _io_FileIO_readall_impl(self);
}
PyDoc_STRVAR(_io_FileIO_read__doc__,
"read($self, size=-1, /)\n"
"--\n"
"\n"
"Read at most size bytes, returned as bytes.\n"
"\n"
"Only makes one system call, so less data may be returned than requested.\n"
"In non-blocking mode, returns None if no data is available.\n"
"Return an empty bytes object at EOF.");
#define _IO_FILEIO_READ_METHODDEF \
{"read", (PyCFunction)_io_FileIO_read, METH_VARARGS, _io_FileIO_read__doc__},
static PyObject *
_io_FileIO_read_impl(fileio *self, Py_ssize_t size);
static PyObject *
_io_FileIO_read(fileio *self, PyObject *args)
{
PyObject *return_value = NULL;
Py_ssize_t size = -1;
if (!PyArg_ParseTuple(args,
"|O&:read",
_PyIO_ConvertSsize_t, &size))
goto exit;
return_value = _io_FileIO_read_impl(self, size);
exit:
return return_value;
}
PyDoc_STRVAR(_io_FileIO_write__doc__,
"write($self, b, /)\n"
"--\n"
"\n"
"Write bytes b to file, return number written.\n"
"\n"
"Only makes one system call, so not all of the data may be written.\n"
"The number of bytes actually written is returned. In non-blocking mode,\n"
"returns None if the write would block.");
#define _IO_FILEIO_WRITE_METHODDEF \
{"write", (PyCFunction)_io_FileIO_write, METH_O, _io_FileIO_write__doc__},
static PyObject *
_io_FileIO_write_impl(fileio *self, Py_buffer *b);
static PyObject *
_io_FileIO_write(fileio *self, PyObject *arg)
{
PyObject *return_value = NULL;
Py_buffer b = {NULL, NULL};
if (!PyArg_Parse(arg,
"y*:write",
&b))
goto exit;
return_value = _io_FileIO_write_impl(self, &b);
exit:
/* Cleanup for b */
if (b.obj)
PyBuffer_Release(&b);
return return_value;
}
PyDoc_STRVAR(_io_FileIO_seek__doc__,
"seek($self, pos, whence=0, /)\n"
"--\n"
"\n"
"Move to new file position and return the file position.\n"
"\n"
"Argument offset is a byte count. Optional argument whence defaults to\n"
"SEEK_SET or 0 (offset from start of file, offset should be >= 0); other values\n"
"are SEEK_CUR or 1 (move relative to current position, positive or negative),\n"
"and SEEK_END or 2 (move relative to end of file, usually negative, although\n"
"many platforms allow seeking beyond the end of a file).\n"
"\n"
"Note that not all file objects are seekable.");
#define _IO_FILEIO_SEEK_METHODDEF \
{"seek", (PyCFunction)_io_FileIO_seek, METH_VARARGS, _io_FileIO_seek__doc__},
static PyObject *
_io_FileIO_seek_impl(fileio *self, PyObject *pos, int whence);
static PyObject *
_io_FileIO_seek(fileio *self, PyObject *args)
{
PyObject *return_value = NULL;
PyObject *pos;
int whence = 0;
if (!PyArg_ParseTuple(args,
"O|i:seek",
&pos, &whence))
goto exit;
return_value = _io_FileIO_seek_impl(self, pos, whence);
exit:
return return_value;
}
PyDoc_STRVAR(_io_FileIO_tell__doc__,
"tell($self, /)\n"
"--\n"
"\n"
"Current file position.\n"
"\n"
"Can raise OSError for non seekable files.");
#define _IO_FILEIO_TELL_METHODDEF \
{"tell", (PyCFunction)_io_FileIO_tell, METH_NOARGS, _io_FileIO_tell__doc__},
static PyObject *
_io_FileIO_tell_impl(fileio *self);
static PyObject *
_io_FileIO_tell(fileio *self, PyObject *Py_UNUSED(ignored))
{
return _io_FileIO_tell_impl(self);
}
#if defined(HAVE_FTRUNCATE)
PyDoc_STRVAR(_io_FileIO_truncate__doc__,
"truncate($self, size=None, /)\n"
"--\n"
"\n"
"Truncate the file to at most size bytes and return the truncated size.\n"
"\n"
"Size defaults to the current file position, as returned by tell().\n"
"The current file position is changed to the value of size.");
#define _IO_FILEIO_TRUNCATE_METHODDEF \
{"truncate", (PyCFunction)_io_FileIO_truncate, METH_VARARGS, _io_FileIO_truncate__doc__},
static PyObject *
_io_FileIO_truncate_impl(fileio *self, PyObject *posobj);
static PyObject *
_io_FileIO_truncate(fileio *self, PyObject *args)
{
PyObject *return_value = NULL;
PyObject *posobj = NULL;
if (!PyArg_UnpackTuple(args, "truncate",
0, 1,
&posobj))
goto exit;
return_value = _io_FileIO_truncate_impl(self, posobj);
exit:
return return_value;
}
#endif /* defined(HAVE_FTRUNCATE) */
PyDoc_STRVAR(_io_FileIO_isatty__doc__,
"isatty($self, /)\n"
"--\n"
"\n"
"True if the file is connected to a TTY device.");
#define _IO_FILEIO_ISATTY_METHODDEF \
{"isatty", (PyCFunction)_io_FileIO_isatty, METH_NOARGS, _io_FileIO_isatty__doc__},
static PyObject *
_io_FileIO_isatty_impl(fileio *self);
static PyObject *
_io_FileIO_isatty(fileio *self, PyObject *Py_UNUSED(ignored))
{
return _io_FileIO_isatty_impl(self);
}
#ifndef _IO_FILEIO_TRUNCATE_METHODDEF
#define _IO_FILEIO_TRUNCATE_METHODDEF
#endif /* !defined(_IO_FILEIO_TRUNCATE_METHODDEF) */
/*[clinic end generated code: output=c6708e1980f6e02d input=a9049054013a1b77]*/

View File

@ -0,0 +1,282 @@
/*[clinic input]
preserve
[clinic start generated code]*/
PyDoc_STRVAR(_io__IOBase_tell__doc__,
"tell($self, /)\n"
"--\n"
"\n"
"Return current stream position.");
#define _IO__IOBASE_TELL_METHODDEF \
{"tell", (PyCFunction)_io__IOBase_tell, METH_NOARGS, _io__IOBase_tell__doc__},
static PyObject *
_io__IOBase_tell_impl(PyObject *self);
static PyObject *
_io__IOBase_tell(PyObject *self, PyObject *Py_UNUSED(ignored))
{
return _io__IOBase_tell_impl(self);
}
PyDoc_STRVAR(_io__IOBase_flush__doc__,
"flush($self, /)\n"
"--\n"
"\n"
"Flush write buffers, if applicable.\n"
"\n"
"This is not implemented for read-only and non-blocking streams.");
#define _IO__IOBASE_FLUSH_METHODDEF \
{"flush", (PyCFunction)_io__IOBase_flush, METH_NOARGS, _io__IOBase_flush__doc__},
static PyObject *
_io__IOBase_flush_impl(PyObject *self);
static PyObject *
_io__IOBase_flush(PyObject *self, PyObject *Py_UNUSED(ignored))
{
return _io__IOBase_flush_impl(self);
}
PyDoc_STRVAR(_io__IOBase_close__doc__,
"close($self, /)\n"
"--\n"
"\n"
"Flush and close the IO object.\n"
"\n"
"This method has no effect if the file is already closed.");
#define _IO__IOBASE_CLOSE_METHODDEF \
{"close", (PyCFunction)_io__IOBase_close, METH_NOARGS, _io__IOBase_close__doc__},
static PyObject *
_io__IOBase_close_impl(PyObject *self);
static PyObject *
_io__IOBase_close(PyObject *self, PyObject *Py_UNUSED(ignored))
{
return _io__IOBase_close_impl(self);
}
PyDoc_STRVAR(_io__IOBase_seekable__doc__,
"seekable($self, /)\n"
"--\n"
"\n"
"Return whether object supports random access.\n"
"\n"
"If False, seek(), tell() and truncate() will raise UnsupportedOperation.\n"
"This method may need to do a test seek().");
#define _IO__IOBASE_SEEKABLE_METHODDEF \
{"seekable", (PyCFunction)_io__IOBase_seekable, METH_NOARGS, _io__IOBase_seekable__doc__},
static PyObject *
_io__IOBase_seekable_impl(PyObject *self);
static PyObject *
_io__IOBase_seekable(PyObject *self, PyObject *Py_UNUSED(ignored))
{
return _io__IOBase_seekable_impl(self);
}
PyDoc_STRVAR(_io__IOBase_readable__doc__,
"readable($self, /)\n"
"--\n"
"\n"
"Return whether object was opened for reading.\n"
"\n"
"If False, read() will raise UnsupportedOperation.");
#define _IO__IOBASE_READABLE_METHODDEF \
{"readable", (PyCFunction)_io__IOBase_readable, METH_NOARGS, _io__IOBase_readable__doc__},
static PyObject *
_io__IOBase_readable_impl(PyObject *self);
static PyObject *
_io__IOBase_readable(PyObject *self, PyObject *Py_UNUSED(ignored))
{
return _io__IOBase_readable_impl(self);
}
PyDoc_STRVAR(_io__IOBase_writable__doc__,
"writable($self, /)\n"
"--\n"
"\n"
"Return whether object was opened for writing.\n"
"\n"
"If False, write() will raise UnsupportedOperation.");
#define _IO__IOBASE_WRITABLE_METHODDEF \
{"writable", (PyCFunction)_io__IOBase_writable, METH_NOARGS, _io__IOBase_writable__doc__},
static PyObject *
_io__IOBase_writable_impl(PyObject *self);
static PyObject *
_io__IOBase_writable(PyObject *self, PyObject *Py_UNUSED(ignored))
{
return _io__IOBase_writable_impl(self);
}
PyDoc_STRVAR(_io__IOBase_fileno__doc__,
"fileno($self, /)\n"
"--\n"
"\n"
"Returns underlying file descriptor if one exists.\n"
"\n"
"An IOError is raised if the IO object does not use a file descriptor.");
#define _IO__IOBASE_FILENO_METHODDEF \
{"fileno", (PyCFunction)_io__IOBase_fileno, METH_NOARGS, _io__IOBase_fileno__doc__},
static PyObject *
_io__IOBase_fileno_impl(PyObject *self);
static PyObject *
_io__IOBase_fileno(PyObject *self, PyObject *Py_UNUSED(ignored))
{
return _io__IOBase_fileno_impl(self);
}
PyDoc_STRVAR(_io__IOBase_isatty__doc__,
"isatty($self, /)\n"
"--\n"
"\n"
"Return whether this is an \'interactive\' stream.\n"
"\n"
"Return False if it can\'t be determined.");
#define _IO__IOBASE_ISATTY_METHODDEF \
{"isatty", (PyCFunction)_io__IOBase_isatty, METH_NOARGS, _io__IOBase_isatty__doc__},
static PyObject *
_io__IOBase_isatty_impl(PyObject *self);
static PyObject *
_io__IOBase_isatty(PyObject *self, PyObject *Py_UNUSED(ignored))
{
return _io__IOBase_isatty_impl(self);
}
PyDoc_STRVAR(_io__IOBase_readline__doc__,
"readline($self, size=-1, /)\n"
"--\n"
"\n"
"Read and return a line from the stream.\n"
"\n"
"If size is specified, at most size bytes will be read.\n"
"\n"
"The line terminator is always b\'\\n\' for binary files; for text\n"
"files, the newlines argument to open can be used to select the line\n"
"terminator(s) recognized.");
#define _IO__IOBASE_READLINE_METHODDEF \
{"readline", (PyCFunction)_io__IOBase_readline, METH_VARARGS, _io__IOBase_readline__doc__},
static PyObject *
_io__IOBase_readline_impl(PyObject *self, Py_ssize_t limit);
static PyObject *
_io__IOBase_readline(PyObject *self, PyObject *args)
{
PyObject *return_value = NULL;
Py_ssize_t limit = -1;
if (!PyArg_ParseTuple(args,
"|O&:readline",
_PyIO_ConvertSsize_t, &limit))
goto exit;
return_value = _io__IOBase_readline_impl(self, limit);
exit:
return return_value;
}
PyDoc_STRVAR(_io__IOBase_readlines__doc__,
"readlines($self, hint=-1, /)\n"
"--\n"
"\n"
"Return a list of lines from the stream.\n"
"\n"
"hint can be specified to control the number of lines read: no more\n"
"lines will be read if the total size (in bytes/characters) of all\n"
"lines so far exceeds hint.");
#define _IO__IOBASE_READLINES_METHODDEF \
{"readlines", (PyCFunction)_io__IOBase_readlines, METH_VARARGS, _io__IOBase_readlines__doc__},
static PyObject *
_io__IOBase_readlines_impl(PyObject *self, Py_ssize_t hint);
static PyObject *
_io__IOBase_readlines(PyObject *self, PyObject *args)
{
PyObject *return_value = NULL;
Py_ssize_t hint = -1;
if (!PyArg_ParseTuple(args,
"|O&:readlines",
_PyIO_ConvertSsize_t, &hint))
goto exit;
return_value = _io__IOBase_readlines_impl(self, hint);
exit:
return return_value;
}
PyDoc_STRVAR(_io__IOBase_writelines__doc__,
"writelines($self, lines, /)\n"
"--\n"
"\n");
#define _IO__IOBASE_WRITELINES_METHODDEF \
{"writelines", (PyCFunction)_io__IOBase_writelines, METH_O, _io__IOBase_writelines__doc__},
PyDoc_STRVAR(_io__RawIOBase_read__doc__,
"read($self, size=-1, /)\n"
"--\n"
"\n");
#define _IO__RAWIOBASE_READ_METHODDEF \
{"read", (PyCFunction)_io__RawIOBase_read, METH_VARARGS, _io__RawIOBase_read__doc__},
static PyObject *
_io__RawIOBase_read_impl(PyObject *self, Py_ssize_t n);
static PyObject *
_io__RawIOBase_read(PyObject *self, PyObject *args)
{
PyObject *return_value = NULL;
Py_ssize_t n = -1;
if (!PyArg_ParseTuple(args,
"|n:read",
&n))
goto exit;
return_value = _io__RawIOBase_read_impl(self, n);
exit:
return return_value;
}
PyDoc_STRVAR(_io__RawIOBase_readall__doc__,
"readall($self, /)\n"
"--\n"
"\n"
"Read until EOF, using multiple read() call.");
#define _IO__RAWIOBASE_READALL_METHODDEF \
{"readall", (PyCFunction)_io__RawIOBase_readall, METH_NOARGS, _io__RawIOBase_readall__doc__},
static PyObject *
_io__RawIOBase_readall_impl(PyObject *self);
static PyObject *
_io__RawIOBase_readall(PyObject *self, PyObject *Py_UNUSED(ignored))
{
return _io__RawIOBase_readall_impl(self);
}
/*[clinic end generated code: output=84eef4b7541f54b7 input=a9049054013a1b77]*/

View File

@ -0,0 +1,288 @@
/*[clinic input]
preserve
[clinic start generated code]*/
PyDoc_STRVAR(_io_StringIO_getvalue__doc__,
"getvalue($self, /)\n"
"--\n"
"\n"
"Retrieve the entire contents of the object.");
#define _IO_STRINGIO_GETVALUE_METHODDEF \
{"getvalue", (PyCFunction)_io_StringIO_getvalue, METH_NOARGS, _io_StringIO_getvalue__doc__},
static PyObject *
_io_StringIO_getvalue_impl(stringio *self);
static PyObject *
_io_StringIO_getvalue(stringio *self, PyObject *Py_UNUSED(ignored))
{
return _io_StringIO_getvalue_impl(self);
}
PyDoc_STRVAR(_io_StringIO_tell__doc__,
"tell($self, /)\n"
"--\n"
"\n"
"Tell the current file position.");
#define _IO_STRINGIO_TELL_METHODDEF \
{"tell", (PyCFunction)_io_StringIO_tell, METH_NOARGS, _io_StringIO_tell__doc__},
static PyObject *
_io_StringIO_tell_impl(stringio *self);
static PyObject *
_io_StringIO_tell(stringio *self, PyObject *Py_UNUSED(ignored))
{
return _io_StringIO_tell_impl(self);
}
PyDoc_STRVAR(_io_StringIO_read__doc__,
"read($self, size=None, /)\n"
"--\n"
"\n"
"Read at most size characters, returned as a string.\n"
"\n"
"If the argument is negative or omitted, read until EOF\n"
"is reached. Return an empty string at EOF.");
#define _IO_STRINGIO_READ_METHODDEF \
{"read", (PyCFunction)_io_StringIO_read, METH_VARARGS, _io_StringIO_read__doc__},
static PyObject *
_io_StringIO_read_impl(stringio *self, PyObject *arg);
static PyObject *
_io_StringIO_read(stringio *self, PyObject *args)
{
PyObject *return_value = NULL;
PyObject *arg = Py_None;
if (!PyArg_UnpackTuple(args, "read",
0, 1,
&arg))
goto exit;
return_value = _io_StringIO_read_impl(self, arg);
exit:
return return_value;
}
PyDoc_STRVAR(_io_StringIO_readline__doc__,
"readline($self, size=None, /)\n"
"--\n"
"\n"
"Read until newline or EOF.\n"
"\n"
"Returns an empty string if EOF is hit immediately.");
#define _IO_STRINGIO_READLINE_METHODDEF \
{"readline", (PyCFunction)_io_StringIO_readline, METH_VARARGS, _io_StringIO_readline__doc__},
static PyObject *
_io_StringIO_readline_impl(stringio *self, PyObject *arg);
static PyObject *
_io_StringIO_readline(stringio *self, PyObject *args)
{
PyObject *return_value = NULL;
PyObject *arg = Py_None;
if (!PyArg_UnpackTuple(args, "readline",
0, 1,
&arg))
goto exit;
return_value = _io_StringIO_readline_impl(self, arg);
exit:
return return_value;
}
PyDoc_STRVAR(_io_StringIO_truncate__doc__,
"truncate($self, pos=None, /)\n"
"--\n"
"\n"
"Truncate size to pos.\n"
"\n"
"The pos argument defaults to the current file position, as\n"
"returned by tell(). The current file position is unchanged.\n"
"Returns the new absolute position.");
#define _IO_STRINGIO_TRUNCATE_METHODDEF \
{"truncate", (PyCFunction)_io_StringIO_truncate, METH_VARARGS, _io_StringIO_truncate__doc__},
static PyObject *
_io_StringIO_truncate_impl(stringio *self, PyObject *arg);
static PyObject *
_io_StringIO_truncate(stringio *self, PyObject *args)
{
PyObject *return_value = NULL;
PyObject *arg = Py_None;
if (!PyArg_UnpackTuple(args, "truncate",
0, 1,
&arg))
goto exit;
return_value = _io_StringIO_truncate_impl(self, arg);
exit:
return return_value;
}
PyDoc_STRVAR(_io_StringIO_seek__doc__,
"seek($self, pos, whence=0, /)\n"
"--\n"
"\n"
"Change stream position.\n"
"\n"
"Seek to character offset pos relative to position indicated by whence:\n"
" 0 Start of stream (the default). pos should be >= 0;\n"
" 1 Current position - pos must be 0;\n"
" 2 End of stream - pos must be 0.\n"
"Returns the new absolute position.");
#define _IO_STRINGIO_SEEK_METHODDEF \
{"seek", (PyCFunction)_io_StringIO_seek, METH_VARARGS, _io_StringIO_seek__doc__},
static PyObject *
_io_StringIO_seek_impl(stringio *self, Py_ssize_t pos, int whence);
static PyObject *
_io_StringIO_seek(stringio *self, PyObject *args)
{
PyObject *return_value = NULL;
Py_ssize_t pos;
int whence = 0;
if (!PyArg_ParseTuple(args,
"n|i:seek",
&pos, &whence))
goto exit;
return_value = _io_StringIO_seek_impl(self, pos, whence);
exit:
return return_value;
}
PyDoc_STRVAR(_io_StringIO_write__doc__,
"write($self, s, /)\n"
"--\n"
"\n"
"Write string to file.\n"
"\n"
"Returns the number of characters written, which is always equal to\n"
"the length of the string.");
#define _IO_STRINGIO_WRITE_METHODDEF \
{"write", (PyCFunction)_io_StringIO_write, METH_O, _io_StringIO_write__doc__},
PyDoc_STRVAR(_io_StringIO_close__doc__,
"close($self, /)\n"
"--\n"
"\n"
"Close the IO object.\n"
"\n"
"Attempting any further operation after the object is closed\n"
"will raise a ValueError.\n"
"\n"
"This method has no effect if the file is already closed.");
#define _IO_STRINGIO_CLOSE_METHODDEF \
{"close", (PyCFunction)_io_StringIO_close, METH_NOARGS, _io_StringIO_close__doc__},
static PyObject *
_io_StringIO_close_impl(stringio *self);
static PyObject *
_io_StringIO_close(stringio *self, PyObject *Py_UNUSED(ignored))
{
return _io_StringIO_close_impl(self);
}
PyDoc_STRVAR(_io_StringIO___init____doc__,
"StringIO(initial_value=\'\', newline=\'\\n\')\n"
"--\n"
"\n"
"Text I/O implementation using an in-memory buffer.\n"
"\n"
"The initial_value argument sets the value of object. The newline\n"
"argument is like the one of TextIOWrapper\'s constructor.");
static int
_io_StringIO___init___impl(stringio *self, PyObject *value,
PyObject *newline_obj);
static int
_io_StringIO___init__(PyObject *self, PyObject *args, PyObject *kwargs)
{
int return_value = -1;
static char *_keywords[] = {"initial_value", "newline", NULL};
PyObject *value = NULL;
PyObject *newline_obj = NULL;
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"|OO:StringIO", _keywords,
&value, &newline_obj))
goto exit;
return_value = _io_StringIO___init___impl((stringio *)self, value, newline_obj);
exit:
return return_value;
}
PyDoc_STRVAR(_io_StringIO_readable__doc__,
"readable($self, /)\n"
"--\n"
"\n"
"Returns True if the IO object can be read.");
#define _IO_STRINGIO_READABLE_METHODDEF \
{"readable", (PyCFunction)_io_StringIO_readable, METH_NOARGS, _io_StringIO_readable__doc__},
static PyObject *
_io_StringIO_readable_impl(stringio *self);
static PyObject *
_io_StringIO_readable(stringio *self, PyObject *Py_UNUSED(ignored))
{
return _io_StringIO_readable_impl(self);
}
PyDoc_STRVAR(_io_StringIO_writable__doc__,
"writable($self, /)\n"
"--\n"
"\n"
"Returns True if the IO object can be written.");
#define _IO_STRINGIO_WRITABLE_METHODDEF \
{"writable", (PyCFunction)_io_StringIO_writable, METH_NOARGS, _io_StringIO_writable__doc__},
static PyObject *
_io_StringIO_writable_impl(stringio *self);
static PyObject *
_io_StringIO_writable(stringio *self, PyObject *Py_UNUSED(ignored))
{
return _io_StringIO_writable_impl(self);
}
PyDoc_STRVAR(_io_StringIO_seekable__doc__,
"seekable($self, /)\n"
"--\n"
"\n"
"Returns True if the IO object can be seeked.");
#define _IO_STRINGIO_SEEKABLE_METHODDEF \
{"seekable", (PyCFunction)_io_StringIO_seekable, METH_NOARGS, _io_StringIO_seekable__doc__},
static PyObject *
_io_StringIO_seekable_impl(stringio *self);
static PyObject *
_io_StringIO_seekable(stringio *self, PyObject *Py_UNUSED(ignored))
{
return _io_StringIO_seekable_impl(self);
}
/*[clinic end generated code: output=f3062096d357c652 input=a9049054013a1b77]*/

View File

@ -0,0 +1,464 @@
/*[clinic input]
preserve
[clinic start generated code]*/
PyDoc_STRVAR(_io_IncrementalNewlineDecoder___init____doc__,
"IncrementalNewlineDecoder(decoder, translate, errors=\'strict\')\n"
"--\n"
"\n"
"Codec used when reading a file in universal newlines mode.\n"
"\n"
"It wraps another incremental decoder, translating \\r\\n and \\r into \\n.\n"
"It also records the types of newlines encountered. When used with\n"
"translate=False, it ensures that the newline sequence is returned in\n"
"one piece. When used with decoder=None, it expects unicode strings as\n"
"decode input and translates newlines without first invoking an external\n"
"decoder.");
static int
_io_IncrementalNewlineDecoder___init___impl(nldecoder_object *self,
PyObject *decoder, int translate,
PyObject *errors);
static int
_io_IncrementalNewlineDecoder___init__(PyObject *self, PyObject *args, PyObject *kwargs)
{
int return_value = -1;
static char *_keywords[] = {"decoder", "translate", "errors", NULL};
PyObject *decoder;
int translate;
PyObject *errors = NULL;
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"Oi|O:IncrementalNewlineDecoder", _keywords,
&decoder, &translate, &errors))
goto exit;
return_value = _io_IncrementalNewlineDecoder___init___impl((nldecoder_object *)self, decoder, translate, errors);
exit:
return return_value;
}
PyDoc_STRVAR(_io_IncrementalNewlineDecoder_decode__doc__,
"decode($self, /, input, final=False)\n"
"--\n"
"\n");
#define _IO_INCREMENTALNEWLINEDECODER_DECODE_METHODDEF \
{"decode", (PyCFunction)_io_IncrementalNewlineDecoder_decode, METH_VARARGS|METH_KEYWORDS, _io_IncrementalNewlineDecoder_decode__doc__},
static PyObject *
_io_IncrementalNewlineDecoder_decode_impl(nldecoder_object *self,
PyObject *input, int final);
static PyObject *
_io_IncrementalNewlineDecoder_decode(nldecoder_object *self, PyObject *args, PyObject *kwargs)
{
PyObject *return_value = NULL;
static char *_keywords[] = {"input", "final", NULL};
PyObject *input;
int final = 0;
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"O|i:decode", _keywords,
&input, &final))
goto exit;
return_value = _io_IncrementalNewlineDecoder_decode_impl(self, input, final);
exit:
return return_value;
}
PyDoc_STRVAR(_io_IncrementalNewlineDecoder_getstate__doc__,
"getstate($self, /)\n"
"--\n"
"\n");
#define _IO_INCREMENTALNEWLINEDECODER_GETSTATE_METHODDEF \
{"getstate", (PyCFunction)_io_IncrementalNewlineDecoder_getstate, METH_NOARGS, _io_IncrementalNewlineDecoder_getstate__doc__},
static PyObject *
_io_IncrementalNewlineDecoder_getstate_impl(nldecoder_object *self);
static PyObject *
_io_IncrementalNewlineDecoder_getstate(nldecoder_object *self, PyObject *Py_UNUSED(ignored))
{
return _io_IncrementalNewlineDecoder_getstate_impl(self);
}
PyDoc_STRVAR(_io_IncrementalNewlineDecoder_setstate__doc__,
"setstate($self, state, /)\n"
"--\n"
"\n");
#define _IO_INCREMENTALNEWLINEDECODER_SETSTATE_METHODDEF \
{"setstate", (PyCFunction)_io_IncrementalNewlineDecoder_setstate, METH_O, _io_IncrementalNewlineDecoder_setstate__doc__},
PyDoc_STRVAR(_io_IncrementalNewlineDecoder_reset__doc__,
"reset($self, /)\n"
"--\n"
"\n");
#define _IO_INCREMENTALNEWLINEDECODER_RESET_METHODDEF \
{"reset", (PyCFunction)_io_IncrementalNewlineDecoder_reset, METH_NOARGS, _io_IncrementalNewlineDecoder_reset__doc__},
static PyObject *
_io_IncrementalNewlineDecoder_reset_impl(nldecoder_object *self);
static PyObject *
_io_IncrementalNewlineDecoder_reset(nldecoder_object *self, PyObject *Py_UNUSED(ignored))
{
return _io_IncrementalNewlineDecoder_reset_impl(self);
}
PyDoc_STRVAR(_io_TextIOWrapper___init____doc__,
"TextIOWrapper(buffer, encoding=None, errors=None, newline=None,\n"
" line_buffering=False, write_through=False)\n"
"--\n"
"\n"
"Character and line based layer over a BufferedIOBase object, buffer.\n"
"\n"
"encoding gives the name of the encoding that the stream will be\n"
"decoded or encoded with. It defaults to locale.getpreferredencoding(False).\n"
"\n"
"errors determines the strictness of encoding and decoding (see\n"
"help(codecs.Codec) or the documentation for codecs.register) and\n"
"defaults to \"strict\".\n"
"\n"
"newline controls how line endings are handled. It can be None, \'\',\n"
"\'\\n\', \'\\r\', and \'\\r\\n\'. It works as follows:\n"
"\n"
"* On input, if newline is None, universal newlines mode is\n"
" enabled. Lines in the input can end in \'\\n\', \'\\r\', or \'\\r\\n\', and\n"
" these are translated into \'\\n\' before being returned to the\n"
" caller. If it is \'\', universal newline mode is enabled, but line\n"
" endings are returned to the caller untranslated. If it has any of\n"
" the other legal values, input lines are only terminated by the given\n"
" string, and the line ending is returned to the caller untranslated.\n"
"\n"
"* On output, if newline is None, any \'\\n\' characters written are\n"
" translated to the system default line separator, os.linesep. If\n"
" newline is \'\' or \'\\n\', no translation takes place. If newline is any\n"
" of the other legal values, any \'\\n\' characters written are translated\n"
" to the given string.\n"
"\n"
"If line_buffering is True, a call to flush is implied when a call to\n"
"write contains a newline character.");
static int
_io_TextIOWrapper___init___impl(textio *self, PyObject *buffer,
const char *encoding, const char *errors,
const char *newline, int line_buffering,
int write_through);
static int
_io_TextIOWrapper___init__(PyObject *self, PyObject *args, PyObject *kwargs)
{
int return_value = -1;
static char *_keywords[] = {"buffer", "encoding", "errors", "newline", "line_buffering", "write_through", NULL};
PyObject *buffer;
const char *encoding = NULL;
const char *errors = NULL;
const char *newline = NULL;
int line_buffering = 0;
int write_through = 0;
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"O|zzzii:TextIOWrapper", _keywords,
&buffer, &encoding, &errors, &newline, &line_buffering, &write_through))
goto exit;
return_value = _io_TextIOWrapper___init___impl((textio *)self, buffer, encoding, errors, newline, line_buffering, write_through);
exit:
return return_value;
}
PyDoc_STRVAR(_io_TextIOWrapper_detach__doc__,
"detach($self, /)\n"
"--\n"
"\n");
#define _IO_TEXTIOWRAPPER_DETACH_METHODDEF \
{"detach", (PyCFunction)_io_TextIOWrapper_detach, METH_NOARGS, _io_TextIOWrapper_detach__doc__},
static PyObject *
_io_TextIOWrapper_detach_impl(textio *self);
static PyObject *
_io_TextIOWrapper_detach(textio *self, PyObject *Py_UNUSED(ignored))
{
return _io_TextIOWrapper_detach_impl(self);
}
PyDoc_STRVAR(_io_TextIOWrapper_write__doc__,
"write($self, text, /)\n"
"--\n"
"\n");
#define _IO_TEXTIOWRAPPER_WRITE_METHODDEF \
{"write", (PyCFunction)_io_TextIOWrapper_write, METH_O, _io_TextIOWrapper_write__doc__},
static PyObject *
_io_TextIOWrapper_write_impl(textio *self, PyObject *text);
static PyObject *
_io_TextIOWrapper_write(textio *self, PyObject *arg)
{
PyObject *return_value = NULL;
PyObject *text;
if (!PyArg_Parse(arg,
"U:write",
&text))
goto exit;
return_value = _io_TextIOWrapper_write_impl(self, text);
exit:
return return_value;
}
PyDoc_STRVAR(_io_TextIOWrapper_read__doc__,
"read($self, size=-1, /)\n"
"--\n"
"\n");
#define _IO_TEXTIOWRAPPER_READ_METHODDEF \
{"read", (PyCFunction)_io_TextIOWrapper_read, METH_VARARGS, _io_TextIOWrapper_read__doc__},
static PyObject *
_io_TextIOWrapper_read_impl(textio *self, Py_ssize_t n);
static PyObject *
_io_TextIOWrapper_read(textio *self, PyObject *args)
{
PyObject *return_value = NULL;
Py_ssize_t n = -1;
if (!PyArg_ParseTuple(args,
"|O&:read",
_PyIO_ConvertSsize_t, &n))
goto exit;
return_value = _io_TextIOWrapper_read_impl(self, n);
exit:
return return_value;
}
PyDoc_STRVAR(_io_TextIOWrapper_readline__doc__,
"readline($self, size=-1, /)\n"
"--\n"
"\n");
#define _IO_TEXTIOWRAPPER_READLINE_METHODDEF \
{"readline", (PyCFunction)_io_TextIOWrapper_readline, METH_VARARGS, _io_TextIOWrapper_readline__doc__},
static PyObject *
_io_TextIOWrapper_readline_impl(textio *self, Py_ssize_t size);
static PyObject *
_io_TextIOWrapper_readline(textio *self, PyObject *args)
{
PyObject *return_value = NULL;
Py_ssize_t size = -1;
if (!PyArg_ParseTuple(args,
"|n:readline",
&size))
goto exit;
return_value = _io_TextIOWrapper_readline_impl(self, size);
exit:
return return_value;
}
PyDoc_STRVAR(_io_TextIOWrapper_seek__doc__,
"seek($self, cookie, whence=0, /)\n"
"--\n"
"\n");
#define _IO_TEXTIOWRAPPER_SEEK_METHODDEF \
{"seek", (PyCFunction)_io_TextIOWrapper_seek, METH_VARARGS, _io_TextIOWrapper_seek__doc__},
static PyObject *
_io_TextIOWrapper_seek_impl(textio *self, PyObject *cookieObj, int whence);
static PyObject *
_io_TextIOWrapper_seek(textio *self, PyObject *args)
{
PyObject *return_value = NULL;
PyObject *cookieObj;
int whence = 0;
if (!PyArg_ParseTuple(args,
"O|i:seek",
&cookieObj, &whence))
goto exit;
return_value = _io_TextIOWrapper_seek_impl(self, cookieObj, whence);
exit:
return return_value;
}
PyDoc_STRVAR(_io_TextIOWrapper_tell__doc__,
"tell($self, /)\n"
"--\n"
"\n");
#define _IO_TEXTIOWRAPPER_TELL_METHODDEF \
{"tell", (PyCFunction)_io_TextIOWrapper_tell, METH_NOARGS, _io_TextIOWrapper_tell__doc__},
static PyObject *
_io_TextIOWrapper_tell_impl(textio *self);
static PyObject *
_io_TextIOWrapper_tell(textio *self, PyObject *Py_UNUSED(ignored))
{
return _io_TextIOWrapper_tell_impl(self);
}
PyDoc_STRVAR(_io_TextIOWrapper_truncate__doc__,
"truncate($self, pos=None, /)\n"
"--\n"
"\n");
#define _IO_TEXTIOWRAPPER_TRUNCATE_METHODDEF \
{"truncate", (PyCFunction)_io_TextIOWrapper_truncate, METH_VARARGS, _io_TextIOWrapper_truncate__doc__},
static PyObject *
_io_TextIOWrapper_truncate_impl(textio *self, PyObject *pos);
static PyObject *
_io_TextIOWrapper_truncate(textio *self, PyObject *args)
{
PyObject *return_value = NULL;
PyObject *pos = Py_None;
if (!PyArg_UnpackTuple(args, "truncate",
0, 1,
&pos))
goto exit;
return_value = _io_TextIOWrapper_truncate_impl(self, pos);
exit:
return return_value;
}
PyDoc_STRVAR(_io_TextIOWrapper_fileno__doc__,
"fileno($self, /)\n"
"--\n"
"\n");
#define _IO_TEXTIOWRAPPER_FILENO_METHODDEF \
{"fileno", (PyCFunction)_io_TextIOWrapper_fileno, METH_NOARGS, _io_TextIOWrapper_fileno__doc__},
static PyObject *
_io_TextIOWrapper_fileno_impl(textio *self);
static PyObject *
_io_TextIOWrapper_fileno(textio *self, PyObject *Py_UNUSED(ignored))
{
return _io_TextIOWrapper_fileno_impl(self);
}
PyDoc_STRVAR(_io_TextIOWrapper_seekable__doc__,
"seekable($self, /)\n"
"--\n"
"\n");
#define _IO_TEXTIOWRAPPER_SEEKABLE_METHODDEF \
{"seekable", (PyCFunction)_io_TextIOWrapper_seekable, METH_NOARGS, _io_TextIOWrapper_seekable__doc__},
static PyObject *
_io_TextIOWrapper_seekable_impl(textio *self);
static PyObject *
_io_TextIOWrapper_seekable(textio *self, PyObject *Py_UNUSED(ignored))
{
return _io_TextIOWrapper_seekable_impl(self);
}
PyDoc_STRVAR(_io_TextIOWrapper_readable__doc__,
"readable($self, /)\n"
"--\n"
"\n");
#define _IO_TEXTIOWRAPPER_READABLE_METHODDEF \
{"readable", (PyCFunction)_io_TextIOWrapper_readable, METH_NOARGS, _io_TextIOWrapper_readable__doc__},
static PyObject *
_io_TextIOWrapper_readable_impl(textio *self);
static PyObject *
_io_TextIOWrapper_readable(textio *self, PyObject *Py_UNUSED(ignored))
{
return _io_TextIOWrapper_readable_impl(self);
}
PyDoc_STRVAR(_io_TextIOWrapper_writable__doc__,
"writable($self, /)\n"
"--\n"
"\n");
#define _IO_TEXTIOWRAPPER_WRITABLE_METHODDEF \
{"writable", (PyCFunction)_io_TextIOWrapper_writable, METH_NOARGS, _io_TextIOWrapper_writable__doc__},
static PyObject *
_io_TextIOWrapper_writable_impl(textio *self);
static PyObject *
_io_TextIOWrapper_writable(textio *self, PyObject *Py_UNUSED(ignored))
{
return _io_TextIOWrapper_writable_impl(self);
}
PyDoc_STRVAR(_io_TextIOWrapper_isatty__doc__,
"isatty($self, /)\n"
"--\n"
"\n");
#define _IO_TEXTIOWRAPPER_ISATTY_METHODDEF \
{"isatty", (PyCFunction)_io_TextIOWrapper_isatty, METH_NOARGS, _io_TextIOWrapper_isatty__doc__},
static PyObject *
_io_TextIOWrapper_isatty_impl(textio *self);
static PyObject *
_io_TextIOWrapper_isatty(textio *self, PyObject *Py_UNUSED(ignored))
{
return _io_TextIOWrapper_isatty_impl(self);
}
PyDoc_STRVAR(_io_TextIOWrapper_flush__doc__,
"flush($self, /)\n"
"--\n"
"\n");
#define _IO_TEXTIOWRAPPER_FLUSH_METHODDEF \
{"flush", (PyCFunction)_io_TextIOWrapper_flush, METH_NOARGS, _io_TextIOWrapper_flush__doc__},
static PyObject *
_io_TextIOWrapper_flush_impl(textio *self);
static PyObject *
_io_TextIOWrapper_flush(textio *self, PyObject *Py_UNUSED(ignored))
{
return _io_TextIOWrapper_flush_impl(self);
}
PyDoc_STRVAR(_io_TextIOWrapper_close__doc__,
"close($self, /)\n"
"--\n"
"\n");
#define _IO_TEXTIOWRAPPER_CLOSE_METHODDEF \
{"close", (PyCFunction)_io_TextIOWrapper_close, METH_NOARGS, _io_TextIOWrapper_close__doc__},
static PyObject *
_io_TextIOWrapper_close_impl(textio *self);
static PyObject *
_io_TextIOWrapper_close(textio *self, PyObject *Py_UNUSED(ignored))
{
return _io_TextIOWrapper_close_impl(self);
}
/*[clinic end generated code: output=a610bd3b694886c3 input=a9049054013a1b77]*/

View File

@ -43,6 +43,19 @@
#define SMALLCHUNK BUFSIZ
#endif
/*[clinic input]
module _io
class _io.FileIO "fileio *" "&PyFileIO_Type"
[clinic start generated code]*/
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=1c77708b41fda70c]*/
/*[python input]
class io_ssize_t_converter(CConverter):
type = 'Py_ssize_t'
converter = '_PyIO_ConvertSsize_t'
[python start generated code]*/
/*[python end generated code: output=da39a3ee5e6b4b0d input=d0a811d3cbfd1b33]*/
typedef struct {
PyObject_HEAD
int fd;
@ -126,8 +139,18 @@ internal_close(fileio *self)
return 0;
}
/*[clinic input]
_io.FileIO.close
Close the file.
A closed file cannot be used for further I/O operations. close() may be
called more than once without error.
[clinic start generated code]*/
static PyObject *
fileio_close(fileio *self)
_io_FileIO_close_impl(fileio *self)
/*[clinic end generated code: output=7737a319ef3bad0b input=f35231760d54a522]*/
{
PyObject *res;
PyObject *exc, *val, *tb;
@ -183,15 +206,36 @@ fileio_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
extern int _Py_open_cloexec_works;
#endif
/*[clinic input]
_io.FileIO.__init__
file as nameobj: object
mode: str = "r"
closefd: int(c_default="1") = True
opener: object = None
Open a file.
The mode can be 'r' (default), 'w', 'x' or 'a' for reading,
writing, exclusive creation or appending. The file will be created if it
doesn't exist when opened for writing or appending; it will be truncated
when opened for writing. A FileExistsError will be raised if it already
exists when opened for creating. Opening a file for creating implies
writing so this mode behaves in a similar way to 'w'.Add a '+' to the mode
to allow simultaneous reading and writing. A custom opener can be used by
passing a callable as *opener*. The underlying file descriptor for the file
object is then obtained by calling opener with (*name*, *flags*).
*opener* must return an open file descriptor (passing os.open as *opener*
results in functionality similar to passing None).
[clinic start generated code]*/
static int
fileio_init(PyObject *oself, PyObject *args, PyObject *kwds)
_io_FileIO___init___impl(fileio *self, PyObject *nameobj, const char *mode,
int closefd, PyObject *opener)
/*[clinic end generated code: output=23413f68e6484bbd input=193164e293d6c097]*/
{
fileio *self = (fileio *) oself;
static char *kwlist[] = {"file", "mode", "closefd", "opener", NULL};
const char *name = NULL;
PyObject *nameobj, *stringobj = NULL, *opener = Py_None;
char *mode = "r";
char *s;
PyObject *stringobj = NULL;
const char *s;
#ifdef MS_WINDOWS
Py_UNICODE *widename = NULL;
#endif
@ -199,7 +243,6 @@ fileio_init(PyObject *oself, PyObject *args, PyObject *kwds)
int rwa = 0, plus = 0;
int flags = 0;
int fd = -1;
int closefd = 1;
int fd_is_own = 0;
#ifdef O_CLOEXEC
int *atomic_flag_works = &_Py_open_cloexec_works;
@ -220,11 +263,6 @@ fileio_init(PyObject *oself, PyObject *args, PyObject *kwds)
self->fd = -1;
}
if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|siO:fileio",
kwlist, &nameobj, &mode, &closefd,
&opener))
return -1;
if (PyFloat_Check(nameobj)) {
PyErr_SetString(PyExc_TypeError,
"integer argument expected, got float");
@ -494,32 +532,60 @@ err_mode(char *action)
return NULL;
}
/*[clinic input]
_io.FileIO.fileno
Return the underlying file descriptor (an integer).
[clinic start generated code]*/
static PyObject *
fileio_fileno(fileio *self)
_io_FileIO_fileno_impl(fileio *self)
/*[clinic end generated code: output=a9626ce5398ece90 input=0b9b2de67335ada3]*/
{
if (self->fd < 0)
return err_closed();
return PyLong_FromLong((long) self->fd);
}
/*[clinic input]
_io.FileIO.readable
True if file was opened in a read mode.
[clinic start generated code]*/
static PyObject *
fileio_readable(fileio *self)
_io_FileIO_readable_impl(fileio *self)
/*[clinic end generated code: output=640744a6150fe9ba input=a3fdfed6eea721c5]*/
{
if (self->fd < 0)
return err_closed();
return PyBool_FromLong((long) self->readable);
}
/*[clinic input]
_io.FileIO.writable
True if file was opened in a write mode.
[clinic start generated code]*/
static PyObject *
fileio_writable(fileio *self)
_io_FileIO_writable_impl(fileio *self)
/*[clinic end generated code: output=96cefc5446e89977 input=c204a808ca2e1748]*/
{
if (self->fd < 0)
return err_closed();
return PyBool_FromLong((long) self->writable);
}
/*[clinic input]
_io.FileIO.seekable
True if file supports random-access.
[clinic start generated code]*/
static PyObject *
fileio_seekable(fileio *self)
_io_FileIO_seekable_impl(fileio *self)
/*[clinic end generated code: output=47909ca0a42e9287 input=c8e5554d2fd63c7f]*/
{
if (self->fd < 0)
return err_closed();
@ -536,10 +602,18 @@ fileio_seekable(fileio *self)
return PyBool_FromLong((long) self->seekable);
}
/*[clinic input]
_io.FileIO.readinto
buffer: Py_buffer(types={'rwbuffer'})
/
Same as RawIOBase.readinto().
[clinic start generated code]*/
static PyObject *
fileio_readinto(fileio *self, PyObject *args)
_io_FileIO_readinto_impl(fileio *self, Py_buffer *buffer)
/*[clinic end generated code: output=b01a5a22c8415cb4 input=5edd8327498d468c]*/
{
Py_buffer pbuf;
Py_ssize_t n;
int err;
@ -548,13 +622,9 @@ fileio_readinto(fileio *self, PyObject *args)
if (!self->readable)
return err_mode("reading");
if (!PyArg_ParseTuple(args, "w*", &pbuf))
return NULL;
n = _Py_read(self->fd, pbuf.buf, pbuf.len);
n = _Py_read(self->fd, buffer->buf, buffer->len);
/* copy errno because PyBuffer_Release() can indirectly modify it */
err = errno;
PyBuffer_Release(&pbuf);
if (n == -1) {
if (err == EAGAIN) {
@ -586,8 +656,18 @@ new_buffersize(fileio *self, size_t currentsize)
return addend + currentsize;
}
/*[clinic input]
_io.FileIO.readall
Read all data from the file, returned as bytes.
In non-blocking mode, returns as much as is immediately available,
or None if no data is available. Return an empty bytes object at EOF.
[clinic start generated code]*/
static PyObject *
fileio_readall(fileio *self)
_io_FileIO_readall_impl(fileio *self)
/*[clinic end generated code: output=faa0292b213b4022 input=dbdc137f55602834]*/
{
struct _Py_stat_struct status;
Py_off_t pos, end;
@ -673,12 +753,24 @@ fileio_readall(fileio *self)
return result;
}
/*[clinic input]
_io.FileIO.read
size: io_ssize_t = -1
/
Read at most size bytes, returned as bytes.
Only makes one system call, so less data may be returned than requested.
In non-blocking mode, returns None if no data is available.
Return an empty bytes object at EOF.
[clinic start generated code]*/
static PyObject *
fileio_read(fileio *self, PyObject *args)
_io_FileIO_read_impl(fileio *self, Py_ssize_t size)
/*[clinic end generated code: output=42528d39dd0ca641 input=5c6caa5490c13a9b]*/
{
char *ptr;
Py_ssize_t n;
Py_ssize_t size = -1;
PyObject *bytes;
if (self->fd < 0)
@ -686,11 +778,8 @@ fileio_read(fileio *self, PyObject *args)
if (!self->readable)
return err_mode("reading");
if (!PyArg_ParseTuple(args, "|O&", &_PyIO_ConvertSsize_t, &size))
return NULL;
if (size < 0)
return fileio_readall(self);
return _io_FileIO_readall_impl(self);
#ifdef MS_WINDOWS
/* On Windows, the count parameter of read() is an int */
@ -725,10 +814,22 @@ fileio_read(fileio *self, PyObject *args)
return (PyObject *) bytes;
}
/*[clinic input]
_io.FileIO.write
b: Py_buffer
/
Write bytes b to file, return number written.
Only makes one system call, so not all of the data may be written.
The number of bytes actually written is returned. In non-blocking mode,
returns None if the write would block.
[clinic start generated code]*/
static PyObject *
fileio_write(fileio *self, PyObject *args)
_io_FileIO_write_impl(fileio *self, Py_buffer *b)
/*[clinic end generated code: output=b4059db3d363a2f7 input=ffbd8834f447ac31]*/
{
Py_buffer pbuf;
Py_ssize_t n;
int err;
@ -737,13 +838,9 @@ fileio_write(fileio *self, PyObject *args)
if (!self->writable)
return err_mode("writing");
if (!PyArg_ParseTuple(args, "y*", &pbuf))
return NULL;
n = _Py_write(self->fd, pbuf.buf, pbuf.len);
n = _Py_write(self->fd, b->buf, b->len);
/* copy errno because PyBuffer_Release() can indirectly modify it */
err = errno;
PyBuffer_Release(&pbuf);
if (n < 0) {
if (err == EAGAIN) {
@ -817,23 +914,44 @@ portable_lseek(int fd, PyObject *posobj, int whence)
#endif
}
static PyObject *
fileio_seek(fileio *self, PyObject *args)
{
PyObject *posobj;
int whence = 0;
/*[clinic input]
_io.FileIO.seek
pos: object
whence: int = 0
/
Move to new file position and return the file position.
Argument offset is a byte count. Optional argument whence defaults to
SEEK_SET or 0 (offset from start of file, offset should be >= 0); other values
are SEEK_CUR or 1 (move relative to current position, positive or negative),
and SEEK_END or 2 (move relative to end of file, usually negative, although
many platforms allow seeking beyond the end of a file).
Note that not all file objects are seekable.
[clinic start generated code]*/
static PyObject *
_io_FileIO_seek_impl(fileio *self, PyObject *pos, int whence)
/*[clinic end generated code: output=c976acdf054e6655 input=0439194b0774d454]*/
{
if (self->fd < 0)
return err_closed();
if (!PyArg_ParseTuple(args, "O|i", &posobj, &whence))
return NULL;
return portable_lseek(self->fd, posobj, whence);
return portable_lseek(self->fd, pos, whence);
}
/*[clinic input]
_io.FileIO.tell
Current file position.
Can raise OSError for non seekable files.
[clinic start generated code]*/
static PyObject *
fileio_tell(fileio *self, PyObject *args)
_io_FileIO_tell_impl(fileio *self)
/*[clinic end generated code: output=ffe2147058809d0b input=807e24ead4cec2f9]*/
{
if (self->fd < 0)
return err_closed();
@ -842,10 +960,21 @@ fileio_tell(fileio *self, PyObject *args)
}
#ifdef HAVE_FTRUNCATE
/*[clinic input]
_io.FileIO.truncate
size as posobj: object = NULL
/
Truncate the file to at most size bytes and return the truncated size.
Size defaults to the current file position, as returned by tell().
The current file position is changed to the value of size.
[clinic start generated code]*/
static PyObject *
fileio_truncate(fileio *self, PyObject *args)
_io_FileIO_truncate_impl(fileio *self, PyObject *posobj)
/*[clinic end generated code: output=e49ca7a916c176fa input=9026af44686b7318]*/
{
PyObject *posobj = NULL; /* the new size wanted by the user */
Py_off_t pos;
int ret;
int fd;
@ -856,9 +985,6 @@ fileio_truncate(fileio *self, PyObject *args)
if (!self->writable)
return err_mode("writing");
if (!PyArg_ParseTuple(args, "|O", &posobj))
return NULL;
if (posobj == Py_None || posobj == NULL) {
/* Get the current position. */
posobj = portable_lseek(fd, NULL, 1);
@ -952,8 +1078,15 @@ fileio_repr(fileio *self)
return res;
}
/*[clinic input]
_io.FileIO.isatty
True if the file is connected to a TTY device.
[clinic start generated code]*/
static PyObject *
fileio_isatty(fileio *self)
_io_FileIO_isatty_impl(fileio *self)
/*[clinic end generated code: output=932c39924e9a8070 input=cd94ca1f5e95e843]*/
{
long res;
@ -978,110 +1111,22 @@ fileio_getstate(fileio *self)
return NULL;
}
PyDoc_STRVAR(fileio_doc,
"file(name: str[, mode: str][, opener: None]) -> file IO object\n"
"\n"
"Open a file. The mode can be 'r' (default), 'w', 'x' or 'a' for reading,\n"
"writing, exclusive creation or appending. The file will be created if it\n"
"doesn't exist when opened for writing or appending; it will be truncated\n"
"when opened for writing. A FileExistsError will be raised if it already\n"
"exists when opened for creating. Opening a file for creating implies\n"
"writing so this mode behaves in a similar way to 'w'.Add a '+' to the mode\n"
"to allow simultaneous reading and writing. A custom opener can be used by\n"
"passing a callable as *opener*. The underlying file descriptor for the file\n"
"object is then obtained by calling opener with (*name*, *flags*).\n"
"*opener* must return an open file descriptor (passing os.open as *opener*\n"
"results in functionality similar to passing None).");
PyDoc_STRVAR(read_doc,
"read(size: int) -> bytes. read at most size bytes, returned as bytes.\n"
"\n"
"Only makes one system call, so less data may be returned than requested\n"
"In non-blocking mode, returns None if no data is available.\n"
"Return an empty bytes object at EOF.");
PyDoc_STRVAR(readall_doc,
"readall() -> bytes. read all data from the file, returned as bytes.\n"
"\n"
"In non-blocking mode, returns as much as is immediately available,\n"
"or None if no data is available. Return an empty bytes object at EOF.");
PyDoc_STRVAR(write_doc,
"write(b: bytes) -> int. Write bytes b to file, return number written.\n"
"\n"
"Only makes one system call, so not all of the data may be written.\n"
"The number of bytes actually written is returned. In non-blocking mode,\n"
"returns None if the write would block."
);
PyDoc_STRVAR(fileno_doc,
"fileno() -> int. Return the underlying file descriptor (an integer).");
PyDoc_STRVAR(seek_doc,
"seek(offset: int[, whence: int]) -> int. Move to new file position and\n"
"return the file position.\n"
"\n"
"Argument offset is a byte count. Optional argument whence defaults to\n"
"SEEK_SET or 0 (offset from start of file, offset should be >= 0); other values\n"
"are SEEK_CUR or 1 (move relative to current position, positive or negative),\n"
"and SEEK_END or 2 (move relative to end of file, usually negative, although\n"
"many platforms allow seeking beyond the end of a file).\n"
"\n"
"Note that not all file objects are seekable.");
#ifdef HAVE_FTRUNCATE
PyDoc_STRVAR(truncate_doc,
"truncate([size: int]) -> int. Truncate the file to at most size bytes\n"
"and return the truncated size.\n"
"\n"
"Size defaults to the current file position, as returned by tell().\n"
"The current file position is changed to the value of size.");
#endif
PyDoc_STRVAR(tell_doc,
"tell() -> int. Current file position.\n"
"\n"
"Can raise OSError for non seekable files."
);
PyDoc_STRVAR(readinto_doc,
"readinto() -> Same as RawIOBase.readinto().");
PyDoc_STRVAR(close_doc,
"close() -> None. Close the file.\n"
"\n"
"A closed file cannot be used for further I/O operations. close() may be\n"
"called more than once without error.");
PyDoc_STRVAR(isatty_doc,
"isatty() -> bool. True if the file is connected to a TTY device.");
PyDoc_STRVAR(seekable_doc,
"seekable() -> bool. True if file supports random-access.");
PyDoc_STRVAR(readable_doc,
"readable() -> bool. True if file was opened in a read mode.");
PyDoc_STRVAR(writable_doc,
"writable() -> bool. True if file was opened in a write mode.");
#include "clinic/fileio.c.h"
static PyMethodDef fileio_methods[] = {
{"read", (PyCFunction)fileio_read, METH_VARARGS, read_doc},
{"readall", (PyCFunction)fileio_readall, METH_NOARGS, readall_doc},
{"readinto", (PyCFunction)fileio_readinto, METH_VARARGS, readinto_doc},
{"write", (PyCFunction)fileio_write, METH_VARARGS, write_doc},
{"seek", (PyCFunction)fileio_seek, METH_VARARGS, seek_doc},
{"tell", (PyCFunction)fileio_tell, METH_VARARGS, tell_doc},
#ifdef HAVE_FTRUNCATE
{"truncate", (PyCFunction)fileio_truncate, METH_VARARGS, truncate_doc},
#endif
{"close", (PyCFunction)fileio_close, METH_NOARGS, close_doc},
{"seekable", (PyCFunction)fileio_seekable, METH_NOARGS, seekable_doc},
{"readable", (PyCFunction)fileio_readable, METH_NOARGS, readable_doc},
{"writable", (PyCFunction)fileio_writable, METH_NOARGS, writable_doc},
{"fileno", (PyCFunction)fileio_fileno, METH_NOARGS, fileno_doc},
{"isatty", (PyCFunction)fileio_isatty, METH_NOARGS, isatty_doc},
_IO_FILEIO_READ_METHODDEF
_IO_FILEIO_READALL_METHODDEF
_IO_FILEIO_READINTO_METHODDEF
_IO_FILEIO_WRITE_METHODDEF
_IO_FILEIO_SEEK_METHODDEF
_IO_FILEIO_TELL_METHODDEF
_IO_FILEIO_TRUNCATE_METHODDEF
_IO_FILEIO_CLOSE_METHODDEF
_IO_FILEIO_SEEKABLE_METHODDEF
_IO_FILEIO_READABLE_METHODDEF
_IO_FILEIO_WRITABLE_METHODDEF
_IO_FILEIO_FILENO_METHODDEF
_IO_FILEIO_ISATTY_METHODDEF
{"_dealloc_warn", (PyCFunction)fileio_dealloc_warn, METH_O, NULL},
{"__getstate__", (PyCFunction)fileio_getstate, METH_NOARGS, NULL},
{NULL, NULL} /* sentinel */
@ -1143,7 +1188,7 @@ PyTypeObject PyFileIO_Type = {
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE
| Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_HAVE_FINALIZE, /* tp_flags */
fileio_doc, /* tp_doc */
_io_FileIO___init____doc__, /* tp_doc */
(traverseproc)fileio_traverse, /* tp_traverse */
(inquiry)fileio_clear, /* tp_clear */
0, /* tp_richcompare */
@ -1158,7 +1203,7 @@ PyTypeObject PyFileIO_Type = {
0, /* tp_descr_get */
0, /* tp_descr_set */
offsetof(fileio, dict), /* tp_dictoffset */
fileio_init, /* tp_init */
_io_FileIO___init__, /* tp_init */
PyType_GenericAlloc, /* tp_alloc */
fileio_new, /* tp_new */
PyObject_GC_Del, /* tp_free */

View File

@ -13,6 +13,20 @@
#include "structmember.h"
#include "_iomodule.h"
/*[clinic input]
module _io
class _io._IOBase "PyObject *" "&PyIOBase_Type"
class _io._RawIOBase "PyObject *" "&PyRawIOBase_Type"
[clinic start generated code]*/
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=d29a4d076c2b211c]*/
/*[python input]
class io_ssize_t_converter(CConverter):
type = 'Py_ssize_t'
converter = '_PyIO_ConvertSsize_t'
[python start generated code]*/
/*[python end generated code: output=da39a3ee5e6b4b0d input=d0a811d3cbfd1b33]*/
/*
* IOBase class, an abstract class
*/
@ -96,11 +110,15 @@ iobase_seek(PyObject *self, PyObject *args)
return iobase_unsupported("seek");
}
PyDoc_STRVAR(iobase_tell_doc,
"Return current stream position.");
/*[clinic input]
_io._IOBase.tell
Return current stream position.
[clinic start generated code]*/
static PyObject *
iobase_tell(PyObject *self, PyObject *args)
_io__IOBase_tell_impl(PyObject *self)
/*[clinic end generated code: output=89a1c0807935abe2 input=04e615fec128801f]*/
{
_Py_IDENTIFIER(seek);
@ -121,13 +139,17 @@ iobase_truncate(PyObject *self, PyObject *args)
/* Flush and close methods */
PyDoc_STRVAR(iobase_flush_doc,
"Flush write buffers, if applicable.\n"
"\n"
"This is not implemented for read-only and non-blocking streams.\n");
/*[clinic input]
_io._IOBase.flush
Flush write buffers, if applicable.
This is not implemented for read-only and non-blocking streams.
[clinic start generated code]*/
static PyObject *
iobase_flush(PyObject *self, PyObject *args)
_io__IOBase_flush_impl(PyObject *self)
/*[clinic end generated code: output=7cef4b4d54656a3b input=773be121abe270aa]*/
{
/* XXX Should this return the number of bytes written??? */
if (IS_CLOSED(self)) {
@ -137,11 +159,6 @@ iobase_flush(PyObject *self, PyObject *args)
Py_RETURN_NONE;
}
PyDoc_STRVAR(iobase_close_doc,
"Flush and close the IO object.\n"
"\n"
"This method has no effect if the file is already closed.\n");
static int
iobase_closed(PyObject *self)
{
@ -180,8 +197,17 @@ _PyIOBase_check_closed(PyObject *self, PyObject *args)
`__IOBase_closed` and call flush() by itself, but it is redundant with
whatever behaviour a non-trivial derived class will implement. */
/*[clinic input]
_io._IOBase.close
Flush and close the IO object.
This method has no effect if the file is already closed.
[clinic start generated code]*/
static PyObject *
iobase_close(PyObject *self, PyObject *args)
_io__IOBase_close_impl(PyObject *self)
/*[clinic end generated code: output=63c6a6f57d783d6d input=f4494d5c31dbc6b7]*/
{
PyObject *res;
@ -304,14 +330,18 @@ iobase_dealloc(iobase *self)
/* Inquiry methods */
PyDoc_STRVAR(iobase_seekable_doc,
"Return whether object supports random access.\n"
"\n"
"If False, seek(), tell() and truncate() will raise UnsupportedOperation.\n"
"This method may need to do a test seek().");
/*[clinic input]
_io._IOBase.seekable
Return whether object supports random access.
If False, seek(), tell() and truncate() will raise UnsupportedOperation.
This method may need to do a test seek().
[clinic start generated code]*/
static PyObject *
iobase_seekable(PyObject *self, PyObject *args)
_io__IOBase_seekable_impl(PyObject *self)
/*[clinic end generated code: output=4c24c67f5f32a43d input=22676eebb81dcf1e]*/
{
Py_RETURN_FALSE;
}
@ -333,13 +363,17 @@ _PyIOBase_check_seekable(PyObject *self, PyObject *args)
return res;
}
PyDoc_STRVAR(iobase_readable_doc,
"Return whether object was opened for reading.\n"
"\n"
"If False, read() will raise UnsupportedOperation.");
/*[clinic input]
_io._IOBase.readable
Return whether object was opened for reading.
If False, read() will raise UnsupportedOperation.
[clinic start generated code]*/
static PyObject *
iobase_readable(PyObject *self, PyObject *args)
_io__IOBase_readable_impl(PyObject *self)
/*[clinic end generated code: output=e48089250686388b input=12fc3d8f6be46434]*/
{
Py_RETURN_FALSE;
}
@ -362,13 +396,17 @@ _PyIOBase_check_readable(PyObject *self, PyObject *args)
return res;
}
PyDoc_STRVAR(iobase_writable_doc,
"Return whether object was opened for writing.\n"
"\n"
"If False, write() will raise UnsupportedOperation.");
/*[clinic input]
_io._IOBase.writable
Return whether object was opened for writing.
If False, write() will raise UnsupportedOperation.
[clinic start generated code]*/
static PyObject *
iobase_writable(PyObject *self, PyObject *args)
_io__IOBase_writable_impl(PyObject *self)
/*[clinic end generated code: output=406001d0985be14f input=c17a0bb6a8dfc590]*/
{
Py_RETURN_FALSE;
}
@ -413,24 +451,32 @@ iobase_exit(PyObject *self, PyObject *args)
/* XXX Should these be present even if unimplemented? */
PyDoc_STRVAR(iobase_fileno_doc,
"Returns underlying file descriptor if one exists.\n"
"\n"
"An IOError is raised if the IO object does not use a file descriptor.\n");
/*[clinic input]
_io._IOBase.fileno
Returns underlying file descriptor if one exists.
An IOError is raised if the IO object does not use a file descriptor.
[clinic start generated code]*/
static PyObject *
iobase_fileno(PyObject *self, PyObject *args)
_io__IOBase_fileno_impl(PyObject *self)
/*[clinic end generated code: output=7cc0973f0f5f3b73 input=32773c5df4b7eede]*/
{
return iobase_unsupported("fileno");
}
PyDoc_STRVAR(iobase_isatty_doc,
"Return whether this is an 'interactive' stream.\n"
"\n"
"Return False if it can't be determined.\n");
/*[clinic input]
_io._IOBase.isatty
Return whether this is an 'interactive' stream.
Return False if it can't be determined.
[clinic start generated code]*/
static PyObject *
iobase_isatty(PyObject *self, PyObject *args)
_io__IOBase_isatty_impl(PyObject *self)
/*[clinic end generated code: output=60cab77cede41cdd input=9ef76530d368458b]*/
{
if (_PyIOBase_check_closed(self, Py_True) == NULL)
return NULL;
@ -439,30 +485,31 @@ iobase_isatty(PyObject *self, PyObject *args)
/* Readline(s) and writelines */
PyDoc_STRVAR(iobase_readline_doc,
"Read and return a line from the stream.\n"
"\n"
"If limit is specified, at most limit bytes will be read.\n"
"\n"
"The line terminator is always b'\\n' for binary files; for text\n"
"files, the newlines argument to open can be used to select the line\n"
"terminator(s) recognized.\n");
/*[clinic input]
_io._IOBase.readline
size as limit: io_ssize_t = -1
/
Read and return a line from the stream.
If size is specified, at most size bytes will be read.
The line terminator is always b'\n' for binary files; for text
files, the newlines argument to open can be used to select the line
terminator(s) recognized.
[clinic start generated code]*/
static PyObject *
iobase_readline(PyObject *self, PyObject *args)
_io__IOBase_readline_impl(PyObject *self, Py_ssize_t limit)
/*[clinic end generated code: output=4479f79b58187840 input=df4cc8884f553cab]*/
{
/* For backwards compatibility, a (slowish) readline(). */
Py_ssize_t limit = -1;
int has_peek = 0;
PyObject *buffer, *result;
Py_ssize_t old_size = -1;
_Py_IDENTIFIER(peek);
if (!PyArg_ParseTuple(args, "|O&:readline", &_PyIO_ConvertSsize_t, &limit)) {
return NULL;
}
if (_PyObject_HasAttrId(self, &PyId_peek))
has_peek = 1;
@ -585,23 +632,25 @@ iobase_iternext(PyObject *self)
return line;
}
PyDoc_STRVAR(iobase_readlines_doc,
"Return a list of lines from the stream.\n"
"\n"
"hint can be specified to control the number of lines read: no more\n"
"lines will be read if the total size (in bytes/characters) of all\n"
"lines so far exceeds hint.");
/*[clinic input]
_io._IOBase.readlines
hint: io_ssize_t = -1
/
Return a list of lines from the stream.
hint can be specified to control the number of lines read: no more
lines will be read if the total size (in bytes/characters) of all
lines so far exceeds hint.
[clinic start generated code]*/
static PyObject *
iobase_readlines(PyObject *self, PyObject *args)
_io__IOBase_readlines_impl(PyObject *self, Py_ssize_t hint)
/*[clinic end generated code: output=2f50421677fa3dea input=1961c4a95e96e661]*/
{
Py_ssize_t hint = -1, length = 0;
Py_ssize_t length = 0;
PyObject *result;
if (!PyArg_ParseTuple(args, "|O&:readlines", &_PyIO_ConvertSsize_t, &hint)) {
return NULL;
}
result = PyList_New(0);
if (result == NULL)
return NULL;
@ -646,14 +695,17 @@ iobase_readlines(PyObject *self, PyObject *args)
return result;
}
static PyObject *
iobase_writelines(PyObject *self, PyObject *args)
{
PyObject *lines, *iter, *res;
/*[clinic input]
_io._IOBase.writelines
lines: object
/
[clinic start generated code]*/
if (!PyArg_ParseTuple(args, "O:writelines", &lines)) {
return NULL;
}
static PyObject *
_io__IOBase_writelines(PyObject *self, PyObject *lines)
/*[clinic end generated code: output=976eb0a9b60a6628 input=432e729a8450b3cb]*/
{
PyObject *iter, *res;
if (_PyIOBase_check_closed(self, Py_True) == NULL)
return NULL;
@ -688,31 +740,33 @@ iobase_writelines(PyObject *self, PyObject *args)
Py_RETURN_NONE;
}
#include "clinic/iobase.c.h"
static PyMethodDef iobase_methods[] = {
{"seek", iobase_seek, METH_VARARGS, iobase_seek_doc},
{"tell", iobase_tell, METH_NOARGS, iobase_tell_doc},
_IO__IOBASE_TELL_METHODDEF
{"truncate", iobase_truncate, METH_VARARGS, iobase_truncate_doc},
{"flush", iobase_flush, METH_NOARGS, iobase_flush_doc},
{"close", iobase_close, METH_NOARGS, iobase_close_doc},
_IO__IOBASE_FLUSH_METHODDEF
_IO__IOBASE_CLOSE_METHODDEF
{"seekable", iobase_seekable, METH_NOARGS, iobase_seekable_doc},
{"readable", iobase_readable, METH_NOARGS, iobase_readable_doc},
{"writable", iobase_writable, METH_NOARGS, iobase_writable_doc},
_IO__IOBASE_SEEKABLE_METHODDEF
_IO__IOBASE_READABLE_METHODDEF
_IO__IOBASE_WRITABLE_METHODDEF
{"_checkClosed", _PyIOBase_check_closed, METH_NOARGS},
{"_checkSeekable", _PyIOBase_check_seekable, METH_NOARGS},
{"_checkReadable", _PyIOBase_check_readable, METH_NOARGS},
{"_checkWritable", _PyIOBase_check_writable, METH_NOARGS},
{"fileno", iobase_fileno, METH_NOARGS, iobase_fileno_doc},
{"isatty", iobase_isatty, METH_NOARGS, iobase_isatty_doc},
_IO__IOBASE_FILENO_METHODDEF
_IO__IOBASE_ISATTY_METHODDEF
{"__enter__", iobase_enter, METH_NOARGS},
{"__exit__", iobase_exit, METH_VARARGS},
{"readline", iobase_readline, METH_VARARGS, iobase_readline_doc},
{"readlines", iobase_readlines, METH_VARARGS, iobase_readlines_doc},
{"writelines", iobase_writelines, METH_VARARGS},
_IO__IOBASE_READLINE_METHODDEF
_IO__IOBASE_READLINES_METHODDEF
_IO__IOBASE_WRITELINES_METHODDEF
{NULL, NULL}
};
@ -795,15 +849,17 @@ PyDoc_STRVAR(rawiobase_doc,
* either.)
*/
static PyObject *
rawiobase_read(PyObject *self, PyObject *args)
{
Py_ssize_t n = -1;
PyObject *b, *res;
/*[clinic input]
_io._RawIOBase.read
size as n: Py_ssize_t = -1
/
[clinic start generated code]*/
if (!PyArg_ParseTuple(args, "|n:read", &n)) {
return NULL;
}
static PyObject *
_io__RawIOBase_read_impl(PyObject *self, Py_ssize_t n)
/*[clinic end generated code: output=6cdeb731e3c9f13c input=b6d0dcf6417d1374]*/
{
PyObject *b, *res;
if (n < 0) {
_Py_IDENTIFIER(readall);
@ -836,11 +892,15 @@ rawiobase_read(PyObject *self, PyObject *args)
}
PyDoc_STRVAR(rawiobase_readall_doc,
"Read until EOF, using multiple read() call.");
/*[clinic input]
_io._RawIOBase.readall
Read until EOF, using multiple read() call.
[clinic start generated code]*/
static PyObject *
rawiobase_readall(PyObject *self, PyObject *args)
_io__RawIOBase_readall_impl(PyObject *self)
/*[clinic end generated code: output=1987b9ce929425a0 input=688874141213622a]*/
{
int r;
PyObject *chunks = PyList_New(0);
@ -893,8 +953,8 @@ rawiobase_readall(PyObject *self, PyObject *args)
}
static PyMethodDef rawiobase_methods[] = {
{"read", rawiobase_read, METH_VARARGS},
{"readall", rawiobase_readall, METH_NOARGS, rawiobase_readall_doc},
_IO__RAWIOBASE_READ_METHODDEF
_IO__RAWIOBASE_READALL_METHODDEF
{NULL, NULL}
};

View File

@ -11,6 +11,12 @@
#define STATE_REALIZED 1
#define STATE_ACCUMULATING 2
/*[clinic input]
module _io
class _io.StringIO "stringio *" "&PyStringIO_Type"
[clinic start generated code]*/
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=c17bc0f42165cd7d]*/
typedef struct {
PyObject_HEAD
Py_UCS4 *buf;
@ -39,6 +45,8 @@ typedef struct {
PyObject *weakreflist;
} stringio;
static int _io_StringIO___init__(PyObject *self, PyObject *args, PyObject *kwargs);
#define CHECK_INITIALIZED(self) \
if (self->ok <= 0) { \
PyErr_SetString(PyExc_ValueError, \
@ -58,12 +66,6 @@ typedef struct {
return NULL; \
}
PyDoc_STRVAR(stringio_doc,
"Text I/O implementation using an in-memory buffer.\n"
"\n"
"The initial_value argument sets the value of object. The newline\n"
"argument is like the one of TextIOWrapper's constructor.");
/* Internal routine for changing the size, in terms of characters, of the
buffer of StringIO objects. The caller should ensure that the 'size'
@ -264,11 +266,15 @@ fail:
return -1;
}
PyDoc_STRVAR(stringio_getvalue_doc,
"Retrieve the entire contents of the object.");
/*[clinic input]
_io.StringIO.getvalue
Retrieve the entire contents of the object.
[clinic start generated code]*/
static PyObject *
stringio_getvalue(stringio *self)
_io_StringIO_getvalue_impl(stringio *self)
/*[clinic end generated code: output=27b6a7bfeaebce01 input=d23cb81d6791cf88]*/
{
CHECK_INITIALIZED(self);
CHECK_CLOSED(self);
@ -278,33 +284,40 @@ stringio_getvalue(stringio *self)
self->string_size);
}
PyDoc_STRVAR(stringio_tell_doc,
"Tell the current file position.");
/*[clinic input]
_io.StringIO.tell
Tell the current file position.
[clinic start generated code]*/
static PyObject *
stringio_tell(stringio *self)
_io_StringIO_tell_impl(stringio *self)
/*[clinic end generated code: output=2e87ac67b116c77b input=ec866ebaff02f405]*/
{
CHECK_INITIALIZED(self);
CHECK_CLOSED(self);
return PyLong_FromSsize_t(self->pos);
}
PyDoc_STRVAR(stringio_read_doc,
"Read at most n characters, returned as a string.\n"
"\n"
"If the argument is negative or omitted, read until EOF\n"
"is reached. Return an empty string at EOF.\n");
/*[clinic input]
_io.StringIO.read
size as arg: object = None
/
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 *
stringio_read(stringio *self, PyObject *args)
_io_StringIO_read_impl(stringio *self, PyObject *arg)
/*[clinic end generated code: output=3676864773746f68 input=9a319015f6f3965c]*/
{
Py_ssize_t size, n;
Py_UCS4 *output;
PyObject *arg = Py_None;
CHECK_INITIALIZED(self);
if (!PyArg_ParseTuple(args, "|O:read", &arg))
return NULL;
CHECK_CLOSED(self);
if (PyNumber_Check(arg)) {
@ -373,20 +386,23 @@ _stringio_readline(stringio *self, Py_ssize_t limit)
return PyUnicode_FromKindAndData(PyUnicode_4BYTE_KIND, start, len);
}
PyDoc_STRVAR(stringio_readline_doc,
"Read until newline or EOF.\n"
"\n"
"Returns an empty string if EOF is hit immediately.\n");
/*[clinic input]
_io.StringIO.readline
size as arg: object = None
/
Read until newline or EOF.
Returns an empty string if EOF is hit immediately.
[clinic start generated code]*/
static PyObject *
stringio_readline(stringio *self, PyObject *args)
_io_StringIO_readline_impl(stringio *self, PyObject *arg)
/*[clinic end generated code: output=99fdcac03a3dee81 input=e0e0ed4042040176]*/
{
PyObject *arg = Py_None;
Py_ssize_t limit = -1;
CHECK_INITIALIZED(self);
if (!PyArg_ParseTuple(args, "|O:readline", &arg))
return NULL;
CHECK_CLOSED(self);
ENSURE_REALIZED(self);
@ -441,22 +457,25 @@ stringio_iternext(stringio *self)
return line;
}
PyDoc_STRVAR(stringio_truncate_doc,
"Truncate size to pos.\n"
"\n"
"The pos argument defaults to the current file position, as\n"
"returned by tell(). The current file position is unchanged.\n"
"Returns the new absolute position.\n");
/*[clinic input]
_io.StringIO.truncate
pos as arg: object = 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 *
stringio_truncate(stringio *self, PyObject *args)
_io_StringIO_truncate_impl(stringio *self, PyObject *arg)
/*[clinic end generated code: output=6072439c2b01d306 input=748619a494ba53ad]*/
{
Py_ssize_t size;
PyObject *arg = Py_None;
CHECK_INITIALIZED(self);
if (!PyArg_ParseTuple(args, "|O:truncate", &arg))
return NULL;
CHECK_CLOSED(self);
if (PyNumber_Check(arg)) {
@ -490,49 +509,51 @@ stringio_truncate(stringio *self, PyObject *args)
return PyLong_FromSsize_t(size);
}
PyDoc_STRVAR(stringio_seek_doc,
"Change stream position.\n"
"\n"
"Seek to character offset pos relative to position indicated by whence:\n"
" 0 Start of stream (the default). pos should be >= 0;\n"
" 1 Current position - pos must be 0;\n"
" 2 End of stream - pos must be 0.\n"
"Returns the new absolute position.\n");
/*[clinic input]
_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 *
stringio_seek(stringio *self, PyObject *args)
_io_StringIO_seek_impl(stringio *self, Py_ssize_t pos, int whence)
/*[clinic end generated code: output=e9e0ac9a8ae71c25 input=e3855b24e7cae06a]*/
{
Py_ssize_t pos;
int mode = 0;
CHECK_INITIALIZED(self);
if (!PyArg_ParseTuple(args, "n|i:seek", &pos, &mode))
return NULL;
CHECK_CLOSED(self);
if (mode != 0 && mode != 1 && mode != 2) {
if (whence != 0 && whence != 1 && whence != 2) {
PyErr_Format(PyExc_ValueError,
"Invalid whence (%i, should be 0, 1 or 2)", mode);
"Invalid whence (%i, should be 0, 1 or 2)", whence);
return NULL;
}
else if (pos < 0 && mode == 0) {
else if (pos < 0 && whence == 0) {
PyErr_Format(PyExc_ValueError,
"Negative seek position %zd", pos);
return NULL;
}
else if (mode != 0 && pos != 0) {
else if (whence != 0 && pos != 0) {
PyErr_SetString(PyExc_IOError,
"Can't do nonzero cur-relative seeks");
return NULL;
}
/* mode 0: offset relative to beginning of the string.
mode 1: no change to current position.
mode 2: change position to end of file. */
if (mode == 1) {
/* whence = 0: offset relative to beginning of the string.
whence = 1: no change to current position.
whence = 2: change position to end of file. */
if (whence == 1) {
pos = self->pos;
}
else if (mode == 2) {
else if (whence == 2) {
pos = self->string_size;
}
@ -541,14 +562,20 @@ stringio_seek(stringio *self, PyObject *args)
return PyLong_FromSsize_t(self->pos);
}
PyDoc_STRVAR(stringio_write_doc,
"Write string to file.\n"
"\n"
"Returns the number of characters written, which is always equal to\n"
"the length of the string.\n");
/*[clinic input]
_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 *
stringio_write(stringio *self, PyObject *obj)
_io_StringIO_write(stringio *self, PyObject *obj)
/*[clinic end generated code: output=0deaba91a15b94da input=cf96f3b16586e669]*/
{
Py_ssize_t size;
@ -569,14 +596,20 @@ stringio_write(stringio *self, PyObject *obj)
return PyLong_FromSsize_t(size);
}
PyDoc_STRVAR(stringio_close_doc,
"Close the IO object. Attempting any further operation after the\n"
"object is closed will raise a ValueError.\n"
"\n"
"This method has no effect if the file is already closed.\n");
/*[clinic input]
_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 *
stringio_close(stringio *self)
_io_StringIO_close_impl(stringio *self)
/*[clinic end generated code: output=04399355cbe518f1 input=cbc10b45f35d6d46]*/
{
self->closed = 1;
/* Free up some memory */
@ -644,19 +677,25 @@ stringio_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
return (PyObject *)self;
}
/*[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
stringio_init(stringio *self, PyObject *args, PyObject *kwds)
_io_StringIO___init___impl(stringio *self, PyObject *value,
PyObject *newline_obj)
/*[clinic end generated code: output=a421ea023b22ef4e input=cee2d9181b2577a3]*/
{
char *kwlist[] = {"initial_value", "newline", NULL};
PyObject *value = NULL;
PyObject *newline_obj = NULL;
char *newline = "\n";
Py_ssize_t value_len;
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO:__init__", kwlist,
&value, &newline_obj))
return -1;
/* Parse the newline argument. This used to be done with the 'z'
specifier, however this allowed any object with the buffer interface to
be converted. Thus we have to parse it manually since we only want to
@ -761,33 +800,45 @@ stringio_init(stringio *self, PyObject *args, PyObject *kwds)
/* Properties and pseudo-properties */
PyDoc_STRVAR(stringio_readable_doc,
"readable() -> bool. Returns True if the IO object can be read.");
/*[clinic input]
_io.StringIO.readable
PyDoc_STRVAR(stringio_writable_doc,
"writable() -> bool. Returns True if the IO object can be written.");
PyDoc_STRVAR(stringio_seekable_doc,
"seekable() -> bool. Returns True if the IO object can be seeked.");
Returns True if the IO object can be read.
[clinic start generated code]*/
static PyObject *
stringio_seekable(stringio *self, PyObject *args)
_io_StringIO_readable_impl(stringio *self)
/*[clinic end generated code: output=b19d44dd8b1ceb99 input=39ce068b224c21ad]*/
{
CHECK_INITIALIZED(self);
CHECK_CLOSED(self);
Py_RETURN_TRUE;
}
/*[clinic input]
_io.StringIO.writable
Returns True if the IO object can be written.
[clinic start generated code]*/
static PyObject *
stringio_readable(stringio *self, PyObject *args)
_io_StringIO_writable_impl(stringio *self)
/*[clinic end generated code: output=13e4dd77187074ca input=7a691353aac38835]*/
{
CHECK_INITIALIZED(self);
CHECK_CLOSED(self);
Py_RETURN_TRUE;
}
/*[clinic input]
_io.StringIO.seekable
Returns True if the IO object can be seeked.
[clinic start generated code]*/
static PyObject *
stringio_writable(stringio *self, PyObject *args)
_io_StringIO_seekable_impl(stringio *self)
/*[clinic end generated code: output=4d20b4641c756879 input=4c606d05b32952e6]*/
{
CHECK_INITIALIZED(self);
CHECK_CLOSED(self);
@ -809,7 +860,7 @@ stringio_writable(stringio *self, PyObject *args)
static PyObject *
stringio_getstate(stringio *self)
{
PyObject *initvalue = stringio_getvalue(self);
PyObject *initvalue = _io_StringIO_getvalue_impl(self);
PyObject *dict;
PyObject *state;
@ -857,7 +908,7 @@ stringio_setstate(stringio *self, PyObject *state)
initarg = PyTuple_GetSlice(state, 0, 2);
if (initarg == NULL)
return NULL;
if (stringio_init(self, initarg, NULL) < 0) {
if (_io_StringIO___init__((PyObject *)self, initarg, NULL) < 0) {
Py_DECREF(initarg);
return NULL;
}
@ -959,19 +1010,21 @@ stringio_newlines(stringio *self, void *context)
return PyObject_GetAttr(self->decoder, _PyIO_str_newlines);
}
static struct PyMethodDef stringio_methods[] = {
{"close", (PyCFunction)stringio_close, METH_NOARGS, stringio_close_doc},
{"getvalue", (PyCFunction)stringio_getvalue, METH_NOARGS, stringio_getvalue_doc},
{"read", (PyCFunction)stringio_read, METH_VARARGS, stringio_read_doc},
{"readline", (PyCFunction)stringio_readline, METH_VARARGS, stringio_readline_doc},
{"tell", (PyCFunction)stringio_tell, METH_NOARGS, stringio_tell_doc},
{"truncate", (PyCFunction)stringio_truncate, METH_VARARGS, stringio_truncate_doc},
{"seek", (PyCFunction)stringio_seek, METH_VARARGS, stringio_seek_doc},
{"write", (PyCFunction)stringio_write, METH_O, stringio_write_doc},
#include "clinic/stringio.c.h"
{"seekable", (PyCFunction)stringio_seekable, METH_NOARGS, stringio_seekable_doc},
{"readable", (PyCFunction)stringio_readable, METH_NOARGS, stringio_readable_doc},
{"writable", (PyCFunction)stringio_writable, METH_NOARGS, stringio_writable_doc},
static struct PyMethodDef stringio_methods[] = {
_IO_STRINGIO_CLOSE_METHODDEF
_IO_STRINGIO_GETVALUE_METHODDEF
_IO_STRINGIO_READ_METHODDEF
_IO_STRINGIO_READLINE_METHODDEF
_IO_STRINGIO_TELL_METHODDEF
_IO_STRINGIO_TRUNCATE_METHODDEF
_IO_STRINGIO_SEEK_METHODDEF
_IO_STRINGIO_WRITE_METHODDEF
_IO_STRINGIO_SEEKABLE_METHODDEF
_IO_STRINGIO_READABLE_METHODDEF
_IO_STRINGIO_WRITABLE_METHODDEF
{"__getstate__", (PyCFunction)stringio_getstate, METH_NOARGS},
{"__setstate__", (PyCFunction)stringio_setstate, METH_O},
@ -1013,7 +1066,7 @@ PyTypeObject PyStringIO_Type = {
0, /*tp_as_buffer*/
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE
| Py_TPFLAGS_HAVE_GC, /*tp_flags*/
stringio_doc, /*tp_doc*/
_io_StringIO___init____doc__, /*tp_doc*/
(traverseproc)stringio_traverse, /*tp_traverse*/
(inquiry)stringio_clear, /*tp_clear*/
0, /*tp_richcompare*/
@ -1028,7 +1081,7 @@ PyTypeObject PyStringIO_Type = {
0, /*tp_descr_get*/
0, /*tp_descr_set*/
offsetof(stringio, dict), /*tp_dictoffset*/
(initproc)stringio_init, /*tp_init*/
_io_StringIO___init__, /*tp_init*/
0, /*tp_alloc*/
stringio_new, /*tp_new*/
};

View File

@ -11,6 +11,20 @@
#include "structmember.h"
#include "_iomodule.h"
/*[clinic input]
module _io
class _io.IncrementalNewlineDecoder "nldecoder_object *" "&PyIncrementalNewlineDecoder_Type"
class _io.TextIOWrapper "textio *" "&TextIOWrapper_TYpe"
[clinic start generated code]*/
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=2097a4fc85670c26]*/
/*[python input]
class io_ssize_t_converter(CConverter):
type = 'Py_ssize_t'
converter = '_PyIO_ConvertSsize_t'
[python start generated code]*/
/*[python end generated code: output=da39a3ee5e6b4b0d input=d0a811d3cbfd1b33]*/
_Py_IDENTIFIER(close);
_Py_IDENTIFIER(_dealloc_warn);
_Py_IDENTIFIER(decode);
@ -210,16 +224,6 @@ PyTypeObject PyTextIOBase_Type = {
/* IncrementalNewlineDecoder */
PyDoc_STRVAR(incrementalnewlinedecoder_doc,
"Codec used when reading a file in universal newlines mode. It wraps\n"
"another incremental decoder, translating \\r\\n and \\r into \\n. It also\n"
"records the types of newlines encountered. When used with\n"
"translate=False, it ensures that the newline sequence is returned in\n"
"one piece. When used with decoder=None, it expects unicode strings as\n"
"decode input and translates newlines without first invoking an external\n"
"decoder.\n"
);
typedef struct {
PyObject_HEAD
PyObject *decoder;
@ -229,19 +233,28 @@ typedef struct {
unsigned int seennl: 3;
} nldecoder_object;
/*[clinic input]
_io.IncrementalNewlineDecoder.__init__
decoder: object
translate: int
errors: object(c_default="NULL") = "strict"
Codec used when reading a file in universal newlines mode.
It wraps another incremental decoder, translating \r\n and \r into \n.
It also records the types of newlines encountered. When used with
translate=False, it ensures that the newline sequence is returned in
one piece. When used with decoder=None, it expects unicode strings as
decode input and translates newlines without first invoking an external
decoder.
[clinic start generated code]*/
static int
incrementalnewlinedecoder_init(nldecoder_object *self,
PyObject *args, PyObject *kwds)
_io_IncrementalNewlineDecoder___init___impl(nldecoder_object *self,
PyObject *decoder, int translate,
PyObject *errors)
/*[clinic end generated code: output=fbd04d443e764ec2 input=89db6b19c6b126bf]*/
{
PyObject *decoder;
int translate;
PyObject *errors = NULL;
char *kwlist[] = {"decoder", "translate", "errors", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwds, "Oi|O:IncrementalNewlineDecoder",
kwlist, &decoder, &translate, &errors))
return -1;
self->decoder = decoder;
Py_INCREF(decoder);
@ -495,22 +508,27 @@ _PyIncrementalNewlineDecoder_decode(PyObject *myself,
return NULL;
}
static PyObject *
incrementalnewlinedecoder_decode(nldecoder_object *self,
PyObject *args, PyObject *kwds)
{
char *kwlist[] = {"input", "final", NULL};
PyObject *input;
int final = 0;
/*[clinic input]
_io.IncrementalNewlineDecoder.decode
input: object
final: int(c_default="0") = False
[clinic start generated code]*/
if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|i:IncrementalNewlineDecoder",
kwlist, &input, &final))
return NULL;
static PyObject *
_io_IncrementalNewlineDecoder_decode_impl(nldecoder_object *self,
PyObject *input, int final)
/*[clinic end generated code: output=0d486755bb37a66e input=d65677385bfd6827]*/
{
return _PyIncrementalNewlineDecoder_decode((PyObject *) self, input, final);
}
/*[clinic input]
_io.IncrementalNewlineDecoder.getstate
[clinic start generated code]*/
static PyObject *
incrementalnewlinedecoder_getstate(nldecoder_object *self, PyObject *args)
_io_IncrementalNewlineDecoder_getstate_impl(nldecoder_object *self)
/*[clinic end generated code: output=f0d2c9c136f4e0d0 input=f8ff101825e32e7f]*/
{
PyObject *buffer;
unsigned PY_LONG_LONG flag;
@ -537,8 +555,16 @@ incrementalnewlinedecoder_getstate(nldecoder_object *self, PyObject *args)
return Py_BuildValue("NK", buffer, flag);
}
/*[clinic input]
_io.IncrementalNewlineDecoder.setstate
state: object
/
[clinic start generated code]*/
static PyObject *
incrementalnewlinedecoder_setstate(nldecoder_object *self, PyObject *state)
_io_IncrementalNewlineDecoder_setstate(nldecoder_object *self,
PyObject *state)
/*[clinic end generated code: output=c10c622508b576cb input=c53fb505a76dbbe2]*/
{
PyObject *buffer;
unsigned PY_LONG_LONG flag;
@ -556,8 +582,13 @@ incrementalnewlinedecoder_setstate(nldecoder_object *self, PyObject *state)
Py_RETURN_NONE;
}
/*[clinic input]
_io.IncrementalNewlineDecoder.reset
[clinic start generated code]*/
static PyObject *
incrementalnewlinedecoder_reset(nldecoder_object *self, PyObject *args)
_io_IncrementalNewlineDecoder_reset_impl(nldecoder_object *self)
/*[clinic end generated code: output=32fa40c7462aa8ff input=728678ddaea776df]*/
{
self->seennl = 0;
self->pendingcr = 0;
@ -591,95 +622,8 @@ incrementalnewlinedecoder_newlines_get(nldecoder_object *self, void *context)
}
static PyMethodDef incrementalnewlinedecoder_methods[] = {
{"decode", (PyCFunction)incrementalnewlinedecoder_decode, METH_VARARGS|METH_KEYWORDS},
{"getstate", (PyCFunction)incrementalnewlinedecoder_getstate, METH_NOARGS},
{"setstate", (PyCFunction)incrementalnewlinedecoder_setstate, METH_O},
{"reset", (PyCFunction)incrementalnewlinedecoder_reset, METH_NOARGS},
{NULL}
};
static PyGetSetDef incrementalnewlinedecoder_getset[] = {
{"newlines", (getter)incrementalnewlinedecoder_newlines_get, NULL, NULL},
{NULL}
};
PyTypeObject PyIncrementalNewlineDecoder_Type = {
PyVarObject_HEAD_INIT(NULL, 0)
"_io.IncrementalNewlineDecoder", /*tp_name*/
sizeof(nldecoder_object), /*tp_basicsize*/
0, /*tp_itemsize*/
(destructor)incrementalnewlinedecoder_dealloc, /*tp_dealloc*/
0, /*tp_print*/
0, /*tp_getattr*/
0, /*tp_setattr*/
0, /*tp_compare */
0, /*tp_repr*/
0, /*tp_as_number*/
0, /*tp_as_sequence*/
0, /*tp_as_mapping*/
0, /*tp_hash */
0, /*tp_call*/
0, /*tp_str*/
0, /*tp_getattro*/
0, /*tp_setattro*/
0, /*tp_as_buffer*/
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
incrementalnewlinedecoder_doc, /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /*tp_weaklistoffset*/
0, /* tp_iter */
0, /* tp_iternext */
incrementalnewlinedecoder_methods, /* tp_methods */
0, /* tp_members */
incrementalnewlinedecoder_getset, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
(initproc)incrementalnewlinedecoder_init, /* tp_init */
0, /* tp_alloc */
PyType_GenericNew, /* tp_new */
};
/* TextIOWrapper */
PyDoc_STRVAR(textiowrapper_doc,
"Character and line based layer over a BufferedIOBase object, buffer.\n"
"\n"
"encoding gives the name of the encoding that the stream will be\n"
"decoded or encoded with. It defaults to locale.getpreferredencoding(False).\n"
"\n"
"errors determines the strictness of encoding and decoding (see\n"
"help(codecs.Codec) or the documentation for codecs.register) and\n"
"defaults to \"strict\".\n"
"\n"
"newline controls how line endings are handled. It can be None, '',\n"
"'\\n', '\\r', and '\\r\\n'. It works as follows:\n"
"\n"
"* On input, if newline is None, universal newlines mode is\n"
" enabled. Lines in the input can end in '\\n', '\\r', or '\\r\\n', and\n"
" these are translated into '\\n' before being returned to the\n"
" caller. If it is '', universal newline mode is enabled, but line\n"
" endings are returned to the caller untranslated. If it has any of\n"
" the other legal values, input lines are only terminated by the given\n"
" string, and the line ending is returned to the caller untranslated.\n"
"\n"
"* On output, if newline is None, any '\\n' characters written are\n"
" translated to the system default line separator, os.linesep. If\n"
" newline is '' or '\\n', no translation takes place. If newline is any\n"
" of the other legal values, any '\\n' characters written are translated\n"
" to the given string.\n"
"\n"
"If line_buffering is True, a call to flush is implied when a call to\n"
"write contains a newline character."
);
typedef PyObject *
(*encodefunc_t)(PyObject *, PyObject *);
@ -742,7 +686,6 @@ typedef struct
PyObject *dict;
} textio;
/* A couple of specialized cases in order to bypass the slow incremental
encoding methods for the most popular encodings. */
@ -843,28 +786,59 @@ static encodefuncentry encodefuncs[] = {
};
static int
textiowrapper_init(textio *self, PyObject *args, PyObject *kwds)
{
char *kwlist[] = {"buffer", "encoding", "errors",
"newline", "line_buffering", "write_through",
NULL};
PyObject *buffer, *raw, *codec_info = NULL;
char *encoding = NULL;
char *errors = NULL;
char *newline = NULL;
int line_buffering = 0, write_through = 0;
_PyIO_State *state = NULL;
/*[clinic input]
_io.TextIOWrapper.__init__
buffer: object
encoding: str(nullable=True) = NULL
errors: str(nullable=True) = NULL
newline: str(nullable=True) = NULL
line_buffering: int(c_default="0") = False
write_through: int(c_default="0") = False
Character and line based layer over a BufferedIOBase object, buffer.
encoding gives the name of the encoding that the stream will be
decoded or encoded with. It defaults to locale.getpreferredencoding(False).
errors determines the strictness of encoding and decoding (see
help(codecs.Codec) or the documentation for codecs.register) and
defaults to "strict".
newline controls how line endings are handled. It can be None, '',
'\n', '\r', and '\r\n'. It works as follows:
* On input, if newline is None, universal newlines mode is
enabled. Lines in the input can end in '\n', '\r', or '\r\n', and
these are translated into '\n' before being returned to the
caller. If it is '', universal newline mode is enabled, but line
endings are returned to the caller untranslated. If it has any of
the other legal values, input lines are only terminated by the given
string, and the line ending is returned to the caller untranslated.
* On output, if newline is None, any '\n' characters written are
translated to the system default line separator, os.linesep. If
newline is '' or '\n', no translation takes place. If newline is any
of the other legal values, any '\n' characters written are translated
to the given string.
If line_buffering is True, a call to flush is implied when a call to
write contains a newline character.
[clinic start generated code]*/
static int
_io_TextIOWrapper___init___impl(textio *self, PyObject *buffer,
const char *encoding, const char *errors,
const char *newline, int line_buffering,
int write_through)
/*[clinic end generated code: output=56a83402ce2a8381 input=1f20decb8d54a4ec]*/
{
PyObject *raw, *codec_info = NULL;
_PyIO_State *state = NULL;
PyObject *res;
int r;
self->ok = 0;
self->detached = 0;
if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|zzzii:fileio",
kwlist, &buffer, &encoding, &errors,
&newline, &line_buffering, &write_through))
return -1;
if (newline && newline[0] != '\0'
&& !(newline[0] == '\n' && newline[1] == '\0')
@ -1244,8 +1218,13 @@ textiowrapper_closed_get(textio *self, void *context);
}
/*[clinic input]
_io.TextIOWrapper.detach
[clinic start generated code]*/
static PyObject *
textiowrapper_detach(textio *self)
_io_TextIOWrapper_detach_impl(textio *self)
/*[clinic end generated code: output=7ba3715cd032d5f2 input=e5a71fbda9e1d9f9]*/
{
PyObject *buffer, *res;
CHECK_ATTACHED(self);
@ -1290,25 +1269,26 @@ _textiowrapper_writeflush(textio *self)
return 0;
}
/*[clinic input]
_io.TextIOWrapper.write
text: unicode
/
[clinic start generated code]*/
static PyObject *
textiowrapper_write(textio *self, PyObject *args)
_io_TextIOWrapper_write_impl(textio *self, PyObject *text)
/*[clinic end generated code: output=d2deb0d50771fcec input=fdf19153584a0e44]*/
{
PyObject *ret;
PyObject *text; /* owned reference */
PyObject *b;
Py_ssize_t textlen;
int haslf = 0;
int needflush = 0, text_needflush = 0;
CHECK_ATTACHED(self);
if (!PyArg_ParseTuple(args, "U:write", &text)) {
return NULL;
}
if (PyUnicode_READY(text) == -1)
return NULL;
CHECK_ATTACHED(self);
CHECK_CLOSED(self);
if (self->encoder == NULL)
@ -1557,17 +1537,19 @@ textiowrapper_read_chunk(textio *self, Py_ssize_t size_hint)
return -1;
}
/*[clinic input]
_io.TextIOWrapper.read
size as n: io_ssize_t = -1
/
[clinic start generated code]*/
static PyObject *
textiowrapper_read(textio *self, PyObject *args)
_io_TextIOWrapper_read_impl(textio *self, Py_ssize_t n)
/*[clinic end generated code: output=7e651ce6cc6a25a6 input=8c09398424085cca]*/
{
Py_ssize_t n = -1;
PyObject *result = NULL, *chunks = NULL;
CHECK_ATTACHED(self);
if (!PyArg_ParseTuple(args, "|O&:read", &_PyIO_ConvertSsize_t, &n))
return NULL;
CHECK_CLOSED(self);
if (self->decoder == NULL)
@ -1933,16 +1915,18 @@ _textiowrapper_readline(textio *self, Py_ssize_t limit)
return NULL;
}
static PyObject *
textiowrapper_readline(textio *self, PyObject *args)
{
Py_ssize_t limit = -1;
/*[clinic input]
_io.TextIOWrapper.readline
size: Py_ssize_t = -1
/
[clinic start generated code]*/
static PyObject *
_io_TextIOWrapper_readline_impl(textio *self, Py_ssize_t size)
/*[clinic end generated code: output=344afa98804e8b25 input=56c7172483b36db6]*/
{
CHECK_ATTACHED(self);
if (!PyArg_ParseTuple(args, "|n:readline", &limit)) {
return NULL;
}
return _textiowrapper_readline(self, limit);
return _textiowrapper_readline(self, size);
}
/* Seek and Tell */
@ -2074,19 +2058,23 @@ _textiowrapper_encoder_setstate(textio *self, cookie_type *cookie)
self, cookie->start_pos == 0 && cookie->dec_flags == 0);
}
/*[clinic input]
_io.TextIOWrapper.seek
cookie as cookieObj: object
whence: int = 0
/
[clinic start generated code]*/
static PyObject *
textiowrapper_seek(textio *self, PyObject *args)
_io_TextIOWrapper_seek_impl(textio *self, PyObject *cookieObj, int whence)
/*[clinic end generated code: output=0a15679764e2d04d input=0458abeb3d7842be]*/
{
PyObject *cookieObj, *posobj;
PyObject *posobj;
cookie_type cookie;
int whence = 0;
PyObject *res;
int cmp;
CHECK_ATTACHED(self);
if (!PyArg_ParseTuple(args, "O|i:seek", &cookieObj, &whence))
return NULL;
CHECK_CLOSED(self);
Py_INCREF(cookieObj);
@ -2258,8 +2246,13 @@ textiowrapper_seek(textio *self, PyObject *args)
}
/*[clinic input]
_io.TextIOWrapper.tell
[clinic start generated code]*/
static PyObject *
textiowrapper_tell(textio *self, PyObject *args)
_io_TextIOWrapper_tell_impl(textio *self)
/*[clinic end generated code: output=4f168c08bf34ad5f input=9a2caf88c24f9ddf]*/
{
PyObject *res;
PyObject *posobj = NULL;
@ -2466,16 +2459,19 @@ fail:
return NULL;
}
/*[clinic input]
_io.TextIOWrapper.truncate
pos: object = None
/
[clinic start generated code]*/
static PyObject *
textiowrapper_truncate(textio *self, PyObject *args)
_io_TextIOWrapper_truncate_impl(textio *self, PyObject *pos)
/*[clinic end generated code: output=90ec2afb9bb7745f input=56ec8baa65aea377]*/
{
PyObject *pos = Py_None;
PyObject *res;
CHECK_ATTACHED(self)
if (!PyArg_ParseTuple(args, "|O:truncate", &pos)) {
return NULL;
}
res = PyObject_CallMethodObjArgs((PyObject *) self, _PyIO_str_flush, NULL);
if (res == NULL)
@ -2540,36 +2536,61 @@ error:
/* Inquiries */
/*[clinic input]
_io.TextIOWrapper.fileno
[clinic start generated code]*/
static PyObject *
textiowrapper_fileno(textio *self, PyObject *args)
_io_TextIOWrapper_fileno_impl(textio *self)
/*[clinic end generated code: output=21490a4c3da13e6c input=c488ca83d0069f9b]*/
{
CHECK_ATTACHED(self);
return _PyObject_CallMethodId(self->buffer, &PyId_fileno, NULL);
}
/*[clinic input]
_io.TextIOWrapper.seekable
[clinic start generated code]*/
static PyObject *
textiowrapper_seekable(textio *self, PyObject *args)
_io_TextIOWrapper_seekable_impl(textio *self)
/*[clinic end generated code: output=ab223dbbcffc0f00 input=8b005ca06e1fca13]*/
{
CHECK_ATTACHED(self);
return _PyObject_CallMethodId(self->buffer, &PyId_seekable, NULL);
}
/*[clinic input]
_io.TextIOWrapper.readable
[clinic start generated code]*/
static PyObject *
textiowrapper_readable(textio *self, PyObject *args)
_io_TextIOWrapper_readable_impl(textio *self)
/*[clinic end generated code: output=72ff7ba289a8a91b input=0704ea7e01b0d3eb]*/
{
CHECK_ATTACHED(self);
return _PyObject_CallMethodId(self->buffer, &PyId_readable, NULL);
}
/*[clinic input]
_io.TextIOWrapper.writable
[clinic start generated code]*/
static PyObject *
textiowrapper_writable(textio *self, PyObject *args)
_io_TextIOWrapper_writable_impl(textio *self)
/*[clinic end generated code: output=a728c71790d03200 input=c41740bc9d8636e8]*/
{
CHECK_ATTACHED(self);
return _PyObject_CallMethodId(self->buffer, &PyId_writable, NULL);
}
/*[clinic input]
_io.TextIOWrapper.isatty
[clinic start generated code]*/
static PyObject *
textiowrapper_isatty(textio *self, PyObject *args)
_io_TextIOWrapper_isatty_impl(textio *self)
/*[clinic end generated code: output=12be1a35bace882e input=fb68d9f2c99bbfff]*/
{
CHECK_ATTACHED(self);
return _PyObject_CallMethodId(self->buffer, &PyId_isatty, NULL);
@ -2583,8 +2604,13 @@ textiowrapper_getstate(textio *self, PyObject *args)
return NULL;
}
/*[clinic input]
_io.TextIOWrapper.flush
[clinic start generated code]*/
static PyObject *
textiowrapper_flush(textio *self, PyObject *args)
_io_TextIOWrapper_flush_impl(textio *self)
/*[clinic end generated code: output=59de9165f9c2e4d2 input=928c60590694ab85]*/
{
CHECK_ATTACHED(self);
CHECK_CLOSED(self);
@ -2594,8 +2620,13 @@ textiowrapper_flush(textio *self, PyObject *args)
return _PyObject_CallMethodId(self->buffer, &PyId_flush, NULL);
}
/*[clinic input]
_io.TextIOWrapper.close
[clinic start generated code]*/
static PyObject *
textiowrapper_close(textio *self, PyObject *args)
_io_TextIOWrapper_close_impl(textio *self)
/*[clinic end generated code: output=056ccf8b4876e4f4 input=9c2114315eae1948]*/
{
PyObject *res;
int r;
@ -2739,24 +2770,81 @@ textiowrapper_chunk_size_set(textio *self, PyObject *arg, void *context)
return 0;
}
static PyMethodDef textiowrapper_methods[] = {
{"detach", (PyCFunction)textiowrapper_detach, METH_NOARGS},
{"write", (PyCFunction)textiowrapper_write, METH_VARARGS},
{"read", (PyCFunction)textiowrapper_read, METH_VARARGS},
{"readline", (PyCFunction)textiowrapper_readline, METH_VARARGS},
{"flush", (PyCFunction)textiowrapper_flush, METH_NOARGS},
{"close", (PyCFunction)textiowrapper_close, METH_NOARGS},
#include "clinic/textio.c.h"
{"fileno", (PyCFunction)textiowrapper_fileno, METH_NOARGS},
{"seekable", (PyCFunction)textiowrapper_seekable, METH_NOARGS},
{"readable", (PyCFunction)textiowrapper_readable, METH_NOARGS},
{"writable", (PyCFunction)textiowrapper_writable, METH_NOARGS},
{"isatty", (PyCFunction)textiowrapper_isatty, METH_NOARGS},
static PyMethodDef incrementalnewlinedecoder_methods[] = {
_IO_INCREMENTALNEWLINEDECODER_DECODE_METHODDEF
_IO_INCREMENTALNEWLINEDECODER_GETSTATE_METHODDEF
_IO_INCREMENTALNEWLINEDECODER_SETSTATE_METHODDEF
_IO_INCREMENTALNEWLINEDECODER_RESET_METHODDEF
{NULL}
};
static PyGetSetDef incrementalnewlinedecoder_getset[] = {
{"newlines", (getter)incrementalnewlinedecoder_newlines_get, NULL, NULL},
{NULL}
};
PyTypeObject PyIncrementalNewlineDecoder_Type = {
PyVarObject_HEAD_INIT(NULL, 0)
"_io.IncrementalNewlineDecoder", /*tp_name*/
sizeof(nldecoder_object), /*tp_basicsize*/
0, /*tp_itemsize*/
(destructor)incrementalnewlinedecoder_dealloc, /*tp_dealloc*/
0, /*tp_print*/
0, /*tp_getattr*/
0, /*tp_setattr*/
0, /*tp_compare */
0, /*tp_repr*/
0, /*tp_as_number*/
0, /*tp_as_sequence*/
0, /*tp_as_mapping*/
0, /*tp_hash */
0, /*tp_call*/
0, /*tp_str*/
0, /*tp_getattro*/
0, /*tp_setattro*/
0, /*tp_as_buffer*/
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
_io_IncrementalNewlineDecoder___init____doc__, /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /*tp_weaklistoffset*/
0, /* tp_iter */
0, /* tp_iternext */
incrementalnewlinedecoder_methods, /* tp_methods */
0, /* tp_members */
incrementalnewlinedecoder_getset, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
_io_IncrementalNewlineDecoder___init__, /* tp_init */
0, /* tp_alloc */
PyType_GenericNew, /* tp_new */
};
static PyMethodDef textiowrapper_methods[] = {
_IO_TEXTIOWRAPPER_DETACH_METHODDEF
_IO_TEXTIOWRAPPER_WRITE_METHODDEF
_IO_TEXTIOWRAPPER_READ_METHODDEF
_IO_TEXTIOWRAPPER_READLINE_METHODDEF
_IO_TEXTIOWRAPPER_FLUSH_METHODDEF
_IO_TEXTIOWRAPPER_CLOSE_METHODDEF
_IO_TEXTIOWRAPPER_FILENO_METHODDEF
_IO_TEXTIOWRAPPER_SEEKABLE_METHODDEF
_IO_TEXTIOWRAPPER_READABLE_METHODDEF
_IO_TEXTIOWRAPPER_WRITABLE_METHODDEF
_IO_TEXTIOWRAPPER_ISATTY_METHODDEF
{"__getstate__", (PyCFunction)textiowrapper_getstate, METH_NOARGS},
{"seek", (PyCFunction)textiowrapper_seek, METH_VARARGS},
{"tell", (PyCFunction)textiowrapper_tell, METH_NOARGS},
{"truncate", (PyCFunction)textiowrapper_truncate, METH_VARARGS},
_IO_TEXTIOWRAPPER_SEEK_METHODDEF
_IO_TEXTIOWRAPPER_TELL_METHODDEF
_IO_TEXTIOWRAPPER_TRUNCATE_METHODDEF
{NULL, NULL}
};
@ -2802,7 +2890,7 @@ PyTypeObject PyTextIOWrapper_Type = {
0, /*tp_as_buffer*/
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE
| Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_HAVE_FINALIZE, /*tp_flags*/
textiowrapper_doc, /* tp_doc */
_io_TextIOWrapper___init____doc__, /* tp_doc */
(traverseproc)textiowrapper_traverse, /* tp_traverse */
(inquiry)textiowrapper_clear, /* tp_clear */
0, /* tp_richcompare */
@ -2817,7 +2905,7 @@ PyTypeObject PyTextIOWrapper_Type = {
0, /* tp_descr_get */
0, /* tp_descr_set */
offsetof(textio, dict), /*tp_dictoffset*/
(initproc)textiowrapper_init, /* tp_init */
_io_TextIOWrapper___init__, /* tp_init */
0, /* tp_alloc */
PyType_GenericNew, /* tp_new */
0, /* tp_free */