Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
680bf1af
Commit
680bf1af
authored
Jun 12, 2009
by
Benjamin Peterson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
move to a naming scheme with all lowercase and underscores
parent
2c3ac6b8
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
660 additions
and
665 deletions
+660
-665
Modules/_io/_iomodule.c
Modules/_io/_iomodule.c
+4
-4
Modules/_io/_iomodule.h
Modules/_io/_iomodule.h
+4
-4
Modules/_io/bufferedio.c
Modules/_io/bufferedio.c
+301
-303
Modules/_io/bytesio.c
Modules/_io/bytesio.c
+30
-30
Modules/_io/fileio.c
Modules/_io/fileio.c
+32
-32
Modules/_io/iobase.c
Modules/_io/iobase.c
+91
-91
Modules/_io/stringio.c
Modules/_io/stringio.c
+29
-29
Modules/_io/textio.c
Modules/_io/textio.c
+169
-172
No files found.
Modules/_io/_iomodule.c
View file @
680bf1af
...
...
@@ -94,7 +94,7 @@ PyDoc_STRVAR(module_doc,
*/
static
int
BlockingIOE
rror_init
(
PyBlockingIOErrorObject
*
self
,
PyObject
*
args
,
blockingioe
rror_init
(
PyBlockingIOErrorObject
*
self
,
PyObject
*
args
,
PyObject
*
kwds
)
{
PyObject
*
myerrno
=
NULL
,
*
strerror
=
NULL
;
...
...
@@ -123,7 +123,7 @@ BlockingIOError_init(PyBlockingIOErrorObject *self, PyObject *args,
return
0
;
}
static
PyMemberDef
BlockingIOE
rror_members
[]
=
{
static
PyMemberDef
blockingioe
rror_members
[]
=
{
{
"characters_written"
,
T_PYSSIZET
,
offsetof
(
PyBlockingIOErrorObject
,
written
),
0
},
{
NULL
}
/* Sentinel */
};
...
...
@@ -158,14 +158,14 @@ static PyTypeObject _PyExc_BlockingIOError = {
0
,
/* tp_iter */
0
,
/* tp_iternext */
0
,
/* tp_methods */
BlockingIOE
rror_members
,
/* tp_members */
blockingioe
rror_members
,
/* tp_members */
0
,
/* tp_getset */
0
,
/* tp_base */
0
,
/* tp_dict */
0
,
/* tp_descr_get */
0
,
/* tp_descr_set */
0
,
/* tp_dictoffset */
(
initproc
)
BlockingIOE
rror_init
,
/* tp_init */
(
initproc
)
blockingioe
rror_init
,
/* tp_init */
0
,
/* tp_alloc */
0
,
/* tp_new */
};
...
...
Modules/_io/_iomodule.h
View file @
680bf1af
...
...
@@ -23,10 +23,10 @@ extern PyTypeObject PyIncrementalNewlineDecoder_Type;
* with args=NULL, and return a new reference.
* BUT when args=Py_True is passed, they return a borrowed reference.
*/
extern
PyObject
*
_PyIOBase_check
R
eadable
(
PyObject
*
self
,
PyObject
*
args
);
extern
PyObject
*
_PyIOBase_check
W
ritable
(
PyObject
*
self
,
PyObject
*
args
);
extern
PyObject
*
_PyIOBase_check
S
eekable
(
PyObject
*
self
,
PyObject
*
args
);
extern
PyObject
*
_PyIOBase_check
C
losed
(
PyObject
*
self
,
PyObject
*
args
);
extern
PyObject
*
_PyIOBase_check
_r
eadable
(
PyObject
*
self
,
PyObject
*
args
);
extern
PyObject
*
_PyIOBase_check
_w
ritable
(
PyObject
*
self
,
PyObject
*
args
);
extern
PyObject
*
_PyIOBase_check
_s
eekable
(
PyObject
*
self
,
PyObject
*
args
);
extern
PyObject
*
_PyIOBase_check
_c
losed
(
PyObject
*
self
,
PyObject
*
args
);
/* Helper for finalization.
This function will revive an object ready to be deallocated and try to
...
...
Modules/_io/bufferedio.c
View file @
680bf1af
...
...
@@ -16,7 +16,7 @@
/*
* BufferedIOBase class, inherits from IOBase.
*/
PyDoc_STRVAR
(
BufferedIOB
ase_doc
,
PyDoc_STRVAR
(
bufferediob
ase_doc
,
"Base class for buffered IO objects.
\n
"
"
\n
"
"The main difference with RawIOBase is that the read() method
\n
"
...
...
@@ -33,7 +33,7 @@ PyDoc_STRVAR(BufferedIOBase_doc,
);
static
PyObject
*
BufferedIOB
ase_readinto
(
PyObject
*
self
,
PyObject
*
args
)
bufferediob
ase_readinto
(
PyObject
*
self
,
PyObject
*
args
)
{
Py_buffer
buf
;
Py_ssize_t
len
;
...
...
@@ -67,25 +67,25 @@ BufferedIOBase_readinto(PyObject *self, PyObject *args)
}
static
PyObject
*
BufferedIOB
ase_unsupported
(
const
char
*
message
)
bufferediob
ase_unsupported
(
const
char
*
message
)
{
PyErr_SetString
(
IO_STATE
->
unsupported_operation
,
message
);
return
NULL
;
}
PyDoc_STRVAR
(
BufferedIOB
ase_detach_doc
,
PyDoc_STRVAR
(
bufferediob
ase_detach_doc
,
"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.
\n
"
);
static
PyObject
*
BufferedIOB
ase_detach
(
PyObject
*
self
)
bufferediob
ase_detach
(
PyObject
*
self
)
{
return
BufferedIOB
ase_unsupported
(
"detach"
);
return
bufferediob
ase_unsupported
(
"detach"
);
}
PyDoc_STRVAR
(
BufferedIOB
ase_read_doc
,
PyDoc_STRVAR
(
bufferediob
ase_read_doc
,
"Read and return up to n bytes.
\n
"
"
\n
"
"If the argument is omitted, None, or negative, reads and
\n
"
...
...
@@ -104,12 +104,12 @@ PyDoc_STRVAR(BufferedIOBase_read_doc,
"mode and no data is available at the moment.
\n
"
);
static
PyObject
*
BufferedIOB
ase_read
(
PyObject
*
self
,
PyObject
*
args
)
bufferediob
ase_read
(
PyObject
*
self
,
PyObject
*
args
)
{
return
BufferedIOB
ase_unsupported
(
"read"
);
return
bufferediob
ase_unsupported
(
"read"
);
}
PyDoc_STRVAR
(
BufferedIOB
ase_read1_doc
,
PyDoc_STRVAR
(
bufferediob
ase_read1_doc
,
"Read and return up to n bytes, with at most one read() call
\n
"
"to the underlying raw stream. A short result does not imply
\n
"
"that EOF is imminent.
\n
"
...
...
@@ -117,12 +117,12 @@ PyDoc_STRVAR(BufferedIOBase_read1_doc,
"Returns an empty bytes object on EOF.
\n
"
);
static
PyObject
*
BufferedIOB
ase_read1
(
PyObject
*
self
,
PyObject
*
args
)
bufferediob
ase_read1
(
PyObject
*
self
,
PyObject
*
args
)
{
return
BufferedIOB
ase_unsupported
(
"read1"
);
return
bufferediob
ase_unsupported
(
"read1"
);
}
PyDoc_STRVAR
(
BufferedIOB
ase_write_doc
,
PyDoc_STRVAR
(
bufferediob
ase_write_doc
,
"Write the given buffer to the IO stream.
\n
"
"
\n
"
"Returns the number of bytes written, which is never less than
\n
"
...
...
@@ -132,18 +132,18 @@ PyDoc_STRVAR(BufferedIOBase_write_doc,
"underlying raw stream cannot accept more data at the moment.
\n
"
);
static
PyObject
*
BufferedIOB
ase_write
(
PyObject
*
self
,
PyObject
*
args
)
bufferediob
ase_write
(
PyObject
*
self
,
PyObject
*
args
)
{
return
BufferedIOB
ase_unsupported
(
"write"
);
return
bufferediob
ase_unsupported
(
"write"
);
}
static
PyMethodDef
BufferedIOB
ase_methods
[]
=
{
{
"detach"
,
(
PyCFunction
)
BufferedIOBase_detach
,
METH_NOARGS
,
BufferedIOB
ase_detach_doc
},
{
"read"
,
BufferedIOBase_read
,
METH_VARARGS
,
BufferedIOB
ase_read_doc
},
{
"read1"
,
BufferedIOBase_read1
,
METH_VARARGS
,
BufferedIOB
ase_read1_doc
},
{
"readinto"
,
BufferedIOB
ase_readinto
,
METH_VARARGS
,
NULL
},
{
"write"
,
BufferedIOBase_write
,
METH_VARARGS
,
BufferedIOB
ase_write_doc
},
static
PyMethodDef
bufferediob
ase_methods
[]
=
{
{
"detach"
,
(
PyCFunction
)
bufferediobase_detach
,
METH_NOARGS
,
bufferediob
ase_detach_doc
},
{
"read"
,
bufferediobase_read
,
METH_VARARGS
,
bufferediob
ase_read_doc
},
{
"read1"
,
bufferediobase_read1
,
METH_VARARGS
,
bufferediob
ase_read1_doc
},
{
"readinto"
,
bufferediob
ase_readinto
,
METH_VARARGS
,
NULL
},
{
"write"
,
bufferediobase_write
,
METH_VARARGS
,
bufferediob
ase_write_doc
},
{
NULL
,
NULL
}
};
...
...
@@ -168,14 +168,14 @@ PyTypeObject PyBufferedIOBase_Type = {
0
,
/*tp_setattro*/
0
,
/*tp_as_buffer*/
Py_TPFLAGS_DEFAULT
|
Py_TPFLAGS_BASETYPE
,
/*tp_flags*/
BufferedIOB
ase_doc
,
/* tp_doc */
bufferediob
ase_doc
,
/* tp_doc */
0
,
/* tp_traverse */
0
,
/* tp_clear */
0
,
/* tp_richcompare */
0
,
/* tp_weaklistoffset */
0
,
/* tp_iter */
0
,
/* tp_iternext */
BufferedIOB
ase_methods
,
/* tp_methods */
bufferediob
ase_methods
,
/* tp_methods */
0
,
/* tp_members */
0
,
/* tp_getset */
&
PyIOBase_Type
,
/* tp_base */
...
...
@@ -231,7 +231,7 @@ typedef struct {
PyObject
*
dict
;
PyObject
*
weakreflist
;
}
BufferedObject
;
}
buffered
;
/*
Implementation notes:
...
...
@@ -245,19 +245,18 @@ typedef struct {
* The absolute position of the raw stream is cached, if possible, in the
`abs_pos` member. It must be updated every time an operation is done
on the raw stream. If not sure, it can be reinitialized by calling
_
Buffered_raw_tell(), which queries the raw stream (_B
uffered_raw_seek()
_
buffered_raw_tell(), which queries the raw stream (_b
uffered_raw_seek()
also does it). To read it, use RAW_TELL().
* Three helpers, _
BufferedReader_raw_read, _BufferedW
riter_raw_write and
_
BufferedW
riter_flush_unlocked do a lot of useful housekeeping.
* Three helpers, _
bufferedreader_raw_read, _bufferedw
riter_raw_write and
_
bufferedw
riter_flush_unlocked do a lot of useful housekeeping.
NOTE: we should try to maintain block alignment of reads and writes to the
raw stream (according to the buffer size), but for now it is only done
in read() and friends.
XXX: method naming is a bit messy.
*/
/* These macros protect the
BufferedO
bject against concurrent operations. */
/* These macros protect the
buffered o
bject against concurrent operations. */
#ifdef WITH_THREAD
#define ENTER_BUFFERED(self) \
...
...
@@ -299,7 +298,7 @@ typedef struct {
#define IS_CLOSED(self) \
(self->fast_closed_checks \
? _PyFileIO_closed(self->raw) \
:
BufferedIOMixin
_closed(self))
:
buffered
_closed(self))
#define CHECK_CLOSED(self, error_msg) \
if (IS_CLOSED(self)) { \
...
...
@@ -330,7 +329,7 @@ typedef struct {
&& self->raw_pos >= 0) ? self->raw_pos - self->pos : 0)
#define RAW_TELL(self) \
(self->abs_pos != -1 ? self->abs_pos : _
B
uffered_raw_tell(self))
(self->abs_pos != -1 ? self->abs_pos : _
b
uffered_raw_tell(self))
#define MINUS_LAST_BLOCK(self, size) \
(self->buffer_mask ? \
...
...
@@ -339,7 +338,7 @@ typedef struct {
static
void
BufferedObject_dealloc
(
BufferedObject
*
self
)
buffered_dealloc
(
buffered
*
self
)
{
if
(
self
->
ok
&&
_PyIOBase_finalize
((
PyObject
*
)
self
)
<
0
)
return
;
...
...
@@ -363,7 +362,7 @@ BufferedObject_dealloc(BufferedObject *self)
}
static
int
Buffered_traverse
(
BufferedObject
*
self
,
visitproc
visit
,
void
*
arg
)
buffered_traverse
(
buffered
*
self
,
visitproc
visit
,
void
*
arg
)
{
Py_VISIT
(
self
->
raw
);
Py_VISIT
(
self
->
dict
);
...
...
@@ -371,7 +370,7 @@ Buffered_traverse(BufferedObject *self, visitproc visit, void *arg)
}
static
int
Buffered_clear
(
BufferedObject
*
self
)
buffered_clear
(
buffered
*
self
)
{
if
(
self
->
ok
&&
_PyIOBase_finalize
((
PyObject
*
)
self
)
<
0
)
return
-
1
;
...
...
@@ -390,14 +389,14 @@ Buffered_clear(BufferedObject *self)
/* Flush and close */
static
PyObject
*
BufferedIOMixin_flush
(
BufferedObject
*
self
,
PyObject
*
args
)
buffered_simple_flush
(
buffered
*
self
,
PyObject
*
args
)
{
CHECK_INITIALIZED
(
self
)
return
PyObject_CallMethodObjArgs
(
self
->
raw
,
_PyIO_str_flush
,
NULL
);
}
static
int
BufferedIOMixin_closed
(
BufferedObject
*
self
)
buffered_closed
(
buffered
*
self
)
{
int
closed
;
PyObject
*
res
;
...
...
@@ -411,14 +410,14 @@ BufferedIOMixin_closed(BufferedObject *self)
}
static
PyObject
*
BufferedIOMixin_closed_get
(
BufferedObject
*
self
,
void
*
context
)
buffered_closed_get
(
buffered
*
self
,
void
*
context
)
{
CHECK_INITIALIZED
(
self
)
return
PyObject_GetAttr
(
self
->
raw
,
_PyIO_str_closed
);
}
static
PyObject
*
BufferedIOMixin_close
(
BufferedObject
*
self
,
PyObject
*
args
)
buffered_close
(
buffered
*
self
,
PyObject
*
args
)
{
PyObject
*
res
=
NULL
;
int
r
;
...
...
@@ -426,7 +425,7 @@ BufferedIOMixin_close(BufferedObject *self, PyObject *args)
CHECK_INITIALIZED
(
self
)
ENTER_BUFFERED
(
self
)
r
=
BufferedIOMixin
_closed
(
self
);
r
=
buffered
_closed
(
self
);
if
(
r
<
0
)
goto
end
;
if
(
r
>
0
)
{
...
...
@@ -457,7 +456,7 @@ end:
/* detach */
static
PyObject
*
BufferedIOMixin_detach
(
BufferedObject
*
self
,
PyObject
*
args
)
buffered_detach
(
buffered
*
self
,
PyObject
*
args
)
{
PyObject
*
raw
,
*
res
;
CHECK_INITIALIZED
(
self
)
...
...
@@ -475,35 +474,35 @@ BufferedIOMixin_detach(BufferedObject *self, PyObject *args)
/* Inquiries */
static
PyObject
*
BufferedIOMixin_seekable
(
BufferedObject
*
self
,
PyObject
*
args
)
buffered_seekable
(
buffered
*
self
,
PyObject
*
args
)
{
CHECK_INITIALIZED
(
self
)
return
PyObject_CallMethodObjArgs
(
self
->
raw
,
_PyIO_str_seekable
,
NULL
);
}
static
PyObject
*
BufferedIOMixin_readable
(
BufferedObject
*
self
,
PyObject
*
args
)
buffered_readable
(
buffered
*
self
,
PyObject
*
args
)
{
CHECK_INITIALIZED
(
self
)
return
PyObject_CallMethodObjArgs
(
self
->
raw
,
_PyIO_str_readable
,
NULL
);
}
static
PyObject
*
BufferedIOMixin_writable
(
BufferedObject
*
self
,
PyObject
*
args
)
buffered_writable
(
buffered
*
self
,
PyObject
*
args
)
{
CHECK_INITIALIZED
(
self
)
return
PyObject_CallMethodObjArgs
(
self
->
raw
,
_PyIO_str_writable
,
NULL
);
}
static
PyObject
*
BufferedIOMixin_name_get
(
BufferedObject
*
self
,
void
*
context
)
buffered_name_get
(
buffered
*
self
,
void
*
context
)
{
CHECK_INITIALIZED
(
self
)
return
PyObject_GetAttrString
(
self
->
raw
,
"name"
);
}
static
PyObject
*
BufferedIOMixin_mode_get
(
BufferedObject
*
self
,
void
*
context
)
buffered_mode_get
(
buffered
*
self
,
void
*
context
)
{
CHECK_INITIALIZED
(
self
)
return
PyObject_GetAttrString
(
self
->
raw
,
"mode"
);
...
...
@@ -512,14 +511,14 @@ BufferedIOMixin_mode_get(BufferedObject *self, void *context)
/* Lower-level APIs */
static
PyObject
*
BufferedIOMixin_fileno
(
BufferedObject
*
self
,
PyObject
*
args
)
buffered_fileno
(
buffered
*
self
,
PyObject
*
args
)
{
CHECK_INITIALIZED
(
self
)
return
PyObject_CallMethodObjArgs
(
self
->
raw
,
_PyIO_str_fileno
,
NULL
);
}
static
PyObject
*
BufferedIOMixin_isatty
(
BufferedObject
*
self
,
PyObject
*
args
)
buffered_isatty
(
buffered
*
self
,
PyObject
*
args
)
{
CHECK_INITIALIZED
(
self
)
return
PyObject_CallMethodObjArgs
(
self
->
raw
,
_PyIO_str_isatty
,
NULL
);
...
...
@@ -528,21 +527,21 @@ BufferedIOMixin_isatty(BufferedObject *self, PyObject *args)
/* Forward decls */
static
PyObject
*
_
BufferedWriter_flush_unlocked
(
BufferedObject
*
,
int
);
_
bufferedwriter_flush_unlocked
(
buffered
*
,
int
);
static
Py_ssize_t
_
BufferedReader_fill_buffer
(
BufferedObject
*
self
);
_
bufferedreader_fill_buffer
(
buffered
*
self
);
static
void
_
BufferedReader_reset_buf
(
BufferedObject
*
self
);
_
bufferedreader_reset_buf
(
buffered
*
self
);
static
void
_
BufferedWriter_reset_buf
(
BufferedObject
*
self
);
_
bufferedwriter_reset_buf
(
buffered
*
self
);
static
PyObject
*
_
BufferedReader_peek_unlocked
(
BufferedObject
*
self
,
Py_ssize_t
);
_
bufferedreader_peek_unlocked
(
buffered
*
self
,
Py_ssize_t
);
static
PyObject
*
_
BufferedReader_read_all
(
BufferedObject
*
self
);
_
bufferedreader_read_all
(
buffered
*
self
);
static
PyObject
*
_
BufferedReader_read_fast
(
BufferedObject
*
self
,
Py_ssize_t
);
_
bufferedreader_read_fast
(
buffered
*
self
,
Py_ssize_t
);
static
PyObject
*
_
BufferedReader_read_generic
(
BufferedObject
*
self
,
Py_ssize_t
);
_
bufferedreader_read_generic
(
buffered
*
self
,
Py_ssize_t
);
/*
...
...
@@ -552,7 +551,7 @@ _BufferedReader_read_generic(BufferedObject *self, Py_ssize_t);
/* Returns the address of the `written` member if a BlockingIOError was
raised, NULL otherwise. The error is always re-raised. */
static
Py_ssize_t
*
_
B
uffered_check_blocking_error
(
void
)
_
b
uffered_check_blocking_error
(
void
)
{
PyObject
*
t
,
*
v
,
*
tb
;
PyBlockingIOErrorObject
*
err
;
...
...
@@ -569,7 +568,7 @@ _Buffered_check_blocking_error(void)
}
static
Py_off_t
_
Buffered_raw_tell
(
BufferedObject
*
self
)
_
buffered_raw_tell
(
buffered
*
self
)
{
Py_off_t
n
;
PyObject
*
res
;
...
...
@@ -589,7 +588,7 @@ _Buffered_raw_tell(BufferedObject *self)
}
static
Py_off_t
_
Buffered_raw_seek
(
BufferedObject
*
self
,
Py_off_t
target
,
int
whence
)
_
buffered_raw_seek
(
buffered
*
self
,
Py_off_t
target
,
int
whence
)
{
PyObject
*
res
,
*
posobj
,
*
whenceobj
;
Py_off_t
n
;
...
...
@@ -621,7 +620,7 @@ _Buffered_raw_seek(BufferedObject *self, Py_off_t target, int whence)
}
static
int
_
Buffered_init
(
BufferedObject
*
self
)
_
buffered_init
(
buffered
*
self
)
{
Py_ssize_t
n
;
if
(
self
->
buffer_size
<=
0
)
{
...
...
@@ -651,7 +650,7 @@ _Buffered_init(BufferedObject *self)
self
->
buffer_mask
=
self
->
buffer_size
-
1
;
else
self
->
buffer_mask
=
0
;
if
(
_
B
uffered_raw_tell
(
self
)
==
-
1
)
if
(
_
b
uffered_raw_tell
(
self
)
==
-
1
)
PyErr_Clear
();
return
0
;
}
...
...
@@ -661,7 +660,7 @@ _Buffered_init(BufferedObject *self)
*/
static
PyObject
*
Buffered_flush
(
BufferedObject
*
self
,
PyObject
*
args
)
buffered_flush
(
buffered
*
self
,
PyObject
*
args
)
{
PyObject
*
res
;
...
...
@@ -669,15 +668,15 @@ Buffered_flush(BufferedObject *self, PyObject *args)
CHECK_CLOSED
(
self
,
"flush of closed file"
)
ENTER_BUFFERED
(
self
)
res
=
_
BufferedW
riter_flush_unlocked
(
self
,
0
);
res
=
_
bufferedw
riter_flush_unlocked
(
self
,
0
);
if
(
res
!=
NULL
&&
self
->
readable
)
{
/* Rewind the raw stream so that its position corresponds to
the current logical position. */
Py_off_t
n
;
n
=
_
B
uffered_raw_seek
(
self
,
-
RAW_OFFSET
(
self
),
1
);
n
=
_
b
uffered_raw_seek
(
self
,
-
RAW_OFFSET
(
self
),
1
);
if
(
n
==
-
1
)
Py_CLEAR
(
res
);
_
BufferedR
eader_reset_buf
(
self
);
_
bufferedr
eader_reset_buf
(
self
);
}
LEAVE_BUFFERED
(
self
)
...
...
@@ -685,7 +684,7 @@ Buffered_flush(BufferedObject *self, PyObject *args)
}
static
PyObject
*
Buffered_peek
(
BufferedObject
*
self
,
PyObject
*
args
)
buffered_peek
(
buffered
*
self
,
PyObject
*
args
)
{
Py_ssize_t
n
=
0
;
PyObject
*
res
=
NULL
;
...
...
@@ -698,12 +697,12 @@ Buffered_peek(BufferedObject *self, PyObject *args)
ENTER_BUFFERED
(
self
)
if
(
self
->
writable
)
{
res
=
_
BufferedW
riter_flush_unlocked
(
self
,
1
);
res
=
_
bufferedw
riter_flush_unlocked
(
self
,
1
);
if
(
res
==
NULL
)
goto
end
;
Py_CLEAR
(
res
);
}
res
=
_
BufferedR
eader_peek_unlocked
(
self
,
n
);
res
=
_
bufferedr
eader_peek_unlocked
(
self
,
n
);
end:
LEAVE_BUFFERED
(
self
)
...
...
@@ -711,7 +710,7 @@ end:
}
static
PyObject
*
Buffered_read
(
BufferedObject
*
self
,
PyObject
*
args
)
buffered_read
(
buffered
*
self
,
PyObject
*
args
)
{
Py_ssize_t
n
=
-
1
;
PyObject
*
res
;
...
...
@@ -731,15 +730,15 @@ Buffered_read(BufferedObject *self, PyObject *args)
if
(
n
==
-
1
)
{
/* The number of bytes is unspecified, read until the end of stream */
ENTER_BUFFERED
(
self
)
res
=
_
BufferedR
eader_read_all
(
self
);
res
=
_
bufferedr
eader_read_all
(
self
);
LEAVE_BUFFERED
(
self
)
}
else
{
res
=
_
BufferedR
eader_read_fast
(
self
,
n
);
res
=
_
bufferedr
eader_read_fast
(
self
,
n
);
if
(
res
==
Py_None
)
{
Py_DECREF
(
res
);
ENTER_BUFFERED
(
self
)
res
=
_
BufferedR
eader_read_generic
(
self
,
n
);
res
=
_
bufferedr
eader_read_generic
(
self
,
n
);
LEAVE_BUFFERED
(
self
)
}
}
...
...
@@ -748,7 +747,7 @@ Buffered_read(BufferedObject *self, PyObject *args)
}
static
PyObject
*
Buffered_read1
(
BufferedObject
*
self
,
PyObject
*
args
)
buffered_read1
(
buffered
*
self
,
PyObject
*
args
)
{
Py_ssize_t
n
,
have
,
r
;
PyObject
*
res
=
NULL
;
...
...
@@ -769,7 +768,7 @@ Buffered_read1(BufferedObject *self, PyObject *args)
ENTER_BUFFERED
(
self
)
if
(
self
->
writable
)
{
res
=
_
BufferedW
riter_flush_unlocked
(
self
,
1
);
res
=
_
bufferedw
riter_flush_unlocked
(
self
,
1
);
if
(
res
==
NULL
)
goto
end
;
Py_CLEAR
(
res
);
...
...
@@ -795,8 +794,8 @@ Buffered_read1(BufferedObject *self, PyObject *args)
}
/* Fill the buffer from the raw stream, and copy it to the result. */
_
BufferedR
eader_reset_buf
(
self
);
r
=
_
BufferedR
eader_fill_buffer
(
self
);
_
bufferedr
eader_reset_buf
(
self
);
r
=
_
bufferedr
eader_fill_buffer
(
self
);
if
(
r
==
-
1
)
goto
end
;
if
(
r
==
-
2
)
...
...
@@ -814,7 +813,7 @@ end:
}
static
PyObject
*
Buffered_readinto
(
BufferedObject
*
self
,
PyObject
*
args
)
buffered_readinto
(
buffered
*
self
,
PyObject
*
args
)
{
PyObject
*
res
=
NULL
;
...
...
@@ -823,20 +822,20 @@ Buffered_readinto(BufferedObject *self, PyObject *args)
/* TODO: use raw.readinto() instead! */
if
(
self
->
writable
)
{
ENTER_BUFFERED
(
self
)
res
=
_
BufferedW
riter_flush_unlocked
(
self
,
0
);
res
=
_
bufferedw
riter_flush_unlocked
(
self
,
0
);
LEAVE_BUFFERED
(
self
)
if
(
res
==
NULL
)
goto
end
;
Py_DECREF
(
res
);
}
res
=
BufferedIOB
ase_readinto
((
PyObject
*
)
self
,
args
);
res
=
bufferediob
ase_readinto
((
PyObject
*
)
self
,
args
);
end:
return
res
;
}
static
PyObject
*
_
Buffered_readline
(
BufferedObject
*
self
,
Py_ssize_t
limit
)
_
buffered_readline
(
buffered
*
self
,
Py_ssize_t
limit
)
{
PyObject
*
res
=
NULL
;
PyObject
*
chunks
=
NULL
;
...
...
@@ -870,7 +869,7 @@ _Buffered_readline(BufferedObject *self, Py_ssize_t limit)
/* Now we try to get some more from the raw stream */
if
(
self
->
writable
)
{
res
=
_
BufferedW
riter_flush_unlocked
(
self
,
1
);
res
=
_
bufferedw
riter_flush_unlocked
(
self
,
1
);
if
(
res
==
NULL
)
goto
end
;
Py_CLEAR
(
res
);
...
...
@@ -893,8 +892,8 @@ _Buffered_readline(BufferedObject *self, Py_ssize_t limit)
}
for
(;;)
{
_
BufferedR
eader_reset_buf
(
self
);
n
=
_
BufferedR
eader_fill_buffer
(
self
);
_
bufferedr
eader_reset_buf
(
self
);
n
=
_
bufferedr
eader_fill_buffer
(
self
);
if
(
n
==
-
1
)
goto
end
;
if
(
n
<=
0
)
...
...
@@ -945,7 +944,7 @@ end_unlocked:
}
static
PyObject
*
Buffered_readline
(
BufferedObject
*
self
,
PyObject
*
args
)
buffered_readline
(
buffered
*
self
,
PyObject
*
args
)
{
Py_ssize_t
limit
=
-
1
;
...
...
@@ -954,17 +953,17 @@ Buffered_readline(BufferedObject *self, PyObject *args)
if
(
!
PyArg_ParseTuple
(
args
,
"|n:readline"
,
&
limit
))
{
return
NULL
;
}
return
_
B
uffered_readline
(
self
,
limit
);
return
_
b
uffered_readline
(
self
,
limit
);
}
static
PyObject
*
Buffered_tell
(
BufferedObject
*
self
,
PyObject
*
args
)
buffered_tell
(
buffered
*
self
,
PyObject
*
args
)
{
Py_off_t
pos
;
CHECK_INITIALIZED
(
self
)
pos
=
_
B
uffered_raw_tell
(
self
);
pos
=
_
b
uffered_raw_tell
(
self
);
if
(
pos
==
-
1
)
return
NULL
;
pos
-=
RAW_OFFSET
(
self
);
...
...
@@ -973,7 +972,7 @@ Buffered_tell(BufferedObject *self, PyObject *args)
}
static
PyObject
*
Buffered_seek
(
BufferedObject
*
self
,
PyObject
*
args
)
buffered_seek
(
buffered
*
self
,
PyObject
*
args
)
{
Py_off_t
target
,
n
;
int
whence
=
0
;
...
...
@@ -1022,23 +1021,23 @@ Buffered_seek(BufferedObject *self, PyObject *args)
/* Fallback: invoke raw seek() method and clear buffer */
if
(
self
->
writable
)
{
res
=
_
BufferedW
riter_flush_unlocked
(
self
,
0
);
res
=
_
bufferedw
riter_flush_unlocked
(
self
,
0
);
if
(
res
==
NULL
)
goto
end
;
Py_CLEAR
(
res
);
_
BufferedW
riter_reset_buf
(
self
);
_
bufferedw
riter_reset_buf
(
self
);
}
/* TODO: align on block boundary and read buffer if needed? */
if
(
whence
==
1
)
target
-=
RAW_OFFSET
(
self
);
n
=
_
B
uffered_raw_seek
(
self
,
target
,
whence
);
n
=
_
b
uffered_raw_seek
(
self
,
target
,
whence
);
if
(
n
==
-
1
)
goto
end
;
self
->
raw_pos
=
-
1
;
res
=
PyLong_FromOff_t
(
n
);
if
(
res
!=
NULL
&&
self
->
readable
)
_
BufferedR
eader_reset_buf
(
self
);
_
bufferedr
eader_reset_buf
(
self
);
end:
LEAVE_BUFFERED
(
self
)
...
...
@@ -1046,7 +1045,7 @@ end:
}
static
PyObject
*
Buffered_truncate
(
BufferedObject
*
self
,
PyObject
*
args
)
buffered_truncate
(
buffered
*
self
,
PyObject
*
args
)
{
PyObject
*
pos
=
Py_None
;
PyObject
*
res
=
NULL
;
...
...
@@ -1059,7 +1058,7 @@ Buffered_truncate(BufferedObject *self, PyObject *args)
ENTER_BUFFERED
(
self
)
if
(
self
->
writable
)
{
res
=
_
BufferedW
riter_flush_unlocked
(
self
,
0
);
res
=
_
bufferedw
riter_flush_unlocked
(
self
,
0
);
if
(
res
==
NULL
)
goto
end
;
Py_CLEAR
(
res
);
...
...
@@ -1068,16 +1067,16 @@ Buffered_truncate(BufferedObject *self, PyObject *args)
if
(
pos
==
Py_None
)
{
/* Rewind the raw stream so that its position corresponds to
the current logical position. */
if
(
_
B
uffered_raw_seek
(
self
,
-
RAW_OFFSET
(
self
),
1
)
==
-
1
)
if
(
_
b
uffered_raw_seek
(
self
,
-
RAW_OFFSET
(
self
),
1
)
==
-
1
)
goto
end
;
}
_
BufferedR
eader_reset_buf
(
self
);
_
bufferedr
eader_reset_buf
(
self
);
}
res
=
PyObject_CallMethodObjArgs
(
self
->
raw
,
_PyIO_str_truncate
,
pos
,
NULL
);
if
(
res
==
NULL
)
goto
end
;
/* Reset cached position */
if
(
_
B
uffered_raw_tell
(
self
)
==
-
1
)
if
(
_
b
uffered_raw_tell
(
self
)
==
-
1
)
PyErr_Clear
();
end:
...
...
@@ -1086,7 +1085,7 @@ end:
}
static
PyObject
*
Buffered_iternext
(
BufferedObject
*
self
)
buffered_iternext
(
buffered
*
self
)
{
PyObject
*
line
;
PyTypeObject
*
tp
;
...
...
@@ -1097,7 +1096,7 @@ Buffered_iternext(BufferedObject *self)
if
(
tp
==
&
PyBufferedReader_Type
||
tp
==
&
PyBufferedRandom_Type
)
{
/* Skip method call overhead for speed */
line
=
_
B
uffered_readline
(
self
,
-
1
);
line
=
_
b
uffered_readline
(
self
,
-
1
);
}
else
{
line
=
PyObject_CallMethodObjArgs
((
PyObject
*
)
self
,
...
...
@@ -1124,7 +1123,7 @@ Buffered_iternext(BufferedObject *self)
}
static
PyObject
*
Buffered_repr
(
BufferedObject
*
self
)
buffered_repr
(
buffered
*
self
)
{
PyObject
*
nameobj
,
*
res
;
...
...
@@ -1148,16 +1147,16 @@ Buffered_repr(BufferedObject *self)
* class BufferedReader
*/
PyDoc_STRVAR
(
BufferedR
eader_doc
,
PyDoc_STRVAR
(
bufferedr
eader_doc
,
"Create a new buffered reader using the given readable raw IO object."
);
static
void
_
BufferedReader_reset_buf
(
BufferedObject
*
self
)
static
void
_
bufferedreader_reset_buf
(
buffered
*
self
)
{
self
->
read_end
=
-
1
;
}
static
int
BufferedReader_init
(
BufferedObject
*
self
,
PyObject
*
args
,
PyObject
*
kwds
)
bufferedreader_init
(
buffered
*
self
,
PyObject
*
args
,
PyObject
*
kwds
)
{
char
*
kwlist
[]
=
{
"raw"
,
"buffer_size"
,
NULL
};
Py_ssize_t
buffer_size
=
DEFAULT_BUFFER_SIZE
;
...
...
@@ -1171,7 +1170,7 @@ BufferedReader_init(BufferedObject *self, PyObject *args, PyObject *kwds)
return
-
1
;
}
if
(
_PyIOBase_check
R
eadable
(
raw
,
Py_True
)
==
NULL
)
if
(
_PyIOBase_check
_r
eadable
(
raw
,
Py_True
)
==
NULL
)
return
-
1
;
Py_CLEAR
(
self
->
raw
);
...
...
@@ -1181,9 +1180,9 @@ BufferedReader_init(BufferedObject *self, PyObject *args, PyObject *kwds)
self
->
readable
=
1
;
self
->
writable
=
0
;
if
(
_
B
uffered_init
(
self
)
<
0
)
if
(
_
b
uffered_init
(
self
)
<
0
)
return
-
1
;
_
BufferedR
eader_reset_buf
(
self
);
_
bufferedr
eader_reset_buf
(
self
);
self
->
fast_closed_checks
=
(
Py_TYPE
(
self
)
==
&
PyBufferedReader_Type
&&
Py_TYPE
(
raw
)
==
&
PyFileIO_Type
);
...
...
@@ -1193,7 +1192,7 @@ BufferedReader_init(BufferedObject *self, PyObject *args, PyObject *kwds)
}
static
Py_ssize_t
_
BufferedReader_raw_read
(
BufferedObject
*
self
,
char
*
start
,
Py_ssize_t
len
)
_
bufferedreader_raw_read
(
buffered
*
self
,
char
*
start
,
Py_ssize_t
len
)
{
Py_buffer
buf
;
PyObject
*
memobj
,
*
res
;
...
...
@@ -1227,7 +1226,7 @@ _BufferedReader_raw_read(BufferedObject *self, char *start, Py_ssize_t len)
}
static
Py_ssize_t
_
BufferedReader_fill_buffer
(
BufferedObject
*
self
)
_
bufferedreader_fill_buffer
(
buffered
*
self
)
{
Py_ssize_t
start
,
len
,
n
;
if
(
VALID_READ_BUFFER
(
self
))
...
...
@@ -1235,7 +1234,7 @@ _BufferedReader_fill_buffer(BufferedObject *self)
else
start
=
0
;
len
=
self
->
buffer_size
-
start
;
n
=
_
BufferedR
eader_raw_read
(
self
,
self
->
buffer
+
start
,
len
);
n
=
_
bufferedr
eader_raw_read
(
self
,
self
->
buffer
+
start
,
len
);
if
(
n
<=
0
)
return
n
;
self
->
read_end
=
start
+
n
;
...
...
@@ -1244,7 +1243,7 @@ _BufferedReader_fill_buffer(BufferedObject *self)
}
static
PyObject
*
_
BufferedReader_read_all
(
BufferedObject
*
self
)
_
bufferedreader_read_all
(
buffered
*
self
)
{
Py_ssize_t
current_size
;
PyObject
*
res
,
*
data
=
NULL
;
...
...
@@ -1263,10 +1262,10 @@ _BufferedReader_read_all(BufferedObject *self)
return
NULL
;
}
}
_
BufferedR
eader_reset_buf
(
self
);
_
bufferedr
eader_reset_buf
(
self
);
/* We're going past the buffer's bounds, flush it */
if
(
self
->
writable
)
{
res
=
_
BufferedW
riter_flush_unlocked
(
self
,
1
);
res
=
_
bufferedw
riter_flush_unlocked
(
self
,
1
);
if
(
res
==
NULL
)
{
Py_DECREF
(
chunks
);
return
NULL
;
...
...
@@ -1316,7 +1315,7 @@ _BufferedReader_read_all(BufferedObject *self)
/* Read n bytes from the buffer if it can, otherwise return None.
This function is simple enough that it can run unlocked. */
static
PyObject
*
_
BufferedReader_read_fast
(
BufferedObject
*
self
,
Py_ssize_t
n
)
_
bufferedreader_read_fast
(
buffered
*
self
,
Py_ssize_t
n
)
{
Py_ssize_t
current_size
;
...
...
@@ -1335,7 +1334,7 @@ _BufferedReader_read_fast(BufferedObject *self, Py_ssize_t n)
* or until an EOF occurs or until read() would block.
*/
static
PyObject
*
_
BufferedReader_read_generic
(
BufferedObject
*
self
,
Py_ssize_t
n
)
_
bufferedreader_read_generic
(
buffered
*
self
,
Py_ssize_t
n
)
{
PyObject
*
res
=
NULL
;
Py_ssize_t
current_size
,
remaining
,
written
;
...
...
@@ -1343,7 +1342,7 @@ _BufferedReader_read_generic(BufferedObject *self, Py_ssize_t n)
current_size
=
Py_SAFE_DOWNCAST
(
READAHEAD
(
self
),
Py_off_t
,
Py_ssize_t
);
if
(
n
<=
current_size
)
return
_
BufferedR
eader_read_fast
(
self
,
n
);
return
_
bufferedr
eader_read_fast
(
self
,
n
);
res
=
PyBytes_FromStringAndSize
(
NULL
,
n
);
if
(
res
==
NULL
)
...
...
@@ -1356,14 +1355,14 @@ _BufferedReader_read_generic(BufferedObject *self, Py_ssize_t n)
remaining
-=
current_size
;
written
+=
current_size
;
}
_
BufferedR
eader_reset_buf
(
self
);
_
bufferedr
eader_reset_buf
(
self
);
while
(
remaining
>
0
)
{
/* We want to read a whole block at the end into buffer.
If we had readv() we could do this in one pass. */
Py_ssize_t
r
=
MINUS_LAST_BLOCK
(
self
,
remaining
);
if
(
r
==
0
)
break
;
r
=
_
BufferedR
eader_raw_read
(
self
,
out
+
written
,
r
);
r
=
_
bufferedr
eader_raw_read
(
self
,
out
+
written
,
r
);
if
(
r
==
-
1
)
goto
error
;
if
(
r
==
0
||
r
==
-
2
)
{
...
...
@@ -1385,7 +1384,7 @@ _BufferedReader_read_generic(BufferedObject *self, Py_ssize_t n)
self
->
raw_pos
=
0
;
self
->
read_end
=
0
;
while
(
self
->
read_end
<
self
->
buffer_size
)
{
Py_ssize_t
r
=
_
BufferedR
eader_fill_buffer
(
self
);
Py_ssize_t
r
=
_
bufferedr
eader_fill_buffer
(
self
);
if
(
r
==
-
1
)
goto
error
;
if
(
r
==
0
||
r
==
-
2
)
{
...
...
@@ -1423,7 +1422,7 @@ error:
}
static
PyObject
*
_
BufferedReader_peek_unlocked
(
BufferedObject
*
self
,
Py_ssize_t
n
)
_
bufferedreader_peek_unlocked
(
buffered
*
self
,
Py_ssize_t
n
)
{
Py_ssize_t
have
,
r
;
...
...
@@ -1439,8 +1438,8 @@ _BufferedReader_peek_unlocked(BufferedObject *self, Py_ssize_t n)
}
/* Fill the buffer from the raw stream, and copy it to the result. */
_
BufferedR
eader_reset_buf
(
self
);
r
=
_
BufferedR
eader_fill_buffer
(
self
);
_
bufferedr
eader_reset_buf
(
self
);
r
=
_
bufferedr
eader_fill_buffer
(
self
);
if
(
r
==
-
1
)
return
NULL
;
if
(
r
==
-
2
)
...
...
@@ -1449,36 +1448,36 @@ _BufferedReader_peek_unlocked(BufferedObject *self, Py_ssize_t n)
return
PyBytes_FromStringAndSize
(
self
->
buffer
,
r
);
}
static
PyMethodDef
BufferedR
eader_methods
[]
=
{
static
PyMethodDef
bufferedr
eader_methods
[]
=
{
/* BufferedIOMixin methods */
{
"detach"
,
(
PyCFunction
)
BufferedIOMixin
_detach
,
METH_NOARGS
},
{
"flush"
,
(
PyCFunction
)
BufferedIOMixin
_flush
,
METH_NOARGS
},
{
"close"
,
(
PyCFunction
)
BufferedIOMixin
_close
,
METH_NOARGS
},
{
"seekable"
,
(
PyCFunction
)
BufferedIOMixin
_seekable
,
METH_NOARGS
},
{
"readable"
,
(
PyCFunction
)
BufferedIOMixin
_readable
,
METH_NOARGS
},
{
"writable"
,
(
PyCFunction
)
BufferedIOMixin
_writable
,
METH_NOARGS
},
{
"fileno"
,
(
PyCFunction
)
BufferedIOMixin
_fileno
,
METH_NOARGS
},
{
"isatty"
,
(
PyCFunction
)
BufferedIOMixin
_isatty
,
METH_NOARGS
},
{
"read"
,
(
PyCFunction
)
B
uffered_read
,
METH_VARARGS
},
{
"peek"
,
(
PyCFunction
)
B
uffered_peek
,
METH_VARARGS
},
{
"read1"
,
(
PyCFunction
)
B
uffered_read1
,
METH_VARARGS
},
{
"readline"
,
(
PyCFunction
)
B
uffered_readline
,
METH_VARARGS
},
{
"seek"
,
(
PyCFunction
)
B
uffered_seek
,
METH_VARARGS
},
{
"tell"
,
(
PyCFunction
)
B
uffered_tell
,
METH_NOARGS
},
{
"truncate"
,
(
PyCFunction
)
B
uffered_truncate
,
METH_VARARGS
},
{
"detach"
,
(
PyCFunction
)
buffered
_detach
,
METH_NOARGS
},
{
"flush"
,
(
PyCFunction
)
buffered_simple
_flush
,
METH_NOARGS
},
{
"close"
,
(
PyCFunction
)
buffered
_close
,
METH_NOARGS
},
{
"seekable"
,
(
PyCFunction
)
buffered
_seekable
,
METH_NOARGS
},
{
"readable"
,
(
PyCFunction
)
buffered
_readable
,
METH_NOARGS
},
{
"writable"
,
(
PyCFunction
)
buffered
_writable
,
METH_NOARGS
},
{
"fileno"
,
(
PyCFunction
)
buffered
_fileno
,
METH_NOARGS
},
{
"isatty"
,
(
PyCFunction
)
buffered
_isatty
,
METH_NOARGS
},
{
"read"
,
(
PyCFunction
)
b
uffered_read
,
METH_VARARGS
},
{
"peek"
,
(
PyCFunction
)
b
uffered_peek
,
METH_VARARGS
},
{
"read1"
,
(
PyCFunction
)
b
uffered_read1
,
METH_VARARGS
},
{
"readline"
,
(
PyCFunction
)
b
uffered_readline
,
METH_VARARGS
},
{
"seek"
,
(
PyCFunction
)
b
uffered_seek
,
METH_VARARGS
},
{
"tell"
,
(
PyCFunction
)
b
uffered_tell
,
METH_NOARGS
},
{
"truncate"
,
(
PyCFunction
)
b
uffered_truncate
,
METH_VARARGS
},
{
NULL
,
NULL
}
};
static
PyMemberDef
BufferedR
eader_members
[]
=
{
{
"raw"
,
T_OBJECT
,
offsetof
(
BufferedObject
,
raw
),
0
},
static
PyMemberDef
bufferedr
eader_members
[]
=
{
{
"raw"
,
T_OBJECT
,
offsetof
(
buffered
,
raw
),
0
},
{
NULL
}
};
static
PyGetSetDef
BufferedR
eader_getset
[]
=
{
{
"closed"
,
(
getter
)
BufferedIOMixin
_closed_get
,
NULL
,
NULL
},
{
"name"
,
(
getter
)
BufferedIOMixin
_name_get
,
NULL
,
NULL
},
{
"mode"
,
(
getter
)
BufferedIOMixin
_mode_get
,
NULL
,
NULL
},
static
PyGetSetDef
bufferedr
eader_getset
[]
=
{
{
"closed"
,
(
getter
)
buffered
_closed_get
,
NULL
,
NULL
},
{
"name"
,
(
getter
)
buffered
_name_get
,
NULL
,
NULL
},
{
"mode"
,
(
getter
)
buffered
_mode_get
,
NULL
,
NULL
},
{
NULL
}
};
...
...
@@ -1486,14 +1485,14 @@ static PyGetSetDef BufferedReader_getset[] = {
PyTypeObject
PyBufferedReader_Type
=
{
PyVarObject_HEAD_INIT
(
NULL
,
0
)
"_io.BufferedReader"
,
/*tp_name*/
sizeof
(
BufferedObject
),
/*tp_basicsize*/
sizeof
(
buffered
),
/*tp_basicsize*/
0
,
/*tp_itemsize*/
(
destructor
)
BufferedObject
_dealloc
,
/*tp_dealloc*/
(
destructor
)
buffered
_dealloc
,
/*tp_dealloc*/
0
,
/*tp_print*/
0
,
/*tp_getattr*/
0
,
/*tp_setattr*/
0
,
/*tp_compare */
(
reprfunc
)
B
uffered_repr
,
/*tp_repr*/
(
reprfunc
)
b
uffered_repr
,
/*tp_repr*/
0
,
/*tp_as_number*/
0
,
/*tp_as_sequence*/
0
,
/*tp_as_mapping*/
...
...
@@ -1505,22 +1504,22 @@ PyTypeObject PyBufferedReader_Type = {
0
,
/*tp_as_buffer*/
Py_TPFLAGS_DEFAULT
|
Py_TPFLAGS_BASETYPE
|
Py_TPFLAGS_HAVE_GC
,
/*tp_flags*/
BufferedR
eader_doc
,
/* tp_doc */
(
traverseproc
)
B
uffered_traverse
,
/* tp_traverse */
(
inquiry
)
B
uffered_clear
,
/* tp_clear */
bufferedr
eader_doc
,
/* tp_doc */
(
traverseproc
)
b
uffered_traverse
,
/* tp_traverse */
(
inquiry
)
b
uffered_clear
,
/* tp_clear */
0
,
/* tp_richcompare */
offsetof
(
BufferedObject
,
weakreflist
),
/*tp_weaklistoffset*/
offsetof
(
buffered
,
weakreflist
),
/*tp_weaklistoffset*/
0
,
/* tp_iter */
(
iternextfunc
)
B
uffered_iternext
,
/* tp_iternext */
BufferedR
eader_methods
,
/* tp_methods */
BufferedR
eader_members
,
/* tp_members */
BufferedR
eader_getset
,
/* tp_getset */
(
iternextfunc
)
b
uffered_iternext
,
/* tp_iternext */
bufferedr
eader_methods
,
/* tp_methods */
bufferedr
eader_members
,
/* tp_members */
bufferedr
eader_getset
,
/* tp_getset */
0
,
/* tp_base */
0
,
/* tp_dict */
0
,
/* tp_descr_get */
0
,
/* tp_descr_set */
offsetof
(
BufferedObject
,
dict
),
/* tp_dictoffset */
(
initproc
)
BufferedR
eader_init
,
/* tp_init */
offsetof
(
buffered
,
dict
),
/* tp_dictoffset */
(
initproc
)
bufferedr
eader_init
,
/* tp_init */
0
,
/* tp_alloc */
PyType_GenericNew
,
/* tp_new */
};
...
...
@@ -1539,7 +1538,7 @@ complain_about_max_buffer_size(void)
/*
* class BufferedWriter
*/
PyDoc_STRVAR
(
BufferedW
riter_doc
,
PyDoc_STRVAR
(
bufferedw
riter_doc
,
"A buffer for a writeable sequential RawIO object.
\n
"
"
\n
"
"The constructor creates a BufferedWriter for the given writeable raw
\n
"
...
...
@@ -1548,14 +1547,14 @@ PyDoc_STRVAR(BufferedWriter_doc,
);
static
void
_
BufferedWriter_reset_buf
(
BufferedObject
*
self
)
_
bufferedwriter_reset_buf
(
buffered
*
self
)
{
self
->
write_pos
=
0
;
self
->
write_end
=
-
1
;
}
static
int
BufferedWriter_init
(
BufferedObject
*
self
,
PyObject
*
args
,
PyObject
*
kwds
)
bufferedwriter_init
(
buffered
*
self
,
PyObject
*
args
,
PyObject
*
kwds
)
{
/* TODO: properly deprecate max_buffer_size */
char
*
kwlist
[]
=
{
"raw"
,
"buffer_size"
,
"max_buffer_size"
,
NULL
};
...
...
@@ -1574,7 +1573,7 @@ BufferedWriter_init(BufferedObject *self, PyObject *args, PyObject *kwds)
if
(
max_buffer_size
!=
-
234
&&
!
complain_about_max_buffer_size
())
return
-
1
;
if
(
_PyIOBase_check
W
ritable
(
raw
,
Py_True
)
==
NULL
)
if
(
_PyIOBase_check
_w
ritable
(
raw
,
Py_True
)
==
NULL
)
return
-
1
;
Py_CLEAR
(
self
->
raw
);
...
...
@@ -1584,9 +1583,9 @@ BufferedWriter_init(BufferedObject *self, PyObject *args, PyObject *kwds)
self
->
writable
=
1
;
self
->
buffer_size
=
buffer_size
;
if
(
_
B
uffered_init
(
self
)
<
0
)
if
(
_
b
uffered_init
(
self
)
<
0
)
return
-
1
;
_
BufferedW
riter_reset_buf
(
self
);
_
bufferedw
riter_reset_buf
(
self
);
self
->
pos
=
0
;
self
->
fast_closed_checks
=
(
Py_TYPE
(
self
)
==
&
PyBufferedWriter_Type
&&
...
...
@@ -1597,7 +1596,7 @@ BufferedWriter_init(BufferedObject *self, PyObject *args, PyObject *kwds)
}
static
Py_ssize_t
_
BufferedWriter_raw_write
(
BufferedObject
*
self
,
char
*
start
,
Py_ssize_t
len
)
_
bufferedwriter_raw_write
(
buffered
*
self
,
char
*
start
,
Py_ssize_t
len
)
{
Py_buffer
buf
;
PyObject
*
memobj
,
*
res
;
...
...
@@ -1628,7 +1627,7 @@ _BufferedWriter_raw_write(BufferedObject *self, char *start, Py_ssize_t len)
/* `restore_pos` is 1 if we need to restore the raw stream position at
the end, 0 otherwise. */
static
PyObject
*
_
BufferedWriter_flush_unlocked
(
BufferedObject
*
self
,
int
restore_pos
)
_
bufferedwriter_flush_unlocked
(
buffered
*
self
,
int
restore_pos
)
{
Py_ssize_t
written
=
0
;
Py_off_t
n
,
rewind
;
...
...
@@ -1638,19 +1637,19 @@ _BufferedWriter_flush_unlocked(BufferedObject *self, int restore_pos)
/* First, rewind */
rewind
=
RAW_OFFSET
(
self
)
+
(
self
->
pos
-
self
->
write_pos
);
if
(
rewind
!=
0
)
{
n
=
_
B
uffered_raw_seek
(
self
,
-
rewind
,
1
);
n
=
_
b
uffered_raw_seek
(
self
,
-
rewind
,
1
);
if
(
n
<
0
)
{
goto
error
;
}
self
->
raw_pos
-=
rewind
;
}
while
(
self
->
write_pos
<
self
->
write_end
)
{
n
=
_
BufferedW
riter_raw_write
(
self
,
n
=
_
bufferedw
riter_raw_write
(
self
,
self
->
buffer
+
self
->
write_pos
,
Py_SAFE_DOWNCAST
(
self
->
write_end
-
self
->
write_pos
,
Py_off_t
,
Py_ssize_t
));
if
(
n
==
-
1
)
{
Py_ssize_t
*
w
=
_
B
uffered_check_blocking_error
();
Py_ssize_t
*
w
=
_
b
uffered_check_blocking_error
();
if
(
w
==
NULL
)
goto
error
;
self
->
write_pos
+=
*
w
;
...
...
@@ -1668,14 +1667,14 @@ _BufferedWriter_flush_unlocked(BufferedObject *self, int restore_pos)
if
(
restore_pos
)
{
Py_off_t
forward
=
rewind
-
written
;
if
(
forward
!=
0
)
{
n
=
_
B
uffered_raw_seek
(
self
,
forward
,
1
);
n
=
_
b
uffered_raw_seek
(
self
,
forward
,
1
);
if
(
n
<
0
)
{
goto
error
;
}
self
->
raw_pos
+=
forward
;
}
}
_
BufferedW
riter_reset_buf
(
self
);
_
bufferedw
riter_reset_buf
(
self
);
end:
Py_RETURN_NONE
;
...
...
@@ -1685,7 +1684,7 @@ error:
}
static
PyObject
*
BufferedWriter_write
(
BufferedObject
*
self
,
PyObject
*
args
)
bufferedwriter_write
(
buffered
*
self
,
PyObject
*
args
)
{
PyObject
*
res
=
NULL
;
Py_buffer
buf
;
...
...
@@ -1723,13 +1722,13 @@ BufferedWriter_write(BufferedObject *self, PyObject *args)
}
/* First write the current buffer */
res
=
_
BufferedW
riter_flush_unlocked
(
self
,
0
);
res
=
_
bufferedw
riter_flush_unlocked
(
self
,
0
);
if
(
res
==
NULL
)
{
Py_ssize_t
*
w
=
_
B
uffered_check_blocking_error
();
Py_ssize_t
*
w
=
_
b
uffered_check_blocking_error
();
if
(
w
==
NULL
)
goto
error
;
if
(
self
->
readable
)
_
BufferedR
eader_reset_buf
(
self
);
_
bufferedr
eader_reset_buf
(
self
);
/* Make some place by shifting the buffer. */
assert
(
VALID_WRITE_BUFFER
(
self
));
memmove
(
self
->
buffer
,
self
->
buffer
+
self
->
write_pos
,
...
...
@@ -1762,10 +1761,10 @@ BufferedWriter_write(BufferedObject *self, PyObject *args)
remaining
=
buf
.
len
;
written
=
0
;
while
(
remaining
>
self
->
buffer_size
)
{
n
=
_
BufferedW
riter_raw_write
(
n
=
_
bufferedw
riter_raw_write
(
self
,
(
char
*
)
buf
.
buf
+
written
,
buf
.
len
-
written
);
if
(
n
==
-
1
)
{
Py_ssize_t
*
w
=
_
B
uffered_check_blocking_error
();
Py_ssize_t
*
w
=
_
b
uffered_check_blocking_error
();
if
(
w
==
NULL
)
goto
error
;
written
+=
*
w
;
...
...
@@ -1788,7 +1787,7 @@ BufferedWriter_write(BufferedObject *self, PyObject *args)
remaining
-=
n
;
}
if
(
self
->
readable
)
_
BufferedR
eader_reset_buf
(
self
);
_
bufferedr
eader_reset_buf
(
self
);
if
(
remaining
>
0
)
{
memcpy
(
self
->
buffer
,
(
char
*
)
buf
.
buf
+
written
,
remaining
);
written
+=
remaining
;
...
...
@@ -1808,33 +1807,33 @@ error:
return
res
;
}
static
PyMethodDef
BufferedW
riter_methods
[]
=
{
static
PyMethodDef
bufferedw
riter_methods
[]
=
{
/* BufferedIOMixin methods */
{
"close"
,
(
PyCFunction
)
BufferedIOMixin
_close
,
METH_NOARGS
},
{
"detach"
,
(
PyCFunction
)
BufferedIOMixin
_detach
,
METH_NOARGS
},
{
"seekable"
,
(
PyCFunction
)
BufferedIOMixin
_seekable
,
METH_NOARGS
},
{
"readable"
,
(
PyCFunction
)
BufferedIOMixin
_readable
,
METH_NOARGS
},
{
"writable"
,
(
PyCFunction
)
BufferedIOMixin
_writable
,
METH_NOARGS
},
{
"fileno"
,
(
PyCFunction
)
BufferedIOMixin
_fileno
,
METH_NOARGS
},
{
"isatty"
,
(
PyCFunction
)
BufferedIOMixin
_isatty
,
METH_NOARGS
},
{
"write"
,
(
PyCFunction
)
BufferedW
riter_write
,
METH_VARARGS
},
{
"truncate"
,
(
PyCFunction
)
B
uffered_truncate
,
METH_VARARGS
},
{
"flush"
,
(
PyCFunction
)
B
uffered_flush
,
METH_NOARGS
},
{
"seek"
,
(
PyCFunction
)
B
uffered_seek
,
METH_VARARGS
},
{
"tell"
,
(
PyCFunction
)
B
uffered_tell
,
METH_NOARGS
},
{
"close"
,
(
PyCFunction
)
buffered
_close
,
METH_NOARGS
},
{
"detach"
,
(
PyCFunction
)
buffered
_detach
,
METH_NOARGS
},
{
"seekable"
,
(
PyCFunction
)
buffered
_seekable
,
METH_NOARGS
},
{
"readable"
,
(
PyCFunction
)
buffered
_readable
,
METH_NOARGS
},
{
"writable"
,
(
PyCFunction
)
buffered
_writable
,
METH_NOARGS
},
{
"fileno"
,
(
PyCFunction
)
buffered
_fileno
,
METH_NOARGS
},
{
"isatty"
,
(
PyCFunction
)
buffered
_isatty
,
METH_NOARGS
},
{
"write"
,
(
PyCFunction
)
bufferedw
riter_write
,
METH_VARARGS
},
{
"truncate"
,
(
PyCFunction
)
b
uffered_truncate
,
METH_VARARGS
},
{
"flush"
,
(
PyCFunction
)
b
uffered_flush
,
METH_NOARGS
},
{
"seek"
,
(
PyCFunction
)
b
uffered_seek
,
METH_VARARGS
},
{
"tell"
,
(
PyCFunction
)
b
uffered_tell
,
METH_NOARGS
},
{
NULL
,
NULL
}
};
static
PyMemberDef
BufferedW
riter_members
[]
=
{
{
"raw"
,
T_OBJECT
,
offsetof
(
BufferedObject
,
raw
),
0
},
static
PyMemberDef
bufferedw
riter_members
[]
=
{
{
"raw"
,
T_OBJECT
,
offsetof
(
buffered
,
raw
),
0
},
{
NULL
}
};
static
PyGetSetDef
BufferedW
riter_getset
[]
=
{
{
"closed"
,
(
getter
)
BufferedIOMixin
_closed_get
,
NULL
,
NULL
},
{
"name"
,
(
getter
)
BufferedIOMixin
_name_get
,
NULL
,
NULL
},
{
"mode"
,
(
getter
)
BufferedIOMixin
_mode_get
,
NULL
,
NULL
},
static
PyGetSetDef
bufferedw
riter_getset
[]
=
{
{
"closed"
,
(
getter
)
buffered
_closed_get
,
NULL
,
NULL
},
{
"name"
,
(
getter
)
buffered
_name_get
,
NULL
,
NULL
},
{
"mode"
,
(
getter
)
buffered
_mode_get
,
NULL
,
NULL
},
{
NULL
}
};
...
...
@@ -1842,14 +1841,14 @@ static PyGetSetDef BufferedWriter_getset[] = {
PyTypeObject
PyBufferedWriter_Type
=
{
PyVarObject_HEAD_INIT
(
NULL
,
0
)
"_io.BufferedWriter"
,
/*tp_name*/
sizeof
(
BufferedObject
),
/*tp_basicsize*/
sizeof
(
buffered
),
/*tp_basicsize*/
0
,
/*tp_itemsize*/
(
destructor
)
BufferedObject
_dealloc
,
/*tp_dealloc*/
(
destructor
)
buffered
_dealloc
,
/*tp_dealloc*/
0
,
/*tp_print*/
0
,
/*tp_getattr*/
0
,
/*tp_setattr*/
0
,
/*tp_compare */
(
reprfunc
)
B
uffered_repr
,
/*tp_repr*/
(
reprfunc
)
b
uffered_repr
,
/*tp_repr*/
0
,
/*tp_as_number*/
0
,
/*tp_as_sequence*/
0
,
/*tp_as_mapping*/
...
...
@@ -1861,22 +1860,22 @@ PyTypeObject PyBufferedWriter_Type = {
0
,
/*tp_as_buffer*/
Py_TPFLAGS_DEFAULT
|
Py_TPFLAGS_BASETYPE
|
Py_TPFLAGS_HAVE_GC
,
/*tp_flags*/
BufferedW
riter_doc
,
/* tp_doc */
(
traverseproc
)
B
uffered_traverse
,
/* tp_traverse */
(
inquiry
)
B
uffered_clear
,
/* tp_clear */
bufferedw
riter_doc
,
/* tp_doc */
(
traverseproc
)
b
uffered_traverse
,
/* tp_traverse */
(
inquiry
)
b
uffered_clear
,
/* tp_clear */
0
,
/* tp_richcompare */
offsetof
(
BufferedObject
,
weakreflist
),
/*tp_weaklistoffset*/
offsetof
(
buffered
,
weakreflist
),
/*tp_weaklistoffset*/
0
,
/* tp_iter */
0
,
/* tp_iternext */
BufferedW
riter_methods
,
/* tp_methods */
BufferedW
riter_members
,
/* tp_members */
BufferedW
riter_getset
,
/* tp_getset */
bufferedw
riter_methods
,
/* tp_methods */
bufferedw
riter_members
,
/* tp_members */
bufferedw
riter_getset
,
/* tp_getset */
0
,
/* tp_base */
0
,
/* tp_dict */
0
,
/* tp_descr_get */
0
,
/* tp_descr_set */
offsetof
(
BufferedObject
,
dict
),
/* tp_dictoffset */
(
initproc
)
BufferedW
riter_init
,
/* tp_init */
offsetof
(
buffered
,
dict
),
/* tp_dictoffset */
(
initproc
)
bufferedw
riter_init
,
/* tp_init */
0
,
/* tp_alloc */
PyType_GenericNew
,
/* tp_new */
};
...
...
@@ -1887,7 +1886,7 @@ PyTypeObject PyBufferedWriter_Type = {
* BufferedRWPair
*/
PyDoc_STRVAR
(
BufferedRWP
air_doc
,
PyDoc_STRVAR
(
bufferedrwp
air_doc
,
"A buffered reader and writer object together.
\n
"
"
\n
"
"A buffered reader object and buffered writer object put together to
\n
"
...
...
@@ -1905,15 +1904,14 @@ PyDoc_STRVAR(BufferedRWPair_doc,
typedef
struct
{
PyObject_HEAD
BufferedObject
*
reader
;
BufferedObject
*
writer
;
buffered
*
reader
;
buffered
*
writer
;
PyObject
*
dict
;
PyObject
*
weakreflist
;
}
BufferedRWPairObject
;
}
rwpair
;
static
int
BufferedRWPair_init
(
BufferedRWPairObject
*
self
,
PyObject
*
args
,
PyObject
*
kwds
)
bufferedrwpair_init
(
rwpair
*
self
,
PyObject
*
args
,
PyObject
*
kwds
)
{
PyObject
*
reader
,
*
writer
;
Py_ssize_t
buffer_size
=
DEFAULT_BUFFER_SIZE
;
...
...
@@ -1927,17 +1925,17 @@ BufferedRWPair_init(BufferedRWPairObject *self, PyObject *args,
if
(
max_buffer_size
!=
-
234
&&
!
complain_about_max_buffer_size
())
return
-
1
;
if
(
_PyIOBase_check
R
eadable
(
reader
,
Py_True
)
==
NULL
)
if
(
_PyIOBase_check
_r
eadable
(
reader
,
Py_True
)
==
NULL
)
return
-
1
;
if
(
_PyIOBase_check
W
ritable
(
writer
,
Py_True
)
==
NULL
)
if
(
_PyIOBase_check
_w
ritable
(
writer
,
Py_True
)
==
NULL
)
return
-
1
;
self
->
reader
=
(
BufferedObject
*
)
PyObject_CallFunction
(
self
->
reader
=
(
buffered
*
)
PyObject_CallFunction
(
(
PyObject
*
)
&
PyBufferedReader_Type
,
"On"
,
reader
,
buffer_size
);
if
(
self
->
reader
==
NULL
)
return
-
1
;
self
->
writer
=
(
BufferedObject
*
)
PyObject_CallFunction
(
self
->
writer
=
(
buffered
*
)
PyObject_CallFunction
(
(
PyObject
*
)
&
PyBufferedWriter_Type
,
"On"
,
writer
,
buffer_size
);
if
(
self
->
writer
==
NULL
)
{
Py_CLEAR
(
self
->
reader
);
...
...
@@ -1948,14 +1946,14 @@ BufferedRWPair_init(BufferedRWPairObject *self, PyObject *args,
}
static
int
BufferedRWPair_traverse
(
BufferedRWPairObject
*
self
,
visitproc
visit
,
void
*
arg
)
bufferedrwpair_traverse
(
rwpair
*
self
,
visitproc
visit
,
void
*
arg
)
{
Py_VISIT
(
self
->
dict
);
return
0
;
}
static
int
BufferedRWPair_clear
(
BufferedRWPairObject
*
self
)
bufferedrwpair_clear
(
rwpair
*
self
)
{
Py_CLEAR
(
self
->
reader
);
Py_CLEAR
(
self
->
writer
);
...
...
@@ -1964,7 +1962,7 @@ BufferedRWPair_clear(BufferedRWPairObject *self)
}
static
void
BufferedRWPair_dealloc
(
BufferedRWPairObject
*
self
)
bufferedrwpair_dealloc
(
rwpair
*
self
)
{
_PyObject_GC_UNTRACK
(
self
);
Py_CLEAR
(
self
->
reader
);
...
...
@@ -1974,7 +1972,7 @@ BufferedRWPair_dealloc(BufferedRWPairObject *self)
}
static
PyObject
*
_forward_call
(
BufferedObject
*
self
,
const
char
*
name
,
PyObject
*
args
)
_forward_call
(
buffered
*
self
,
const
char
*
name
,
PyObject
*
args
)
{
PyObject
*
func
=
PyObject_GetAttrString
((
PyObject
*
)
self
,
name
);
PyObject
*
ret
;
...
...
@@ -1990,55 +1988,55 @@ _forward_call(BufferedObject *self, const char *name, PyObject *args)
}
static
PyObject
*
BufferedRWPair_read
(
BufferedRWPairObject
*
self
,
PyObject
*
args
)
bufferedrwpair_read
(
rwpair
*
self
,
PyObject
*
args
)
{
return
_forward_call
(
self
->
reader
,
"read"
,
args
);
}
static
PyObject
*
BufferedRWPair_peek
(
BufferedRWPairObject
*
self
,
PyObject
*
args
)
bufferedrwpair_peek
(
rwpair
*
self
,
PyObject
*
args
)
{
return
_forward_call
(
self
->
reader
,
"peek"
,
args
);
}
static
PyObject
*
BufferedRWPair_read1
(
BufferedRWPairObject
*
self
,
PyObject
*
args
)
bufferedrwpair_read1
(
rwpair
*
self
,
PyObject
*
args
)
{
return
_forward_call
(
self
->
reader
,
"read1"
,
args
);
}
static
PyObject
*
BufferedRWPair_readinto
(
BufferedRWPairObject
*
self
,
PyObject
*
args
)
bufferedrwpair_readinto
(
rwpair
*
self
,
PyObject
*
args
)
{
return
_forward_call
(
self
->
reader
,
"readinto"
,
args
);
}
static
PyObject
*
BufferedRWPair_write
(
BufferedRWPairObject
*
self
,
PyObject
*
args
)
bufferedrwpair_write
(
rwpair
*
self
,
PyObject
*
args
)
{
return
_forward_call
(
self
->
writer
,
"write"
,
args
);
}
static
PyObject
*
BufferedRWPair_flush
(
BufferedRWPairObject
*
self
,
PyObject
*
args
)
bufferedrwpair_flush
(
rwpair
*
self
,
PyObject
*
args
)
{
return
_forward_call
(
self
->
writer
,
"flush"
,
args
);
}
static
PyObject
*
BufferedRWPair_readable
(
BufferedRWPairObject
*
self
,
PyObject
*
args
)
bufferedrwpair_readable
(
rwpair
*
self
,
PyObject
*
args
)
{
return
_forward_call
(
self
->
reader
,
"readable"
,
args
);
}
static
PyObject
*
BufferedRWPair_writable
(
BufferedRWPairObject
*
self
,
PyObject
*
args
)
bufferedrwpair_writable
(
rwpair
*
self
,
PyObject
*
args
)
{
return
_forward_call
(
self
->
writer
,
"writable"
,
args
);
}
static
PyObject
*
BufferedRWPair_close
(
BufferedRWPairObject
*
self
,
PyObject
*
args
)
bufferedrwpair_close
(
rwpair
*
self
,
PyObject
*
args
)
{
PyObject
*
ret
=
_forward_call
(
self
->
writer
,
"close"
,
args
);
if
(
ret
==
NULL
)
...
...
@@ -2049,7 +2047,7 @@ BufferedRWPair_close(BufferedRWPairObject *self, PyObject *args)
}
static
PyObject
*
BufferedRWPair_isatty
(
BufferedRWPairObject
*
self
,
PyObject
*
args
)
bufferedrwpair_isatty
(
rwpair
*
self
,
PyObject
*
args
)
{
PyObject
*
ret
=
_forward_call
(
self
->
writer
,
"isatty"
,
args
);
...
...
@@ -2063,40 +2061,40 @@ BufferedRWPair_isatty(BufferedRWPairObject *self, PyObject *args)
}
static
PyObject
*
BufferedRWPair_closed_get
(
BufferedRWPairObject
*
self
,
void
*
context
)
bufferedrwpair_closed_get
(
rwpair
*
self
,
void
*
context
)
{
return
PyObject_GetAttr
((
PyObject
*
)
self
->
writer
,
_PyIO_str_closed
);
}
static
PyMethodDef
BufferedRWP
air_methods
[]
=
{
{
"read"
,
(
PyCFunction
)
BufferedRWP
air_read
,
METH_VARARGS
},
{
"peek"
,
(
PyCFunction
)
BufferedRWP
air_peek
,
METH_VARARGS
},
{
"read1"
,
(
PyCFunction
)
BufferedRWP
air_read1
,
METH_VARARGS
},
{
"readinto"
,
(
PyCFunction
)
BufferedRWP
air_readinto
,
METH_VARARGS
},
static
PyMethodDef
bufferedrwp
air_methods
[]
=
{
{
"read"
,
(
PyCFunction
)
bufferedrwp
air_read
,
METH_VARARGS
},
{
"peek"
,
(
PyCFunction
)
bufferedrwp
air_peek
,
METH_VARARGS
},
{
"read1"
,
(
PyCFunction
)
bufferedrwp
air_read1
,
METH_VARARGS
},
{
"readinto"
,
(
PyCFunction
)
bufferedrwp
air_readinto
,
METH_VARARGS
},
{
"write"
,
(
PyCFunction
)
BufferedRWP
air_write
,
METH_VARARGS
},
{
"flush"
,
(
PyCFunction
)
BufferedRWP
air_flush
,
METH_NOARGS
},
{
"write"
,
(
PyCFunction
)
bufferedrwp
air_write
,
METH_VARARGS
},
{
"flush"
,
(
PyCFunction
)
bufferedrwp
air_flush
,
METH_NOARGS
},
{
"readable"
,
(
PyCFunction
)
BufferedRWP
air_readable
,
METH_NOARGS
},
{
"writable"
,
(
PyCFunction
)
BufferedRWP
air_writable
,
METH_NOARGS
},
{
"readable"
,
(
PyCFunction
)
bufferedrwp
air_readable
,
METH_NOARGS
},
{
"writable"
,
(
PyCFunction
)
bufferedrwp
air_writable
,
METH_NOARGS
},
{
"close"
,
(
PyCFunction
)
BufferedRWP
air_close
,
METH_NOARGS
},
{
"isatty"
,
(
PyCFunction
)
BufferedRWP
air_isatty
,
METH_NOARGS
},
{
"close"
,
(
PyCFunction
)
bufferedrwp
air_close
,
METH_NOARGS
},
{
"isatty"
,
(
PyCFunction
)
bufferedrwp
air_isatty
,
METH_NOARGS
},
{
NULL
,
NULL
}
};
static
PyGetSetDef
BufferedRWP
air_getset
[]
=
{
{
"closed"
,
(
getter
)
BufferedRWP
air_closed_get
,
NULL
,
NULL
},
static
PyGetSetDef
bufferedrwp
air_getset
[]
=
{
{
"closed"
,
(
getter
)
bufferedrwp
air_closed_get
,
NULL
,
NULL
},
{
NULL
}
};
PyTypeObject
PyBufferedRWPair_Type
=
{
PyVarObject_HEAD_INIT
(
NULL
,
0
)
"_io.BufferedRWPair"
,
/*tp_name*/
sizeof
(
BufferedRWPairObject
),
/*tp_basicsize*/
sizeof
(
rwpair
),
/*tp_basicsize*/
0
,
/*tp_itemsize*/
(
destructor
)
BufferedRWP
air_dealloc
,
/*tp_dealloc*/
(
destructor
)
bufferedrwp
air_dealloc
,
/*tp_dealloc*/
0
,
/*tp_print*/
0
,
/*tp_getattr*/
0
,
/*tp_setattr*/
...
...
@@ -2113,22 +2111,22 @@ PyTypeObject PyBufferedRWPair_Type = {
0
,
/*tp_as_buffer*/
Py_TPFLAGS_DEFAULT
|
Py_TPFLAGS_BASETYPE
|
Py_TPFLAGS_HAVE_GC
,
/* tp_flags */
BufferedRWP
air_doc
,
/* tp_doc */
(
traverseproc
)
BufferedRWP
air_traverse
,
/* tp_traverse */
(
inquiry
)
BufferedRWP
air_clear
,
/* tp_clear */
bufferedrwp
air_doc
,
/* tp_doc */
(
traverseproc
)
bufferedrwp
air_traverse
,
/* tp_traverse */
(
inquiry
)
bufferedrwp
air_clear
,
/* tp_clear */
0
,
/* tp_richcompare */
offsetof
(
BufferedRWPairObject
,
weakreflist
),
/*tp_weaklistoffset*/
offsetof
(
rwpair
,
weakreflist
),
/*tp_weaklistoffset*/
0
,
/* tp_iter */
0
,
/* tp_iternext */
BufferedRWP
air_methods
,
/* tp_methods */
bufferedrwp
air_methods
,
/* tp_methods */
0
,
/* tp_members */
BufferedRWP
air_getset
,
/* tp_getset */
bufferedrwp
air_getset
,
/* tp_getset */
0
,
/* tp_base */
0
,
/* tp_dict */
0
,
/* tp_descr_get */
0
,
/* tp_descr_set */
offsetof
(
BufferedRWPairObject
,
dict
),
/* tp_dictoffset */
(
initproc
)
BufferedRWP
air_init
,
/* tp_init */
offsetof
(
rwpair
,
dict
),
/* tp_dictoffset */
(
initproc
)
bufferedrwp
air_init
,
/* tp_init */
0
,
/* tp_alloc */
PyType_GenericNew
,
/* tp_new */
};
...
...
@@ -2139,7 +2137,7 @@ PyTypeObject PyBufferedRWPair_Type = {
* BufferedRandom
*/
PyDoc_STRVAR
(
BufferedR
andom_doc
,
PyDoc_STRVAR
(
bufferedr
andom_doc
,
"A buffered interface to random access streams.
\n
"
"
\n
"
"The constructor creates a reader and writer for a seekable stream,
\n
"
...
...
@@ -2148,7 +2146,7 @@ PyDoc_STRVAR(BufferedRandom_doc,
);
static
int
BufferedRandom_init
(
BufferedObject
*
self
,
PyObject
*
args
,
PyObject
*
kwds
)
bufferedrandom_init
(
buffered
*
self
,
PyObject
*
args
,
PyObject
*
kwds
)
{
char
*
kwlist
[]
=
{
"raw"
,
"buffer_size"
,
"max_buffer_size"
,
NULL
};
Py_ssize_t
buffer_size
=
DEFAULT_BUFFER_SIZE
;
...
...
@@ -2166,11 +2164,11 @@ BufferedRandom_init(BufferedObject *self, PyObject *args, PyObject *kwds)
if
(
max_buffer_size
!=
-
234
&&
!
complain_about_max_buffer_size
())
return
-
1
;
if
(
_PyIOBase_check
S
eekable
(
raw
,
Py_True
)
==
NULL
)
if
(
_PyIOBase_check
_s
eekable
(
raw
,
Py_True
)
==
NULL
)
return
-
1
;
if
(
_PyIOBase_check
R
eadable
(
raw
,
Py_True
)
==
NULL
)
if
(
_PyIOBase_check
_r
eadable
(
raw
,
Py_True
)
==
NULL
)
return
-
1
;
if
(
_PyIOBase_check
W
ritable
(
raw
,
Py_True
)
==
NULL
)
if
(
_PyIOBase_check
_w
ritable
(
raw
,
Py_True
)
==
NULL
)
return
-
1
;
Py_CLEAR
(
self
->
raw
);
...
...
@@ -2180,10 +2178,10 @@ BufferedRandom_init(BufferedObject *self, PyObject *args, PyObject *kwds)
self
->
readable
=
1
;
self
->
writable
=
1
;
if
(
_
B
uffered_init
(
self
)
<
0
)
if
(
_
b
uffered_init
(
self
)
<
0
)
return
-
1
;
_
BufferedR
eader_reset_buf
(
self
);
_
BufferedW
riter_reset_buf
(
self
);
_
bufferedr
eader_reset_buf
(
self
);
_
bufferedw
riter_reset_buf
(
self
);
self
->
pos
=
0
;
self
->
fast_closed_checks
=
(
Py_TYPE
(
self
)
==
&
PyBufferedRandom_Type
&&
...
...
@@ -2193,39 +2191,39 @@ BufferedRandom_init(BufferedObject *self, PyObject *args, PyObject *kwds)
return
0
;
}
static
PyMethodDef
BufferedR
andom_methods
[]
=
{
static
PyMethodDef
bufferedr
andom_methods
[]
=
{
/* BufferedIOMixin methods */
{
"close"
,
(
PyCFunction
)
BufferedIOMixin
_close
,
METH_NOARGS
},
{
"detach"
,
(
PyCFunction
)
BufferedIOMixin
_detach
,
METH_NOARGS
},
{
"seekable"
,
(
PyCFunction
)
BufferedIOMixin
_seekable
,
METH_NOARGS
},
{
"readable"
,
(
PyCFunction
)
BufferedIOMixin
_readable
,
METH_NOARGS
},
{
"writable"
,
(
PyCFunction
)
BufferedIOMixin
_writable
,
METH_NOARGS
},
{
"fileno"
,
(
PyCFunction
)
BufferedIOMixin
_fileno
,
METH_NOARGS
},
{
"isatty"
,
(
PyCFunction
)
BufferedIOMixin
_isatty
,
METH_NOARGS
},
{
"flush"
,
(
PyCFunction
)
B
uffered_flush
,
METH_NOARGS
},
{
"seek"
,
(
PyCFunction
)
B
uffered_seek
,
METH_VARARGS
},
{
"tell"
,
(
PyCFunction
)
B
uffered_tell
,
METH_NOARGS
},
{
"truncate"
,
(
PyCFunction
)
B
uffered_truncate
,
METH_VARARGS
},
{
"read"
,
(
PyCFunction
)
B
uffered_read
,
METH_VARARGS
},
{
"read1"
,
(
PyCFunction
)
B
uffered_read1
,
METH_VARARGS
},
{
"readinto"
,
(
PyCFunction
)
B
uffered_readinto
,
METH_VARARGS
},
{
"readline"
,
(
PyCFunction
)
B
uffered_readline
,
METH_VARARGS
},
{
"peek"
,
(
PyCFunction
)
B
uffered_peek
,
METH_VARARGS
},
{
"write"
,
(
PyCFunction
)
BufferedW
riter_write
,
METH_VARARGS
},
{
"close"
,
(
PyCFunction
)
buffered
_close
,
METH_NOARGS
},
{
"detach"
,
(
PyCFunction
)
buffered
_detach
,
METH_NOARGS
},
{
"seekable"
,
(
PyCFunction
)
buffered
_seekable
,
METH_NOARGS
},
{
"readable"
,
(
PyCFunction
)
buffered
_readable
,
METH_NOARGS
},
{
"writable"
,
(
PyCFunction
)
buffered
_writable
,
METH_NOARGS
},
{
"fileno"
,
(
PyCFunction
)
buffered
_fileno
,
METH_NOARGS
},
{
"isatty"
,
(
PyCFunction
)
buffered
_isatty
,
METH_NOARGS
},
{
"flush"
,
(
PyCFunction
)
b
uffered_flush
,
METH_NOARGS
},
{
"seek"
,
(
PyCFunction
)
b
uffered_seek
,
METH_VARARGS
},
{
"tell"
,
(
PyCFunction
)
b
uffered_tell
,
METH_NOARGS
},
{
"truncate"
,
(
PyCFunction
)
b
uffered_truncate
,
METH_VARARGS
},
{
"read"
,
(
PyCFunction
)
b
uffered_read
,
METH_VARARGS
},
{
"read1"
,
(
PyCFunction
)
b
uffered_read1
,
METH_VARARGS
},
{
"readinto"
,
(
PyCFunction
)
b
uffered_readinto
,
METH_VARARGS
},
{
"readline"
,
(
PyCFunction
)
b
uffered_readline
,
METH_VARARGS
},
{
"peek"
,
(
PyCFunction
)
b
uffered_peek
,
METH_VARARGS
},
{
"write"
,
(
PyCFunction
)
bufferedw
riter_write
,
METH_VARARGS
},
{
NULL
,
NULL
}
};
static
PyMemberDef
BufferedR
andom_members
[]
=
{
{
"raw"
,
T_OBJECT
,
offsetof
(
BufferedObject
,
raw
),
0
},
static
PyMemberDef
bufferedr
andom_members
[]
=
{
{
"raw"
,
T_OBJECT
,
offsetof
(
buffered
,
raw
),
0
},
{
NULL
}
};
static
PyGetSetDef
BufferedR
andom_getset
[]
=
{
{
"closed"
,
(
getter
)
BufferedIOMixin
_closed_get
,
NULL
,
NULL
},
{
"name"
,
(
getter
)
BufferedIOMixin
_name_get
,
NULL
,
NULL
},
{
"mode"
,
(
getter
)
BufferedIOMixin
_mode_get
,
NULL
,
NULL
},
static
PyGetSetDef
bufferedr
andom_getset
[]
=
{
{
"closed"
,
(
getter
)
buffered
_closed_get
,
NULL
,
NULL
},
{
"name"
,
(
getter
)
buffered
_name_get
,
NULL
,
NULL
},
{
"mode"
,
(
getter
)
buffered
_mode_get
,
NULL
,
NULL
},
{
NULL
}
};
...
...
@@ -2233,14 +2231,14 @@ static PyGetSetDef BufferedRandom_getset[] = {
PyTypeObject
PyBufferedRandom_Type
=
{
PyVarObject_HEAD_INIT
(
NULL
,
0
)
"_io.BufferedRandom"
,
/*tp_name*/
sizeof
(
BufferedObject
),
/*tp_basicsize*/
sizeof
(
buffered
),
/*tp_basicsize*/
0
,
/*tp_itemsize*/
(
destructor
)
BufferedObject
_dealloc
,
/*tp_dealloc*/
(
destructor
)
buffered
_dealloc
,
/*tp_dealloc*/
0
,
/*tp_print*/
0
,
/*tp_getattr*/
0
,
/*tp_setattr*/
0
,
/*tp_compare */
(
reprfunc
)
B
uffered_repr
,
/*tp_repr*/
(
reprfunc
)
b
uffered_repr
,
/*tp_repr*/
0
,
/*tp_as_number*/
0
,
/*tp_as_sequence*/
0
,
/*tp_as_mapping*/
...
...
@@ -2252,22 +2250,22 @@ PyTypeObject PyBufferedRandom_Type = {
0
,
/*tp_as_buffer*/
Py_TPFLAGS_DEFAULT
|
Py_TPFLAGS_BASETYPE
|
Py_TPFLAGS_HAVE_GC
,
/*tp_flags*/
BufferedR
andom_doc
,
/* tp_doc */
(
traverseproc
)
B
uffered_traverse
,
/* tp_traverse */
(
inquiry
)
B
uffered_clear
,
/* tp_clear */
bufferedr
andom_doc
,
/* tp_doc */
(
traverseproc
)
b
uffered_traverse
,
/* tp_traverse */
(
inquiry
)
b
uffered_clear
,
/* tp_clear */
0
,
/* tp_richcompare */
offsetof
(
BufferedObject
,
weakreflist
),
/*tp_weaklistoffset*/
offsetof
(
buffered
,
weakreflist
),
/*tp_weaklistoffset*/
0
,
/* tp_iter */
(
iternextfunc
)
B
uffered_iternext
,
/* tp_iternext */
BufferedR
andom_methods
,
/* tp_methods */
BufferedR
andom_members
,
/* tp_members */
BufferedR
andom_getset
,
/* tp_getset */
(
iternextfunc
)
b
uffered_iternext
,
/* tp_iternext */
bufferedr
andom_methods
,
/* tp_methods */
bufferedr
andom_members
,
/* tp_members */
bufferedr
andom_getset
,
/* tp_getset */
0
,
/* tp_base */
0
,
/*tp_dict*/
0
,
/* tp_descr_get */
0
,
/* tp_descr_set */
offsetof
(
BufferedObject
,
dict
),
/*tp_dictoffset*/
(
initproc
)
BufferedR
andom_init
,
/* tp_init */
offsetof
(
buffered
,
dict
),
/*tp_dictoffset*/
(
initproc
)
bufferedr
andom_init
,
/* tp_init */
0
,
/* tp_alloc */
PyType_GenericNew
,
/* tp_new */
};
...
...
Modules/_io/bytesio.c
View file @
680bf1af
...
...
@@ -10,7 +10,7 @@ typedef struct {
size_t
buf_size
;
PyObject
*
dict
;
PyObject
*
weakreflist
;
}
BytesIOObject
;
}
bytesio
;
#define CHECK_CLOSED(self) \
if ((self)->buf == NULL) { \
...
...
@@ -23,7 +23,7 @@ typedef struct {
object. Returns the length between the current position to the
next newline character. */
static
Py_ssize_t
get_line
(
BytesIOObject
*
self
,
char
**
output
)
get_line
(
bytesio
*
self
,
char
**
output
)
{
char
*
n
;
const
char
*
str_end
;
...
...
@@ -56,7 +56,7 @@ get_line(BytesIOObject *self, char **output)
The caller should ensure that the 'size' argument is non-negative. Returns
0 on success, -1 otherwise. */
static
int
resize_buffer
(
BytesIOObject
*
self
,
size_t
size
)
resize_buffer
(
bytesio
*
self
,
size_t
size
)
{
/* Here, unsigned types are used to avoid dealing with signed integer
overflow, which is undefined in C. */
...
...
@@ -108,7 +108,7 @@ resize_buffer(BytesIOObject *self, size_t size)
/* Internal routine for writing a string of bytes to the buffer of a BytesIO
object. Returns the number of bytes wrote, or -1 on error. */
static
Py_ssize_t
write_bytes
(
BytesIOObject
*
self
,
const
char
*
bytes
,
Py_ssize_t
len
)
write_bytes
(
bytesio
*
self
,
const
char
*
bytes
,
Py_ssize_t
len
)
{
assert
(
self
->
buf
!=
NULL
);
assert
(
self
->
pos
>=
0
);
...
...
@@ -146,7 +146,7 @@ write_bytes(BytesIOObject *self, const char *bytes, Py_ssize_t len)
}
static
PyObject
*
bytesio_get_closed
(
BytesIOObject
*
self
)
bytesio_get_closed
(
bytesio
*
self
)
{
if
(
self
->
buf
==
NULL
)
{
Py_RETURN_TRUE
;
...
...
@@ -158,7 +158,7 @@ bytesio_get_closed(BytesIOObject *self)
/* Generic getter for the writable, readable and seekable properties */
static
PyObject
*
return_true
(
BytesIOObject
*
self
)
return_true
(
bytesio
*
self
)
{
Py_RETURN_TRUE
;
}
...
...
@@ -167,7 +167,7 @@ PyDoc_STRVAR(flush_doc,
"flush() -> None. Does nothing."
);
static
PyObject
*
bytesio_flush
(
BytesIOObject
*
self
)
bytesio_flush
(
bytesio
*
self
)
{
Py_RETURN_NONE
;
}
...
...
@@ -178,7 +178,7 @@ PyDoc_STRVAR(getval_doc,
"Retrieve the entire contents of the BytesIO object."
);
static
PyObject
*
bytesio_getvalue
(
BytesIOObject
*
self
)
bytesio_getvalue
(
bytesio
*
self
)
{
CHECK_CLOSED
(
self
);
return
PyBytes_FromStringAndSize
(
self
->
buf
,
self
->
string_size
);
...
...
@@ -191,7 +191,7 @@ PyDoc_STRVAR(isatty_doc,
"to a tty-like device."
);
static
PyObject
*
bytesio_isatty
(
BytesIOObject
*
self
)
bytesio_isatty
(
bytesio
*
self
)
{
CHECK_CLOSED
(
self
);
Py_RETURN_FALSE
;
...
...
@@ -201,7 +201,7 @@ PyDoc_STRVAR(tell_doc,
"tell() -> current file position, an integer
\n
"
);
static
PyObject
*
bytesio_tell
(
BytesIOObject
*
self
)
bytesio_tell
(
bytesio
*
self
)
{
CHECK_CLOSED
(
self
);
return
PyLong_FromSsize_t
(
self
->
pos
);
...
...
@@ -214,7 +214,7 @@ PyDoc_STRVAR(read_doc,
"Return an empty string at EOF."
);
static
PyObject
*
bytesio_read
(
BytesIOObject
*
self
,
PyObject
*
args
)
bytesio_read
(
bytesio
*
self
,
PyObject
*
args
)
{
Py_ssize_t
size
,
n
;
char
*
output
;
...
...
@@ -263,7 +263,7 @@ PyDoc_STRVAR(read1_doc,
"Return an empty string at EOF."
);
static
PyObject
*
bytesio_read1
(
BytesIOObject
*
self
,
PyObject
*
n
)
bytesio_read1
(
bytesio
*
self
,
PyObject
*
n
)
{
PyObject
*
arg
,
*
res
;
...
...
@@ -283,7 +283,7 @@ PyDoc_STRVAR(readline_doc,
"Return an empty string at EOF.
\n
"
);
static
PyObject
*
bytesio_readline
(
BytesIOObject
*
self
,
PyObject
*
args
)
bytesio_readline
(
bytesio
*
self
,
PyObject
*
args
)
{
Py_ssize_t
size
,
n
;
char
*
output
;
...
...
@@ -328,7 +328,7 @@ PyDoc_STRVAR(readlines_doc,
"total number of bytes in the lines returned.
\n
"
);
static
PyObject
*
bytesio_readlines
(
BytesIOObject
*
self
,
PyObject
*
args
)
bytesio_readlines
(
bytesio
*
self
,
PyObject
*
args
)
{
Py_ssize_t
maxsize
,
size
,
n
;
PyObject
*
result
,
*
line
;
...
...
@@ -387,7 +387,7 @@ PyDoc_STRVAR(readinto_doc,
"is set not to block as has no data to read."
);
static
PyObject
*
bytesio_readinto
(
BytesIOObject
*
self
,
PyObject
*
buffer
)
bytesio_readinto
(
bytesio
*
self
,
PyObject
*
buffer
)
{
void
*
raw_buffer
;
Py_ssize_t
len
;
...
...
@@ -415,7 +415,7 @@ PyDoc_STRVAR(truncate_doc,
"Returns the new size. Imply an absolute seek to the position size."
);
static
PyObject
*
bytesio_truncate
(
BytesIOObject
*
self
,
PyObject
*
args
)
bytesio_truncate
(
bytesio
*
self
,
PyObject
*
args
)
{
Py_ssize_t
size
;
PyObject
*
arg
=
Py_None
;
...
...
@@ -457,7 +457,7 @@ bytesio_truncate(BytesIOObject *self, PyObject *args)
}
static
PyObject
*
bytesio_iternext
(
BytesIOObject
*
self
)
bytesio_iternext
(
bytesio
*
self
)
{
char
*
next
;
Py_ssize_t
n
;
...
...
@@ -482,7 +482,7 @@ PyDoc_STRVAR(seek_doc,
"Returns the new absolute position."
);
static
PyObject
*
bytesio_seek
(
BytesIOObject
*
self
,
PyObject
*
args
)
bytesio_seek
(
bytesio
*
self
,
PyObject
*
args
)
{
Py_ssize_t
pos
;
int
mode
=
0
;
...
...
@@ -536,7 +536,7 @@ PyDoc_STRVAR(write_doc,
"Return the number of bytes written."
);
static
PyObject
*
bytesio_write
(
BytesIOObject
*
self
,
PyObject
*
obj
)
bytesio_write
(
bytesio
*
self
,
PyObject
*
obj
)
{
Py_ssize_t
n
=
0
;
Py_buffer
buf
;
...
...
@@ -564,7 +564,7 @@ PyDoc_STRVAR(writelines_doc,
"each string."
);
static
PyObject
*
bytesio_writelines
(
BytesIOObject
*
self
,
PyObject
*
v
)
bytesio_writelines
(
bytesio
*
self
,
PyObject
*
v
)
{
PyObject
*
it
,
*
item
;
PyObject
*
ret
;
...
...
@@ -597,7 +597,7 @@ PyDoc_STRVAR(close_doc,
"close() -> None. Disable all I/O operations."
);
static
PyObject
*
bytesio_close
(
BytesIOObject
*
self
)
bytesio_close
(
bytesio
*
self
)
{
if
(
self
->
buf
!=
NULL
)
{
PyMem_Free
(
self
->
buf
);
...
...
@@ -607,7 +607,7 @@ bytesio_close(BytesIOObject *self)
}
static
void
bytesio_dealloc
(
BytesIOObject
*
self
)
bytesio_dealloc
(
bytesio
*
self
)
{
if
(
self
->
buf
!=
NULL
)
{
PyMem_Free
(
self
->
buf
);
...
...
@@ -620,10 +620,10 @@ bytesio_dealloc(BytesIOObject *self)
static
PyObject
*
bytesio_new
(
PyTypeObject
*
type
,
PyObject
*
args
,
PyObject
*
kwds
)
{
BytesIOObject
*
self
;
bytesio
*
self
;
assert
(
type
!=
NULL
&&
type
->
tp_alloc
!=
NULL
);
self
=
(
BytesIOObject
*
)
type
->
tp_alloc
(
type
,
0
);
self
=
(
bytesio
*
)
type
->
tp_alloc
(
type
,
0
);
if
(
self
==
NULL
)
return
NULL
;
...
...
@@ -640,7 +640,7 @@ bytesio_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
}
static
int
bytesio_init
(
BytesIOObject
*
self
,
PyObject
*
args
,
PyObject
*
kwds
)
bytesio_init
(
bytesio
*
self
,
PyObject
*
args
,
PyObject
*
kwds
)
{
PyObject
*
initvalue
=
NULL
;
...
...
@@ -664,7 +664,7 @@ bytesio_init(BytesIOObject *self, PyObject *args, PyObject *kwds)
}
static
int
bytesio_traverse
(
BytesIOObject
*
self
,
visitproc
visit
,
void
*
arg
)
bytesio_traverse
(
bytesio
*
self
,
visitproc
visit
,
void
*
arg
)
{
Py_VISIT
(
self
->
dict
);
Py_VISIT
(
self
->
weakreflist
);
...
...
@@ -672,7 +672,7 @@ bytesio_traverse(BytesIOObject *self, visitproc visit, void *arg)
}
static
int
bytesio_clear
(
BytesIOObject
*
self
)
bytesio_clear
(
bytesio
*
self
)
{
Py_CLEAR
(
self
->
dict
);
if
(
self
->
weakreflist
!=
NULL
)
...
...
@@ -717,7 +717,7 @@ PyDoc_STRVAR(bytesio_doc,
PyTypeObject
PyBytesIO_Type
=
{
PyVarObject_HEAD_INIT
(
NULL
,
0
)
"_io.BytesIO"
,
/*tp_name*/
sizeof
(
BytesIOObject
),
/*tp_basicsize*/
sizeof
(
bytesio
),
/*tp_basicsize*/
0
,
/*tp_itemsize*/
(
destructor
)
bytesio_dealloc
,
/*tp_dealloc*/
0
,
/*tp_print*/
...
...
@@ -740,7 +740,7 @@ PyTypeObject PyBytesIO_Type = {
(
traverseproc
)
bytesio_traverse
,
/*tp_traverse*/
(
inquiry
)
bytesio_clear
,
/*tp_clear*/
0
,
/*tp_richcompare*/
offsetof
(
BytesIOObject
,
weakreflist
),
/*tp_weaklistoffset*/
offsetof
(
bytesio
,
weakreflist
),
/*tp_weaklistoffset*/
PyObject_SelfIter
,
/*tp_iter*/
(
iternextfunc
)
bytesio_iternext
,
/*tp_iternext*/
bytesio_methods
,
/*tp_methods*/
...
...
@@ -750,7 +750,7 @@ PyTypeObject PyBytesIO_Type = {
0
,
/*tp_dict*/
0
,
/*tp_descr_get*/
0
,
/*tp_descr_set*/
offsetof
(
BytesIOObject
,
dict
),
/*tp_dictoffset*/
offsetof
(
bytesio
,
dict
),
/*tp_dictoffset*/
(
initproc
)
bytesio_init
,
/*tp_init*/
0
,
/*tp_alloc*/
bytesio_new
,
/*tp_new*/
...
...
Modules/_io/fileio.c
View file @
680bf1af
...
...
@@ -51,7 +51,7 @@ typedef struct {
int
closefd
:
1
;
PyObject
*
weakreflist
;
PyObject
*
dict
;
}
PyFileIOObject
;
}
fileio
;
PyTypeObject
PyFileIO_Type
;
...
...
@@ -60,7 +60,7 @@ PyTypeObject PyFileIO_Type;
int
_PyFileIO_closed
(
PyObject
*
self
)
{
return
((
PyFileIOObject
*
)
self
)
->
fd
<
0
;
return
((
fileio
*
)
self
)
->
fd
<
0
;
}
static
PyObject
*
...
...
@@ -70,7 +70,7 @@ static PyObject *portable_lseek(int fd, PyObject *posobj, int whence);
/* Returns 0 on success, -1 with exception set on failure. */
static
int
internal_close
(
PyFileIOObject
*
self
)
internal_close
(
fileio
*
self
)
{
int
err
=
0
;
int
save_errno
=
0
;
...
...
@@ -98,7 +98,7 @@ internal_close(PyFileIOObject *self)
}
static
PyObject
*
fileio_close
(
PyFileIOObject
*
self
)
fileio_close
(
fileio
*
self
)
{
if
(
!
self
->
closefd
)
{
self
->
fd
=
-
1
;
...
...
@@ -115,11 +115,11 @@ fileio_close(PyFileIOObject *self)
static
PyObject
*
fileio_new
(
PyTypeObject
*
type
,
PyObject
*
args
,
PyObject
*
kwds
)
{
PyFileIOObject
*
self
;
fileio
*
self
;
assert
(
type
!=
NULL
&&
type
->
tp_alloc
!=
NULL
);
self
=
(
PyFileIOObject
*
)
type
->
tp_alloc
(
type
,
0
);
self
=
(
fileio
*
)
type
->
tp_alloc
(
type
,
0
);
if
(
self
!=
NULL
)
{
self
->
fd
=
-
1
;
self
->
readable
=
0
;
...
...
@@ -137,7 +137,7 @@ fileio_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
directories, so we need a check. */
static
int
dircheck
(
PyFileIOObject
*
self
,
const
char
*
name
)
dircheck
(
fileio
*
self
,
const
char
*
name
)
{
#if defined(HAVE_FSTAT) && defined(S_IFDIR) && defined(EISDIR)
struct
stat
buf
;
...
...
@@ -181,7 +181,7 @@ check_fd(int fd)
static
int
fileio_init
(
PyObject
*
oself
,
PyObject
*
args
,
PyObject
*
kwds
)
{
PyFileIOObject
*
self
=
(
PyFileIOObject
*
)
oself
;
fileio
*
self
=
(
fileio
*
)
oself
;
static
char
*
kwlist
[]
=
{
"file"
,
"mode"
,
"closefd"
,
NULL
};
const
char
*
name
=
NULL
;
PyObject
*
nameobj
,
*
stringobj
=
NULL
;
...
...
@@ -380,21 +380,21 @@ fileio_init(PyObject *oself, PyObject *args, PyObject *kwds)
}
static
int
fileio_traverse
(
PyFileIOObject
*
self
,
visitproc
visit
,
void
*
arg
)
fileio_traverse
(
fileio
*
self
,
visitproc
visit
,
void
*
arg
)
{
Py_VISIT
(
self
->
dict
);
return
0
;
}
static
int
fileio_clear
(
PyFileIOObject
*
self
)
fileio_clear
(
fileio
*
self
)
{
Py_CLEAR
(
self
->
dict
);
return
0
;
}
static
void
fileio_dealloc
(
PyFileIOObject
*
self
)
fileio_dealloc
(
fileio
*
self
)
{
if
(
_PyIOBase_finalize
((
PyObject
*
)
self
)
<
0
)
return
;
...
...
@@ -420,7 +420,7 @@ err_mode(char *action)
}
static
PyObject
*
fileio_fileno
(
PyFileIOObject
*
self
)
fileio_fileno
(
fileio
*
self
)
{
if
(
self
->
fd
<
0
)
return
err_closed
();
...
...
@@ -428,7 +428,7 @@ fileio_fileno(PyFileIOObject *self)
}
static
PyObject
*
fileio_readable
(
PyFileIOObject
*
self
)
fileio_readable
(
fileio
*
self
)
{
if
(
self
->
fd
<
0
)
return
err_closed
();
...
...
@@ -436,7 +436,7 @@ fileio_readable(PyFileIOObject *self)
}
static
PyObject
*
fileio_writable
(
PyFileIOObject
*
self
)
fileio_writable
(
fileio
*
self
)
{
if
(
self
->
fd
<
0
)
return
err_closed
();
...
...
@@ -444,7 +444,7 @@ fileio_writable(PyFileIOObject *self)
}
static
PyObject
*
fileio_seekable
(
PyFileIOObject
*
self
)
fileio_seekable
(
fileio
*
self
)
{
if
(
self
->
fd
<
0
)
return
err_closed
();
...
...
@@ -462,7 +462,7 @@ fileio_seekable(PyFileIOObject *self)
}
static
PyObject
*
fileio_readinto
(
PyFileIOObject
*
self
,
PyObject
*
args
)
fileio_readinto
(
fileio
*
self
,
PyObject
*
args
)
{
Py_buffer
pbuf
;
Py_ssize_t
n
;
...
...
@@ -494,7 +494,7 @@ fileio_readinto(PyFileIOObject *self, PyObject *args)
}
static
size_t
new_buffersize
(
PyFileIOObject
*
self
,
size_t
currentsize
)
new_buffersize
(
fileio
*
self
,
size_t
currentsize
)
{
#ifdef HAVE_FSTAT
off_t
pos
,
end
;
...
...
@@ -524,7 +524,7 @@ new_buffersize(PyFileIOObject *self, size_t currentsize)
}
static
PyObject
*
fileio_readall
(
PyFileIOObject
*
self
)
fileio_readall
(
fileio
*
self
)
{
PyObject
*
result
;
Py_ssize_t
total
=
0
;
...
...
@@ -590,7 +590,7 @@ fileio_readall(PyFileIOObject *self)
}
static
PyObject
*
fileio_read
(
PyFileIOObject
*
self
,
PyObject
*
args
)
fileio_read
(
fileio
*
self
,
PyObject
*
args
)
{
char
*
ptr
;
Py_ssize_t
n
;
...
...
@@ -641,7 +641,7 @@ fileio_read(PyFileIOObject *self, PyObject *args)
}
static
PyObject
*
fileio_write
(
PyFileIOObject
*
self
,
PyObject
*
args
)
fileio_write
(
fileio
*
self
,
PyObject
*
args
)
{
Py_buffer
pbuf
;
Py_ssize_t
n
;
...
...
@@ -734,7 +734,7 @@ portable_lseek(int fd, PyObject *posobj, int whence)
}
static
PyObject
*
fileio_seek
(
PyFileIOObject
*
self
,
PyObject
*
args
)
fileio_seek
(
fileio
*
self
,
PyObject
*
args
)
{
PyObject
*
posobj
;
int
whence
=
0
;
...
...
@@ -749,7 +749,7 @@ fileio_seek(PyFileIOObject *self, PyObject *args)
}
static
PyObject
*
fileio_tell
(
PyFileIOObject
*
self
,
PyObject
*
args
)
fileio_tell
(
fileio
*
self
,
PyObject
*
args
)
{
if
(
self
->
fd
<
0
)
return
err_closed
();
...
...
@@ -759,7 +759,7 @@ fileio_tell(PyFileIOObject *self, PyObject *args)
#ifdef HAVE_FTRUNCATE
static
PyObject
*
fileio_truncate
(
PyFileIOObject
*
self
,
PyObject
*
args
)
fileio_truncate
(
fileio
*
self
,
PyObject
*
args
)
{
PyObject
*
posobj
=
NULL
;
Py_off_t
pos
;
...
...
@@ -831,7 +831,7 @@ fileio_truncate(PyFileIOObject *self, PyObject *args)
#endif
static
char
*
mode_string
(
PyFileIOObject
*
self
)
mode_string
(
fileio
*
self
)
{
if
(
self
->
readable
)
{
if
(
self
->
writable
)
...
...
@@ -844,7 +844,7 @@ mode_string(PyFileIOObject *self)
}
static
PyObject
*
fileio_repr
(
PyFileIOObject
*
self
)
fileio_repr
(
fileio
*
self
)
{
PyObject
*
nameobj
,
*
res
;
...
...
@@ -869,7 +869,7 @@ fileio_repr(PyFileIOObject *self)
}
static
PyObject
*
fileio_isatty
(
PyFileIOObject
*
self
)
fileio_isatty
(
fileio
*
self
)
{
long
res
;
...
...
@@ -980,19 +980,19 @@ static PyMethodDef fileio_methods[] = {
/* 'closed' and 'mode' are attributes for backwards compatibility reasons. */
static
PyObject
*
get_closed
(
PyFileIOObject
*
self
,
void
*
closure
)
get_closed
(
fileio
*
self
,
void
*
closure
)
{
return
PyBool_FromLong
((
long
)(
self
->
fd
<
0
));
}
static
PyObject
*
get_closefd
(
PyFileIOObject
*
self
,
void
*
closure
)
get_closefd
(
fileio
*
self
,
void
*
closure
)
{
return
PyBool_FromLong
((
long
)(
self
->
closefd
));
}
static
PyObject
*
get_mode
(
PyFileIOObject
*
self
,
void
*
closure
)
get_mode
(
fileio
*
self
,
void
*
closure
)
{
return
PyUnicode_FromString
(
mode_string
(
self
));
}
...
...
@@ -1008,7 +1008,7 @@ static PyGetSetDef fileio_getsetlist[] = {
PyTypeObject
PyFileIO_Type
=
{
PyVarObject_HEAD_INIT
(
NULL
,
0
)
"_io.FileIO"
,
sizeof
(
PyFileIOObject
),
sizeof
(
fileio
),
0
,
(
destructor
)
fileio_dealloc
,
/* tp_dealloc */
0
,
/* tp_print */
...
...
@@ -1031,7 +1031,7 @@ PyTypeObject PyFileIO_Type = {
(
traverseproc
)
fileio_traverse
,
/* tp_traverse */
(
inquiry
)
fileio_clear
,
/* tp_clear */
0
,
/* tp_richcompare */
offsetof
(
PyFileIOObject
,
weakreflist
),
/* tp_weaklistoffset */
offsetof
(
fileio
,
weakreflist
),
/* tp_weaklistoffset */
0
,
/* tp_iter */
0
,
/* tp_iternext */
fileio_methods
,
/* tp_methods */
...
...
@@ -1041,7 +1041,7 @@ PyTypeObject PyFileIO_Type = {
0
,
/* tp_dict */
0
,
/* tp_descr_get */
0
,
/* tp_descr_set */
offsetof
(
PyFileIOObject
,
dict
),
/* tp_dictoffset */
offsetof
(
fileio
,
dict
),
/* tp_dictoffset */
fileio_init
,
/* tp_init */
PyType_GenericAlloc
,
/* tp_alloc */
fileio_new
,
/* tp_new */
...
...
Modules/_io/iobase.c
View file @
680bf1af
...
...
@@ -22,9 +22,9 @@ typedef struct {
PyObject
*
dict
;
PyObject
*
weakreflist
;
}
IOBaseObject
;
}
iobase
;
PyDoc_STRVAR
(
IOB
ase_doc
,
PyDoc_STRVAR
(
iob
ase_doc
,
"The abstract base class for all I/O classes, acting on streams of
\n
"
"bytes. There is no public constructor.
\n
"
"
\n
"
...
...
@@ -63,7 +63,7 @@ PyDoc_STRVAR(IOBase_doc,
/* Internal methods */
static
PyObject
*
IOB
ase_unsupported
(
const
char
*
message
)
iob
ase_unsupported
(
const
char
*
message
)
{
PyErr_SetString
(
IO_STATE
->
unsupported_operation
,
message
);
return
NULL
;
...
...
@@ -71,7 +71,7 @@ IOBase_unsupported(const char *message)
/* Positionning */
PyDoc_STRVAR
(
IOB
ase_seek_doc
,
PyDoc_STRVAR
(
iob
ase_seek_doc
,
"Change stream position.
\n
"
"
\n
"
"Change the stream position to byte offset offset. offset is
\n
"
...
...
@@ -85,41 +85,41 @@ PyDoc_STRVAR(IOBase_seek_doc,
"Return the new absolute position."
);
static
PyObject
*
IOB
ase_seek
(
PyObject
*
self
,
PyObject
*
args
)
iob
ase_seek
(
PyObject
*
self
,
PyObject
*
args
)
{
return
IOB
ase_unsupported
(
"seek"
);
return
iob
ase_unsupported
(
"seek"
);
}
PyDoc_STRVAR
(
IOB
ase_tell_doc
,
PyDoc_STRVAR
(
iob
ase_tell_doc
,
"Return current stream position."
);
static
PyObject
*
IOB
ase_tell
(
PyObject
*
self
,
PyObject
*
args
)
iob
ase_tell
(
PyObject
*
self
,
PyObject
*
args
)
{
return
PyObject_CallMethod
(
self
,
"seek"
,
"ii"
,
0
,
1
);
}
PyDoc_STRVAR
(
IOB
ase_truncate_doc
,
PyDoc_STRVAR
(
iob
ase_truncate_doc
,
"Truncate file to size bytes.
\n
"
"
\n
"
"Size defaults to the current IO position as reported by tell(). Return
\n
"
"the new size."
);
static
PyObject
*
IOB
ase_truncate
(
PyObject
*
self
,
PyObject
*
args
)
iob
ase_truncate
(
PyObject
*
self
,
PyObject
*
args
)
{
return
IOB
ase_unsupported
(
"truncate"
);
return
iob
ase_unsupported
(
"truncate"
);
}
/* Flush and close methods */
PyDoc_STRVAR
(
IOB
ase_flush_doc
,
PyDoc_STRVAR
(
iob
ase_flush_doc
,
"Flush write buffers, if applicable.
\n
"
"
\n
"
"This is not implemented for read-only and non-blocking streams.
\n
"
);
static
PyObject
*
IOB
ase_flush
(
PyObject
*
self
,
PyObject
*
args
)
iob
ase_flush
(
PyObject
*
self
,
PyObject
*
args
)
{
/* XXX Should this return the number of bytes written??? */
if
(
IS_CLOSED
(
self
))
{
...
...
@@ -129,13 +129,13 @@ IOBase_flush(PyObject *self, PyObject *args)
Py_RETURN_NONE
;
}
PyDoc_STRVAR
(
IOB
ase_close_doc
,
PyDoc_STRVAR
(
iob
ase_close_doc
,
"Flush and close the IO object.
\n
"
"
\n
"
"This method has no effect if the file is already closed.
\n
"
);
static
int
IOB
ase_closed
(
PyObject
*
self
)
iob
ase_closed
(
PyObject
*
self
)
{
PyObject
*
res
;
int
closed
;
...
...
@@ -150,15 +150,15 @@ IOBase_closed(PyObject *self)
}
static
PyObject
*
IOB
ase_closed_get
(
PyObject
*
self
,
void
*
context
)
iob
ase_closed_get
(
PyObject
*
self
,
void
*
context
)
{
return
PyBool_FromLong
(
IS_CLOSED
(
self
));
}
PyObject
*
_PyIOBase_check
C
losed
(
PyObject
*
self
,
PyObject
*
args
)
_PyIOBase_check
_c
losed
(
PyObject
*
self
,
PyObject
*
args
)
{
if
(
IOB
ase_closed
(
self
))
{
if
(
iob
ase_closed
(
self
))
{
PyErr_SetString
(
PyExc_ValueError
,
"I/O operation on closed file."
);
return
NULL
;
}
...
...
@@ -173,7 +173,7 @@ _PyIOBase_checkClosed(PyObject *self, PyObject *args)
whatever behaviour a non-trivial derived class will implement. */
static
PyObject
*
IOB
ase_close
(
PyObject
*
self
,
PyObject
*
args
)
iob
ase_close
(
PyObject
*
self
,
PyObject
*
args
)
{
PyObject
*
res
;
...
...
@@ -260,14 +260,14 @@ _PyIOBase_finalize(PyObject *self)
}
static
int
IOBase_traverse
(
IOBaseObject
*
self
,
visitproc
visit
,
void
*
arg
)
iobase_traverse
(
iobase
*
self
,
visitproc
visit
,
void
*
arg
)
{
Py_VISIT
(
self
->
dict
);
return
0
;
}
static
int
IOBase_clear
(
IOBaseObject
*
self
)
iobase_clear
(
iobase
*
self
)
{
if
(
_PyIOBase_finalize
((
PyObject
*
)
self
)
<
0
)
return
-
1
;
...
...
@@ -278,7 +278,7 @@ IOBase_clear(IOBaseObject *self)
/* Destructor */
static
void
IOBase_dealloc
(
IOBaseObject
*
self
)
iobase_dealloc
(
iobase
*
self
)
{
/* NOTE: since IOBaseObject has its own dict, Python-defined attributes
are still available here for close() to use.
...
...
@@ -301,20 +301,20 @@ IOBase_dealloc(IOBaseObject *self)
/* Inquiry methods */
PyDoc_STRVAR
(
IOB
ase_seekable_doc
,
PyDoc_STRVAR
(
iob
ase_seekable_doc
,
"Return whether object supports random access.
\n
"
"
\n
"
"If False, seek(), tell() and truncate() will raise IOError.
\n
"
"This method may need to do a test seek()."
);
static
PyObject
*
IOB
ase_seekable
(
PyObject
*
self
,
PyObject
*
args
)
iob
ase_seekable
(
PyObject
*
self
,
PyObject
*
args
)
{
Py_RETURN_FALSE
;
}
PyObject
*
_PyIOBase_check
S
eekable
(
PyObject
*
self
,
PyObject
*
args
)
_PyIOBase_check
_s
eekable
(
PyObject
*
self
,
PyObject
*
args
)
{
PyObject
*
res
=
PyObject_CallMethodObjArgs
(
self
,
_PyIO_str_seekable
,
NULL
);
if
(
res
==
NULL
)
...
...
@@ -330,20 +330,20 @@ _PyIOBase_checkSeekable(PyObject *self, PyObject *args)
return
res
;
}
PyDoc_STRVAR
(
IOB
ase_readable_doc
,
PyDoc_STRVAR
(
iob
ase_readable_doc
,
"Return whether object was opened for reading.
\n
"
"
\n
"
"If False, read() will raise IOError."
);
static
PyObject
*
IOB
ase_readable
(
PyObject
*
self
,
PyObject
*
args
)
iob
ase_readable
(
PyObject
*
self
,
PyObject
*
args
)
{
Py_RETURN_FALSE
;
}
/* May be called with any object */
PyObject
*
_PyIOBase_check
R
eadable
(
PyObject
*
self
,
PyObject
*
args
)
_PyIOBase_check
_r
eadable
(
PyObject
*
self
,
PyObject
*
args
)
{
PyObject
*
res
=
PyObject_CallMethodObjArgs
(
self
,
_PyIO_str_readable
,
NULL
);
if
(
res
==
NULL
)
...
...
@@ -359,20 +359,20 @@ _PyIOBase_checkReadable(PyObject *self, PyObject *args)
return
res
;
}
PyDoc_STRVAR
(
IOB
ase_writable_doc
,
PyDoc_STRVAR
(
iob
ase_writable_doc
,
"Return whether object was opened for writing.
\n
"
"
\n
"
"If False, read() will raise IOError."
);
static
PyObject
*
IOB
ase_writable
(
PyObject
*
self
,
PyObject
*
args
)
iob
ase_writable
(
PyObject
*
self
,
PyObject
*
args
)
{
Py_RETURN_FALSE
;
}
/* May be called with any object */
PyObject
*
_PyIOBase_check
W
ritable
(
PyObject
*
self
,
PyObject
*
args
)
_PyIOBase_check
_w
ritable
(
PyObject
*
self
,
PyObject
*
args
)
{
PyObject
*
res
=
PyObject_CallMethodObjArgs
(
self
,
_PyIO_str_writable
,
NULL
);
if
(
res
==
NULL
)
...
...
@@ -391,9 +391,9 @@ _PyIOBase_checkWritable(PyObject *self, PyObject *args)
/* Context manager */
static
PyObject
*
IOB
ase_enter
(
PyObject
*
self
,
PyObject
*
args
)
iob
ase_enter
(
PyObject
*
self
,
PyObject
*
args
)
{
if
(
_PyIOBase_check
C
losed
(
self
,
Py_True
)
==
NULL
)
if
(
_PyIOBase_check
_c
losed
(
self
,
Py_True
)
==
NULL
)
return
NULL
;
Py_INCREF
(
self
);
...
...
@@ -401,7 +401,7 @@ IOBase_enter(PyObject *self, PyObject *args)
}
static
PyObject
*
IOB
ase_exit
(
PyObject
*
self
,
PyObject
*
args
)
iob
ase_exit
(
PyObject
*
self
,
PyObject
*
args
)
{
return
PyObject_CallMethodObjArgs
(
self
,
_PyIO_str_close
,
NULL
);
}
...
...
@@ -410,33 +410,33 @@ IOBase_exit(PyObject *self, PyObject *args)
/* XXX Should these be present even if unimplemented? */
PyDoc_STRVAR
(
IOB
ase_fileno_doc
,
PyDoc_STRVAR
(
iob
ase_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
"
);
static
PyObject
*
IOB
ase_fileno
(
PyObject
*
self
,
PyObject
*
args
)
iob
ase_fileno
(
PyObject
*
self
,
PyObject
*
args
)
{
return
IOB
ase_unsupported
(
"fileno"
);
return
iob
ase_unsupported
(
"fileno"
);
}
PyDoc_STRVAR
(
IOB
ase_isatty_doc
,
PyDoc_STRVAR
(
iob
ase_isatty_doc
,
"Return whether this is an 'interactive' stream.
\n
"
"
\n
"
"Return False if it can't be determined.
\n
"
);
static
PyObject
*
IOB
ase_isatty
(
PyObject
*
self
,
PyObject
*
args
)
iob
ase_isatty
(
PyObject
*
self
,
PyObject
*
args
)
{
if
(
_PyIOBase_check
C
losed
(
self
,
Py_True
)
==
NULL
)
if
(
_PyIOBase_check
_c
losed
(
self
,
Py_True
)
==
NULL
)
return
NULL
;
Py_RETURN_FALSE
;
}
/* Readline(s) and writelines */
PyDoc_STRVAR
(
IOB
ase_readline_doc
,
PyDoc_STRVAR
(
iob
ase_readline_doc
,
"Read and return a line from the stream.
\n
"
"
\n
"
"If limit is specified, at most limit bytes will be read.
\n
"
...
...
@@ -446,7 +446,7 @@ PyDoc_STRVAR(IOBase_readline_doc,
"terminator(s) recognized.
\n
"
);
static
PyObject
*
IOB
ase_readline
(
PyObject
*
self
,
PyObject
*
args
)
iob
ase_readline
(
PyObject
*
self
,
PyObject
*
args
)
{
/* For backwards compatibility, a (slowish) readline(). */
...
...
@@ -541,9 +541,9 @@ IOBase_readline(PyObject *self, PyObject *args)
}
static
PyObject
*
IOB
ase_iter
(
PyObject
*
self
)
iob
ase_iter
(
PyObject
*
self
)
{
if
(
_PyIOBase_check
C
losed
(
self
,
Py_True
)
==
NULL
)
if
(
_PyIOBase_check
_c
losed
(
self
,
Py_True
)
==
NULL
)
return
NULL
;
Py_INCREF
(
self
);
...
...
@@ -551,7 +551,7 @@ IOBase_iter(PyObject *self)
}
static
PyObject
*
IOB
ase_iternext
(
PyObject
*
self
)
iob
ase_iternext
(
PyObject
*
self
)
{
PyObject
*
line
=
PyObject_CallMethodObjArgs
(
self
,
_PyIO_str_readline
,
NULL
);
...
...
@@ -566,7 +566,7 @@ IOBase_iternext(PyObject *self)
return
line
;
}
PyDoc_STRVAR
(
IOB
ase_readlines_doc
,
PyDoc_STRVAR
(
iob
ase_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
"
...
...
@@ -574,7 +574,7 @@ PyDoc_STRVAR(IOBase_readlines_doc,
"lines so far exceeds hint."
);
static
PyObject
*
IOB
ase_readlines
(
PyObject
*
self
,
PyObject
*
args
)
iob
ase_readlines
(
PyObject
*
self
,
PyObject
*
args
)
{
Py_ssize_t
hint
=
-
1
,
length
=
0
;
PyObject
*
hintobj
=
Py_None
,
*
result
;
...
...
@@ -631,7 +631,7 @@ IOBase_readlines(PyObject *self, PyObject *args)
}
static
PyObject
*
IOB
ase_writelines
(
PyObject
*
self
,
PyObject
*
args
)
iob
ase_writelines
(
PyObject
*
self
,
PyObject
*
args
)
{
PyObject
*
lines
,
*
iter
,
*
res
;
...
...
@@ -639,7 +639,7 @@ IOBase_writelines(PyObject *self, PyObject *args)
return
NULL
;
}
if
(
_PyIOBase_check
C
losed
(
self
,
Py_True
)
==
NULL
)
if
(
_PyIOBase_check
_c
losed
(
self
,
Py_True
)
==
NULL
)
return
NULL
;
iter
=
PyObject_GetIter
(
lines
);
...
...
@@ -669,37 +669,37 @@ IOBase_writelines(PyObject *self, PyObject *args)
Py_RETURN_NONE
;
}
static
PyMethodDef
IOB
ase_methods
[]
=
{
{
"seek"
,
IOBase_seek
,
METH_VARARGS
,
IOB
ase_seek_doc
},
{
"tell"
,
IOBase_tell
,
METH_NOARGS
,
IOB
ase_tell_doc
},
{
"truncate"
,
IOBase_truncate
,
METH_VARARGS
,
IOB
ase_truncate_doc
},
{
"flush"
,
IOBase_flush
,
METH_NOARGS
,
IOB
ase_flush_doc
},
{
"close"
,
IOBase_close
,
METH_NOARGS
,
IOB
ase_close_doc
},
static
PyMethodDef
iob
ase_methods
[]
=
{
{
"seek"
,
iobase_seek
,
METH_VARARGS
,
iob
ase_seek_doc
},
{
"tell"
,
iobase_tell
,
METH_NOARGS
,
iob
ase_tell_doc
},
{
"truncate"
,
iobase_truncate
,
METH_VARARGS
,
iob
ase_truncate_doc
},
{
"flush"
,
iobase_flush
,
METH_NOARGS
,
iob
ase_flush_doc
},
{
"close"
,
iobase_close
,
METH_NOARGS
,
iob
ase_close_doc
},
{
"seekable"
,
IOBase_seekable
,
METH_NOARGS
,
IOB
ase_seekable_doc
},
{
"readable"
,
IOBase_readable
,
METH_NOARGS
,
IOB
ase_readable_doc
},
{
"writable"
,
IOBase_writable
,
METH_NOARGS
,
IOB
ase_writable_doc
},
{
"seekable"
,
iobase_seekable
,
METH_NOARGS
,
iob
ase_seekable_doc
},
{
"readable"
,
iobase_readable
,
METH_NOARGS
,
iob
ase_readable_doc
},
{
"writable"
,
iobase_writable
,
METH_NOARGS
,
iob
ase_writable_doc
},
{
"_checkClosed"
,
_PyIOBase_check
C
losed
,
METH_NOARGS
},
{
"_checkSeekable"
,
_PyIOBase_check
S
eekable
,
METH_NOARGS
},
{
"_checkReadable"
,
_PyIOBase_check
R
eadable
,
METH_NOARGS
},
{
"_checkWritable"
,
_PyIOBase_check
W
ritable
,
METH_NOARGS
},
{
"_checkClosed"
,
_PyIOBase_check
_c
losed
,
METH_NOARGS
},
{
"_checkSeekable"
,
_PyIOBase_check
_s
eekable
,
METH_NOARGS
},
{
"_checkReadable"
,
_PyIOBase_check
_r
eadable
,
METH_NOARGS
},
{
"_checkWritable"
,
_PyIOBase_check
_w
ritable
,
METH_NOARGS
},
{
"fileno"
,
IOBase_fileno
,
METH_NOARGS
,
IOB
ase_fileno_doc
},
{
"isatty"
,
IOBase_isatty
,
METH_NOARGS
,
IOB
ase_isatty_doc
},
{
"fileno"
,
iobase_fileno
,
METH_NOARGS
,
iob
ase_fileno_doc
},
{
"isatty"
,
iobase_isatty
,
METH_NOARGS
,
iob
ase_isatty_doc
},
{
"__enter__"
,
IOB
ase_enter
,
METH_NOARGS
},
{
"__exit__"
,
IOB
ase_exit
,
METH_VARARGS
},
{
"__enter__"
,
iob
ase_enter
,
METH_NOARGS
},
{
"__exit__"
,
iob
ase_exit
,
METH_VARARGS
},
{
"readline"
,
IOBase_readline
,
METH_VARARGS
,
IOB
ase_readline_doc
},
{
"readlines"
,
IOBase_readlines
,
METH_VARARGS
,
IOB
ase_readlines_doc
},
{
"writelines"
,
IOB
ase_writelines
,
METH_VARARGS
},
{
"readline"
,
iobase_readline
,
METH_VARARGS
,
iob
ase_readline_doc
},
{
"readlines"
,
iobase_readlines
,
METH_VARARGS
,
iob
ase_readlines_doc
},
{
"writelines"
,
iob
ase_writelines
,
METH_VARARGS
},
{
NULL
,
NULL
}
};
static
PyGetSetDef
IOB
ase_getset
[]
=
{
{
"closed"
,
(
getter
)
IOB
ase_closed_get
,
NULL
,
NULL
},
static
PyGetSetDef
iob
ase_getset
[]
=
{
{
"closed"
,
(
getter
)
iob
ase_closed_get
,
NULL
,
NULL
},
{
NULL
}
};
...
...
@@ -707,9 +707,9 @@ static PyGetSetDef IOBase_getset[] = {
PyTypeObject
PyIOBase_Type
=
{
PyVarObject_HEAD_INIT
(
NULL
,
0
)
"_io._IOBase"
,
/*tp_name*/
sizeof
(
IOBaseObject
),
/*tp_basicsize*/
sizeof
(
iobase
),
/*tp_basicsize*/
0
,
/*tp_itemsize*/
(
destructor
)
IOB
ase_dealloc
,
/*tp_dealloc*/
(
destructor
)
iob
ase_dealloc
,
/*tp_dealloc*/
0
,
/*tp_print*/
0
,
/*tp_getattr*/
0
,
/*tp_setattr*/
...
...
@@ -726,21 +726,21 @@ PyTypeObject PyIOBase_Type = {
0
,
/*tp_as_buffer*/
Py_TPFLAGS_DEFAULT
|
Py_TPFLAGS_BASETYPE
|
Py_TPFLAGS_HAVE_GC
,
/*tp_flags*/
IOB
ase_doc
,
/* tp_doc */
(
traverseproc
)
IOB
ase_traverse
,
/* tp_traverse */
(
inquiry
)
IOB
ase_clear
,
/* tp_clear */
iob
ase_doc
,
/* tp_doc */
(
traverseproc
)
iob
ase_traverse
,
/* tp_traverse */
(
inquiry
)
iob
ase_clear
,
/* tp_clear */
0
,
/* tp_richcompare */
offsetof
(
IOBaseObject
,
weakreflist
),
/* tp_weaklistoffset */
IOB
ase_iter
,
/* tp_iter */
IOB
ase_iternext
,
/* tp_iternext */
IOB
ase_methods
,
/* tp_methods */
offsetof
(
iobase
,
weakreflist
),
/* tp_weaklistoffset */
iob
ase_iter
,
/* tp_iter */
iob
ase_iternext
,
/* tp_iternext */
iob
ase_methods
,
/* tp_methods */
0
,
/* tp_members */
IOB
ase_getset
,
/* tp_getset */
iob
ase_getset
,
/* tp_getset */
0
,
/* tp_base */
0
,
/* tp_dict */
0
,
/* tp_descr_get */
0
,
/* tp_descr_set */
offsetof
(
IOBaseObject
,
dict
),
/* tp_dictoffset */
offsetof
(
iobase
,
dict
),
/* tp_dictoffset */
0
,
/* tp_init */
0
,
/* tp_alloc */
PyType_GenericNew
,
/* tp_new */
...
...
@@ -750,7 +750,7 @@ PyTypeObject PyIOBase_Type = {
/*
* RawIOBase class, Inherits from IOBase.
*/
PyDoc_STRVAR
(
RawIOB
ase_doc
,
PyDoc_STRVAR
(
rawiob
ase_doc
,
"Base class for raw binary I/O."
);
/*
...
...
@@ -766,7 +766,7 @@ PyDoc_STRVAR(RawIOBase_doc,
*/
static
PyObject
*
RawIOB
ase_read
(
PyObject
*
self
,
PyObject
*
args
)
rawiob
ase_read
(
PyObject
*
self
,
PyObject
*
args
)
{
Py_ssize_t
n
=
-
1
;
PyObject
*
b
,
*
res
;
...
...
@@ -803,11 +803,11 @@ RawIOBase_read(PyObject *self, PyObject *args)
}
PyDoc_STRVAR
(
RawIOB
ase_readall_doc
,
PyDoc_STRVAR
(
rawiob
ase_readall_doc
,
"Read until EOF, using multiple read() call."
);
static
PyObject
*
RawIOB
ase_readall
(
PyObject
*
self
,
PyObject
*
args
)
rawiob
ase_readall
(
PyObject
*
self
,
PyObject
*
args
)
{
int
r
;
PyObject
*
chunks
=
PyList_New
(
0
);
...
...
@@ -846,9 +846,9 @@ RawIOBase_readall(PyObject *self, PyObject *args)
return
result
;
}
static
PyMethodDef
RawIOB
ase_methods
[]
=
{
{
"read"
,
RawIOB
ase_read
,
METH_VARARGS
},
{
"readall"
,
RawIOBase_readall
,
METH_NOARGS
,
RawIOB
ase_readall_doc
},
static
PyMethodDef
rawiob
ase_methods
[]
=
{
{
"read"
,
rawiob
ase_read
,
METH_VARARGS
},
{
"readall"
,
rawiobase_readall
,
METH_NOARGS
,
rawiob
ase_readall_doc
},
{
NULL
,
NULL
}
};
...
...
@@ -873,14 +873,14 @@ PyTypeObject PyRawIOBase_Type = {
0
,
/*tp_setattro*/
0
,
/*tp_as_buffer*/
Py_TPFLAGS_DEFAULT
|
Py_TPFLAGS_BASETYPE
,
/*tp_flags*/
RawIOB
ase_doc
,
/* tp_doc */
rawiob
ase_doc
,
/* tp_doc */
0
,
/* tp_traverse */
0
,
/* tp_clear */
0
,
/* tp_richcompare */
0
,
/* tp_weaklistoffset */
0
,
/* tp_iter */
0
,
/* tp_iternext */
RawIOB
ase_methods
,
/* tp_methods */
rawiob
ase_methods
,
/* tp_methods */
0
,
/* tp_members */
0
,
/* tp_getset */
&
PyIOBase_Type
,
/* tp_base */
...
...
Modules/_io/stringio.c
View file @
680bf1af
...
...
@@ -24,7 +24,7 @@ typedef struct {
PyObject
*
dict
;
PyObject
*
weakreflist
;
}
StringIOObject
;
}
stringio
;
#define CHECK_INITIALIZED(self) \
if (self->ok <= 0) { \
...
...
@@ -51,7 +51,7 @@ PyDoc_STRVAR(stringio_doc,
buffer of StringIO objects. The caller should ensure that the 'size'
argument is non-negative. Returns 0 on success, -1 otherwise. */
static
int
resize_buffer
(
StringIOObject
*
self
,
size_t
size
)
resize_buffer
(
stringio
*
self
,
size_t
size
)
{
/* Here, unsigned types are used to avoid dealing with signed integer
overflow, which is undefined in C. */
...
...
@@ -106,7 +106,7 @@ resize_buffer(StringIOObject *self, size_t size)
/* Internal routine for writing a whole PyUnicode object to the buffer of a
StringIO object. Returns 0 on success, or -1 on error. */
static
Py_ssize_t
write_str
(
StringIOObject
*
self
,
PyObject
*
obj
)
write_str
(
stringio
*
self
,
PyObject
*
obj
)
{
Py_UNICODE
*
str
;
Py_ssize_t
len
;
...
...
@@ -186,7 +186,7 @@ PyDoc_STRVAR(stringio_getvalue_doc,
"Retrieve the entire contents of the object."
);
static
PyObject
*
stringio_getvalue
(
StringIOObject
*
self
)
stringio_getvalue
(
stringio
*
self
)
{
CHECK_INITIALIZED
(
self
);
CHECK_CLOSED
(
self
);
...
...
@@ -197,7 +197,7 @@ PyDoc_STRVAR(stringio_tell_doc,
"Tell the current file position."
);
static
PyObject
*
stringio_tell
(
StringIOObject
*
self
)
stringio_tell
(
stringio
*
self
)
{
CHECK_INITIALIZED
(
self
);
CHECK_CLOSED
(
self
);
...
...
@@ -211,7 +211,7 @@ PyDoc_STRVAR(stringio_read_doc,
"is reached. Return an empty string at EOF.
\n
"
);
static
PyObject
*
stringio_read
(
StringIOObject
*
self
,
PyObject
*
args
)
stringio_read
(
stringio
*
self
,
PyObject
*
args
)
{
Py_ssize_t
size
,
n
;
Py_UNICODE
*
output
;
...
...
@@ -252,7 +252,7 @@ stringio_read(StringIOObject *self, PyObject *args)
/* Internal helper, used by stringio_readline and stringio_iternext */
static
PyObject
*
_stringio_readline
(
StringIOObject
*
self
,
Py_ssize_t
limit
)
_stringio_readline
(
stringio
*
self
,
Py_ssize_t
limit
)
{
Py_UNICODE
*
start
,
*
end
,
old_char
;
Py_ssize_t
len
,
consumed
;
...
...
@@ -286,7 +286,7 @@ PyDoc_STRVAR(stringio_readline_doc,
"Returns an empty string if EOF is hit immediately.
\n
"
);
static
PyObject
*
stringio_readline
(
StringIOObject
*
self
,
PyObject
*
args
)
stringio_readline
(
stringio
*
self
,
PyObject
*
args
)
{
PyObject
*
arg
=
Py_None
;
Py_ssize_t
limit
=
-
1
;
...
...
@@ -310,7 +310,7 @@ stringio_readline(StringIOObject *self, PyObject *args)
}
static
PyObject
*
stringio_iternext
(
StringIOObject
*
self
)
stringio_iternext
(
stringio
*
self
)
{
PyObject
*
line
;
...
...
@@ -354,7 +354,7 @@ PyDoc_STRVAR(stringio_truncate_doc,
"Returns the new absolute position.
\n
"
);
static
PyObject
*
stringio_truncate
(
StringIOObject
*
self
,
PyObject
*
args
)
stringio_truncate
(
stringio
*
self
,
PyObject
*
args
)
{
Py_ssize_t
size
;
PyObject
*
arg
=
Py_None
;
...
...
@@ -405,7 +405,7 @@ PyDoc_STRVAR(stringio_seek_doc,
"Returns the new absolute position.
\n
"
);
static
PyObject
*
stringio_seek
(
StringIOObject
*
self
,
PyObject
*
args
)
stringio_seek
(
stringio
*
self
,
PyObject
*
args
)
{
Py_ssize_t
pos
;
int
mode
=
0
;
...
...
@@ -453,7 +453,7 @@ PyDoc_STRVAR(stringio_write_doc,
"the length of the string.
\n
"
);
static
PyObject
*
stringio_write
(
StringIOObject
*
self
,
PyObject
*
obj
)
stringio_write
(
stringio
*
self
,
PyObject
*
obj
)
{
Py_ssize_t
size
;
...
...
@@ -479,7 +479,7 @@ PyDoc_STRVAR(stringio_close_doc,
"This method has no effect if the file is already closed.
\n
"
);
static
PyObject
*
stringio_close
(
StringIOObject
*
self
)
stringio_close
(
stringio
*
self
)
{
self
->
closed
=
1
;
/* Free up some memory */
...
...
@@ -492,21 +492,21 @@ stringio_close(StringIOObject *self)
}
static
int
stringio_traverse
(
StringIOObject
*
self
,
visitproc
visit
,
void
*
arg
)
stringio_traverse
(
stringio
*
self
,
visitproc
visit
,
void
*
arg
)
{
Py_VISIT
(
self
->
dict
);
return
0
;
}
static
int
stringio_clear
(
StringIOObject
*
self
)
stringio_clear
(
stringio
*
self
)
{
Py_CLEAR
(
self
->
dict
);
return
0
;
}
static
void
stringio_dealloc
(
StringIOObject
*
self
)
stringio_dealloc
(
stringio
*
self
)
{
_PyObject_GC_UNTRACK
(
self
);
Py_CLEAR
(
self
->
readnl
);
...
...
@@ -522,10 +522,10 @@ stringio_dealloc(StringIOObject *self)
static
PyObject
*
stringio_new
(
PyTypeObject
*
type
,
PyObject
*
args
,
PyObject
*
kwds
)
{
StringIOObject
*
self
;
stringio
*
self
;
assert
(
type
!=
NULL
&&
type
->
tp_alloc
!=
NULL
);
self
=
(
StringIOObject
*
)
type
->
tp_alloc
(
type
,
0
);
self
=
(
stringio
*
)
type
->
tp_alloc
(
type
,
0
);
if
(
self
==
NULL
)
return
NULL
;
...
...
@@ -542,7 +542,7 @@ stringio_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
}
static
int
stringio_init
(
StringIOObject
*
self
,
PyObject
*
args
,
PyObject
*
kwds
)
stringio_init
(
stringio
*
self
,
PyObject
*
args
,
PyObject
*
kwds
)
{
char
*
kwlist
[]
=
{
"initial_value"
,
"newline"
,
NULL
};
PyObject
*
value
=
NULL
;
...
...
@@ -625,28 +625,28 @@ stringio_init(StringIOObject *self, PyObject *args, PyObject *kwds)
/* Properties and pseudo-properties */
static
PyObject
*
stringio_seekable
(
StringIOObject
*
self
,
PyObject
*
args
)
stringio_seekable
(
stringio
*
self
,
PyObject
*
args
)
{
CHECK_INITIALIZED
(
self
);
Py_RETURN_TRUE
;
}
static
PyObject
*
stringio_readable
(
StringIOObject
*
self
,
PyObject
*
args
)
stringio_readable
(
stringio
*
self
,
PyObject
*
args
)
{
CHECK_INITIALIZED
(
self
);
Py_RETURN_TRUE
;
}
static
PyObject
*
stringio_writable
(
StringIOObject
*
self
,
PyObject
*
args
)
stringio_writable
(
stringio
*
self
,
PyObject
*
args
)
{
CHECK_INITIALIZED
(
self
);
Py_RETURN_TRUE
;
}
static
PyObject
*
stringio_buffer
(
StringIOObject
*
self
,
void
*
context
)
stringio_buffer
(
stringio
*
self
,
void
*
context
)
{
PyErr_SetString
(
IO_STATE
->
unsupported_operation
,
"buffer attribute is unsupported on type StringIO"
);
...
...
@@ -654,14 +654,14 @@ stringio_buffer(StringIOObject *self, void *context)
}
static
PyObject
*
stringio_closed
(
StringIOObject
*
self
,
void
*
context
)
stringio_closed
(
stringio
*
self
,
void
*
context
)
{
CHECK_INITIALIZED
(
self
);
return
PyBool_FromLong
(
self
->
closed
);
}
static
PyObject
*
stringio_line_buffering
(
StringIOObject
*
self
,
void
*
context
)
stringio_line_buffering
(
stringio
*
self
,
void
*
context
)
{
CHECK_INITIALIZED
(
self
);
CHECK_CLOSED
(
self
);
...
...
@@ -669,7 +669,7 @@ stringio_line_buffering(StringIOObject *self, void *context)
}
static
PyObject
*
stringio_newlines
(
StringIOObject
*
self
,
void
*
context
)
stringio_newlines
(
stringio
*
self
,
void
*
context
)
{
CHECK_INITIALIZED
(
self
);
CHECK_CLOSED
(
self
);
...
...
@@ -711,7 +711,7 @@ static PyGetSetDef stringio_getset[] = {
PyTypeObject
PyStringIO_Type
=
{
PyVarObject_HEAD_INIT
(
NULL
,
0
)
"_io.StringIO"
,
/*tp_name*/
sizeof
(
StringIOObject
),
/*tp_basicsize*/
sizeof
(
stringio
),
/*tp_basicsize*/
0
,
/*tp_itemsize*/
(
destructor
)
stringio_dealloc
,
/*tp_dealloc*/
0
,
/*tp_print*/
...
...
@@ -734,7 +734,7 @@ PyTypeObject PyStringIO_Type = {
(
traverseproc
)
stringio_traverse
,
/*tp_traverse*/
(
inquiry
)
stringio_clear
,
/*tp_clear*/
0
,
/*tp_richcompare*/
offsetof
(
StringIOObject
,
weakreflist
),
/*tp_weaklistoffset*/
offsetof
(
stringio
,
weakreflist
),
/*tp_weaklistoffset*/
0
,
/*tp_iter*/
(
iternextfunc
)
stringio_iternext
,
/*tp_iternext*/
stringio_methods
,
/*tp_methods*/
...
...
@@ -744,7 +744,7 @@ PyTypeObject PyStringIO_Type = {
0
,
/*tp_dict*/
0
,
/*tp_descr_get*/
0
,
/*tp_descr_set*/
offsetof
(
StringIOObject
,
dict
),
/*tp_dictoffset*/
offsetof
(
stringio
,
dict
),
/*tp_dictoffset*/
(
initproc
)
stringio_init
,
/*tp_init*/
0
,
/*tp_alloc*/
stringio_new
,
/*tp_new*/
...
...
Modules/_io/textio.c
View file @
680bf1af
...
...
@@ -13,7 +13,7 @@
/* TextIOBase */
PyDoc_STRVAR
(
TextIOB
ase_doc
,
PyDoc_STRVAR
(
textiob
ase_doc
,
"Base class for text I/O.
\n
"
"
\n
"
"This class provides a character and line based interface to stream
\n
"
...
...
@@ -28,7 +28,7 @@ _unsupported(const char *message)
return
NULL
;
}
PyDoc_STRVAR
(
TextIOB
ase_detach_doc
,
PyDoc_STRVAR
(
textiob
ase_detach_doc
,
"Separate the underlying buffer from the TextIOBase and return it.
\n
"
"
\n
"
"After the underlying buffer has been detached, the TextIO is in an
\n
"
...
...
@@ -36,12 +36,12 @@ PyDoc_STRVAR(TextIOBase_detach_doc,
);
static
PyObject
*
TextIOB
ase_detach
(
PyObject
*
self
)
textiob
ase_detach
(
PyObject
*
self
)
{
return
_unsupported
(
"detach"
);
}
PyDoc_STRVAR
(
TextIOB
ase_read_doc
,
PyDoc_STRVAR
(
textiob
ase_read_doc
,
"Read at most n characters from stream.
\n
"
"
\n
"
"Read from underlying buffer until we have n characters or we hit EOF.
\n
"
...
...
@@ -49,48 +49,48 @@ PyDoc_STRVAR(TextIOBase_read_doc,
);
static
PyObject
*
TextIOB
ase_read
(
PyObject
*
self
,
PyObject
*
args
)
textiob
ase_read
(
PyObject
*
self
,
PyObject
*
args
)
{
return
_unsupported
(
"read"
);
}
PyDoc_STRVAR
(
TextIOB
ase_readline_doc
,
PyDoc_STRVAR
(
textiob
ase_readline_doc
,
"Read until newline or EOF.
\n
"
"
\n
"
"Returns an empty string if EOF is hit immediately.
\n
"
);
static
PyObject
*
TextIOB
ase_readline
(
PyObject
*
self
,
PyObject
*
args
)
textiob
ase_readline
(
PyObject
*
self
,
PyObject
*
args
)
{
return
_unsupported
(
"readline"
);
}
PyDoc_STRVAR
(
TextIOB
ase_write_doc
,
PyDoc_STRVAR
(
textiob
ase_write_doc
,
"Write string to stream.
\n
"
"Returns the number of characters written (which is always equal to
\n
"
"the length of the string).
\n
"
);
static
PyObject
*
TextIOB
ase_write
(
PyObject
*
self
,
PyObject
*
args
)
textiob
ase_write
(
PyObject
*
self
,
PyObject
*
args
)
{
return
_unsupported
(
"write"
);
}
PyDoc_STRVAR
(
TextIOB
ase_encoding_doc
,
PyDoc_STRVAR
(
textiob
ase_encoding_doc
,
"Encoding of the text stream.
\n
"
"
\n
"
"Subclasses should override.
\n
"
);
static
PyObject
*
TextIOB
ase_encoding_get
(
PyObject
*
self
,
void
*
context
)
textiob
ase_encoding_get
(
PyObject
*
self
,
void
*
context
)
{
Py_RETURN_NONE
;
}
PyDoc_STRVAR
(
TextIOB
ase_newlines_doc
,
PyDoc_STRVAR
(
textiob
ase_newlines_doc
,
"Line endings translated so far.
\n
"
"
\n
"
"Only line endings translated during reading are considered.
\n
"
...
...
@@ -99,36 +99,36 @@ PyDoc_STRVAR(TextIOBase_newlines_doc,
);
static
PyObject
*
TextIOB
ase_newlines_get
(
PyObject
*
self
,
void
*
context
)
textiob
ase_newlines_get
(
PyObject
*
self
,
void
*
context
)
{
Py_RETURN_NONE
;
}
PyDoc_STRVAR
(
TextIOB
ase_errors_doc
,
PyDoc_STRVAR
(
textiob
ase_errors_doc
,
"The error setting of the decoder or encoder.
\n
"
"
\n
"
"Subclasses should override.
\n
"
);
static
PyObject
*
TextIOB
ase_errors_get
(
PyObject
*
self
,
void
*
context
)
textiob
ase_errors_get
(
PyObject
*
self
,
void
*
context
)
{
Py_RETURN_NONE
;
}
static
PyMethodDef
TextIOB
ase_methods
[]
=
{
{
"detach"
,
(
PyCFunction
)
TextIOBase_detach
,
METH_NOARGS
,
TextIOB
ase_detach_doc
},
{
"read"
,
TextIOBase_read
,
METH_VARARGS
,
TextIOB
ase_read_doc
},
{
"readline"
,
TextIOBase_readline
,
METH_VARARGS
,
TextIOB
ase_readline_doc
},
{
"write"
,
TextIOBase_write
,
METH_VARARGS
,
TextIOB
ase_write_doc
},
static
PyMethodDef
textiob
ase_methods
[]
=
{
{
"detach"
,
(
PyCFunction
)
textiobase_detach
,
METH_NOARGS
,
textiob
ase_detach_doc
},
{
"read"
,
textiobase_read
,
METH_VARARGS
,
textiob
ase_read_doc
},
{
"readline"
,
textiobase_readline
,
METH_VARARGS
,
textiob
ase_readline_doc
},
{
"write"
,
textiobase_write
,
METH_VARARGS
,
textiob
ase_write_doc
},
{
NULL
,
NULL
}
};
static
PyGetSetDef
TextIOB
ase_getset
[]
=
{
{
"encoding"
,
(
getter
)
TextIOBase_encoding_get
,
NULL
,
TextIOB
ase_encoding_doc
},
{
"newlines"
,
(
getter
)
TextIOBase_newlines_get
,
NULL
,
TextIOB
ase_newlines_doc
},
{
"errors"
,
(
getter
)
TextIOBase_errors_get
,
NULL
,
TextIOB
ase_errors_doc
},
static
PyGetSetDef
textiob
ase_getset
[]
=
{
{
"encoding"
,
(
getter
)
textiobase_encoding_get
,
NULL
,
textiob
ase_encoding_doc
},
{
"newlines"
,
(
getter
)
textiobase_newlines_get
,
NULL
,
textiob
ase_newlines_doc
},
{
"errors"
,
(
getter
)
textiobase_errors_get
,
NULL
,
textiob
ase_errors_doc
},
{
NULL
}
};
...
...
@@ -153,16 +153,16 @@ PyTypeObject PyTextIOBase_Type = {
0
,
/*tp_setattro*/
0
,
/*tp_as_buffer*/
Py_TPFLAGS_DEFAULT
|
Py_TPFLAGS_BASETYPE
,
/*tp_flags*/
TextIOB
ase_doc
,
/* tp_doc */
textiob
ase_doc
,
/* tp_doc */
0
,
/* tp_traverse */
0
,
/* tp_clear */
0
,
/* tp_richcompare */
0
,
/* tp_weaklistoffset */
0
,
/* tp_iter */
0
,
/* tp_iternext */
TextIOB
ase_methods
,
/* tp_methods */
textiob
ase_methods
,
/* tp_methods */
0
,
/* tp_members */
TextIOB
ase_getset
,
/* tp_getset */
textiob
ase_getset
,
/* tp_getset */
&
PyIOBase_Type
,
/* tp_base */
0
,
/* tp_dict */
0
,
/* tp_descr_get */
...
...
@@ -176,7 +176,7 @@ PyTypeObject PyTextIOBase_Type = {
/* IncrementalNewlineDecoder */
PyDoc_STRVAR
(
IncrementalNewlineD
ecoder_doc
,
PyDoc_STRVAR
(
incrementalnewlined
ecoder_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
"
...
...
@@ -193,10 +193,10 @@ typedef struct {
int
pendingcr
:
1
;
int
translate
:
1
;
unsigned
int
seennl
:
3
;
}
PyNewLineDecoderO
bject
;
}
nldecoder_o
bject
;
static
int
IncrementalNewlineDecoder_init
(
PyNewLineDecoderO
bject
*
self
,
incrementalnewlinedecoder_init
(
nldecoder_o
bject
*
self
,
PyObject
*
args
,
PyObject
*
kwds
)
{
PyObject
*
decoder
;
...
...
@@ -229,7 +229,7 @@ IncrementalNewlineDecoder_init(PyNewLineDecoderObject *self,
}
static
void
IncrementalNewlineDecoder_dealloc
(
PyNewLineDecoderO
bject
*
self
)
incrementalnewlinedecoder_dealloc
(
nldecoder_o
bject
*
self
)
{
Py_CLEAR
(
self
->
decoder
);
Py_CLEAR
(
self
->
errors
);
...
...
@@ -247,7 +247,7 @@ _PyIncrementalNewlineDecoder_decode(PyObject *_self,
{
PyObject
*
output
;
Py_ssize_t
output_len
;
PyNewLineDecoderObject
*
self
=
(
PyNewLineDecoderO
bject
*
)
_self
;
nldecoder_object
*
self
=
(
nldecoder_o
bject
*
)
_self
;
if
(
self
->
decoder
==
NULL
)
{
PyErr_SetString
(
PyExc_ValueError
,
...
...
@@ -460,7 +460,7 @@ _PyIncrementalNewlineDecoder_decode(PyObject *_self,
}
static
PyObject
*
IncrementalNewlineDecoder_decode
(
PyNewLineDecoderO
bject
*
self
,
incrementalnewlinedecoder_decode
(
nldecoder_o
bject
*
self
,
PyObject
*
args
,
PyObject
*
kwds
)
{
char
*
kwlist
[]
=
{
"input"
,
"final"
,
NULL
};
...
...
@@ -474,7 +474,7 @@ IncrementalNewlineDecoder_decode(PyNewLineDecoderObject *self,
}
static
PyObject
*
IncrementalNewlineDecoder_getstate
(
PyNewLineDecoderO
bject
*
self
,
PyObject
*
args
)
incrementalnewlinedecoder_getstate
(
nldecoder_o
bject
*
self
,
PyObject
*
args
)
{
PyObject
*
buffer
;
unsigned
PY_LONG_LONG
flag
;
...
...
@@ -502,7 +502,7 @@ IncrementalNewlineDecoder_getstate(PyNewLineDecoderObject *self, PyObject *args)
}
static
PyObject
*
IncrementalNewlineDecoder_setstate
(
PyNewLineDecoderO
bject
*
self
,
PyObject
*
state
)
incrementalnewlinedecoder_setstate
(
nldecoder_o
bject
*
self
,
PyObject
*
state
)
{
PyObject
*
buffer
;
unsigned
PY_LONG_LONG
flag
;
...
...
@@ -521,7 +521,7 @@ IncrementalNewlineDecoder_setstate(PyNewLineDecoderObject *self, PyObject *state
}
static
PyObject
*
IncrementalNewlineDecoder_reset
(
PyNewLineDecoderO
bject
*
self
,
PyObject
*
args
)
incrementalnewlinedecoder_reset
(
nldecoder_o
bject
*
self
,
PyObject
*
args
)
{
self
->
seennl
=
0
;
self
->
pendingcr
=
0
;
...
...
@@ -532,7 +532,7 @@ IncrementalNewlineDecoder_reset(PyNewLineDecoderObject *self, PyObject *args)
}
static
PyObject
*
IncrementalNewlineDecoder_newlines_get
(
PyNewLineDecoderO
bject
*
self
,
void
*
context
)
incrementalnewlinedecoder_newlines_get
(
nldecoder_o
bject
*
self
,
void
*
context
)
{
switch
(
self
->
seennl
)
{
case
SEEN_CR
:
...
...
@@ -556,25 +556,25 @@ IncrementalNewlineDecoder_newlines_get(PyNewLineDecoderObject *self, void *conte
}
static
PyMethodDef
IncrementalNewlineD
ecoder_methods
[]
=
{
{
"decode"
,
(
PyCFunction
)
IncrementalNewlineD
ecoder_decode
,
METH_VARARGS
|
METH_KEYWORDS
},
{
"getstate"
,
(
PyCFunction
)
IncrementalNewlineD
ecoder_getstate
,
METH_NOARGS
},
{
"setstate"
,
(
PyCFunction
)
IncrementalNewlineD
ecoder_setstate
,
METH_O
},
{
"reset"
,
(
PyCFunction
)
IncrementalNewlineD
ecoder_reset
,
METH_NOARGS
},
static
PyMethodDef
incrementalnewlined
ecoder_methods
[]
=
{
{
"decode"
,
(
PyCFunction
)
incrementalnewlined
ecoder_decode
,
METH_VARARGS
|
METH_KEYWORDS
},
{
"getstate"
,
(
PyCFunction
)
incrementalnewlined
ecoder_getstate
,
METH_NOARGS
},
{
"setstate"
,
(
PyCFunction
)
incrementalnewlined
ecoder_setstate
,
METH_O
},
{
"reset"
,
(
PyCFunction
)
incrementalnewlined
ecoder_reset
,
METH_NOARGS
},
{
NULL
}
};
static
PyGetSetDef
IncrementalNewlineD
ecoder_getset
[]
=
{
{
"newlines"
,
(
getter
)
IncrementalNewlineD
ecoder_newlines_get
,
NULL
,
NULL
},
static
PyGetSetDef
incrementalnewlined
ecoder_getset
[]
=
{
{
"newlines"
,
(
getter
)
incrementalnewlined
ecoder_newlines_get
,
NULL
,
NULL
},
{
NULL
}
};
PyTypeObject
PyIncrementalNewlineDecoder_Type
=
{
PyVarObject_HEAD_INIT
(
NULL
,
0
)
"_io.IncrementalNewlineDecoder"
,
/*tp_name*/
sizeof
(
PyNewLineDecoderO
bject
),
/*tp_basicsize*/
sizeof
(
nldecoder_o
bject
),
/*tp_basicsize*/
0
,
/*tp_itemsize*/
(
destructor
)
IncrementalNewlineD
ecoder_dealloc
,
/*tp_dealloc*/
(
destructor
)
incrementalnewlined
ecoder_dealloc
,
/*tp_dealloc*/
0
,
/*tp_print*/
0
,
/*tp_getattr*/
0
,
/*tp_setattr*/
...
...
@@ -590,22 +590,22 @@ PyTypeObject PyIncrementalNewlineDecoder_Type = {
0
,
/*tp_setattro*/
0
,
/*tp_as_buffer*/
Py_TPFLAGS_DEFAULT
|
Py_TPFLAGS_BASETYPE
,
/*tp_flags*/
IncrementalNewlineD
ecoder_doc
,
/* tp_doc */
incrementalnewlined
ecoder_doc
,
/* tp_doc */
0
,
/* tp_traverse */
0
,
/* tp_clear */
0
,
/* tp_richcompare */
0
,
/*tp_weaklistoffset*/
0
,
/* tp_iter */
0
,
/* tp_iternext */
IncrementalNewlineD
ecoder_methods
,
/* tp_methods */
incrementalnewlined
ecoder_methods
,
/* tp_methods */
0
,
/* tp_members */
IncrementalNewlineD
ecoder_getset
,
/* tp_getset */
incrementalnewlined
ecoder_getset
,
/* tp_getset */
0
,
/* tp_base */
0
,
/* tp_dict */
0
,
/* tp_descr_get */
0
,
/* tp_descr_set */
0
,
/* tp_dictoffset */
(
initproc
)
IncrementalNewlineD
ecoder_init
,
/* tp_init */
(
initproc
)
incrementalnewlined
ecoder_init
,
/* tp_init */
0
,
/* tp_alloc */
PyType_GenericNew
,
/* tp_new */
};
...
...
@@ -613,7 +613,7 @@ PyTypeObject PyIncrementalNewlineDecoder_Type = {
/* TextIOWrapper */
PyDoc_STRVAR
(
TextIOW
rapper_doc
,
PyDoc_STRVAR
(
textiow
rapper_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
"
...
...
@@ -689,14 +689,14 @@ typedef struct
PyObject
*
weakreflist
;
PyObject
*
dict
;
}
PyTextIOWrapperObject
;
}
textio
;
/* A couple of specialized cases in order to bypass the slow incremental
encoding methods for the most popular encodings. */
static
PyObject
*
ascii_encode
(
PyTextIOWrapperObject
*
self
,
PyObject
*
text
)
ascii_encode
(
textio
*
self
,
PyObject
*
text
)
{
return
PyUnicode_EncodeASCII
(
PyUnicode_AS_UNICODE
(
text
),
PyUnicode_GET_SIZE
(
text
),
...
...
@@ -704,7 +704,7 @@ ascii_encode(PyTextIOWrapperObject *self, PyObject *text)
}
static
PyObject
*
utf16be_encode
(
PyTextIOWrapperObject
*
self
,
PyObject
*
text
)
utf16be_encode
(
textio
*
self
,
PyObject
*
text
)
{
return
PyUnicode_EncodeUTF16
(
PyUnicode_AS_UNICODE
(
text
),
PyUnicode_GET_SIZE
(
text
),
...
...
@@ -712,7 +712,7 @@ utf16be_encode(PyTextIOWrapperObject *self, PyObject *text)
}
static
PyObject
*
utf16le_encode
(
PyTextIOWrapperObject
*
self
,
PyObject
*
text
)
utf16le_encode
(
textio
*
self
,
PyObject
*
text
)
{
return
PyUnicode_EncodeUTF16
(
PyUnicode_AS_UNICODE
(
text
),
PyUnicode_GET_SIZE
(
text
),
...
...
@@ -720,7 +720,7 @@ utf16le_encode(PyTextIOWrapperObject *self, PyObject *text)
}
static
PyObject
*
utf16_encode
(
PyTextIOWrapperObject
*
self
,
PyObject
*
text
)
utf16_encode
(
textio
*
self
,
PyObject
*
text
)
{
if
(
!
self
->
encoding_start_of_stream
)
{
/* Skip the BOM and use native byte ordering */
...
...
@@ -736,7 +736,7 @@ utf16_encode(PyTextIOWrapperObject *self, PyObject *text)
}
static
PyObject
*
utf32be_encode
(
PyTextIOWrapperObject
*
self
,
PyObject
*
text
)
utf32be_encode
(
textio
*
self
,
PyObject
*
text
)
{
return
PyUnicode_EncodeUTF32
(
PyUnicode_AS_UNICODE
(
text
),
PyUnicode_GET_SIZE
(
text
),
...
...
@@ -744,7 +744,7 @@ utf32be_encode(PyTextIOWrapperObject *self, PyObject *text)
}
static
PyObject
*
utf32le_encode
(
PyTextIOWrapperObject
*
self
,
PyObject
*
text
)
utf32le_encode
(
textio
*
self
,
PyObject
*
text
)
{
return
PyUnicode_EncodeUTF32
(
PyUnicode_AS_UNICODE
(
text
),
PyUnicode_GET_SIZE
(
text
),
...
...
@@ -752,7 +752,7 @@ utf32le_encode(PyTextIOWrapperObject *self, PyObject *text)
}
static
PyObject
*
utf32_encode
(
PyTextIOWrapperObject
*
self
,
PyObject
*
text
)
utf32_encode
(
textio
*
self
,
PyObject
*
text
)
{
if
(
!
self
->
encoding_start_of_stream
)
{
/* Skip the BOM and use native byte ordering */
...
...
@@ -768,7 +768,7 @@ utf32_encode(PyTextIOWrapperObject *self, PyObject *text)
}
static
PyObject
*
utf8_encode
(
PyTextIOWrapperObject
*
self
,
PyObject
*
text
)
utf8_encode
(
textio
*
self
,
PyObject
*
text
)
{
return
PyUnicode_EncodeUTF8
(
PyUnicode_AS_UNICODE
(
text
),
PyUnicode_GET_SIZE
(
text
),
...
...
@@ -776,7 +776,7 @@ utf8_encode(PyTextIOWrapperObject *self, PyObject *text)
}
static
PyObject
*
latin1_encode
(
PyTextIOWrapperObject
*
self
,
PyObject
*
text
)
latin1_encode
(
textio
*
self
,
PyObject
*
text
)
{
return
PyUnicode_EncodeLatin1
(
PyUnicode_AS_UNICODE
(
text
),
PyUnicode_GET_SIZE
(
text
),
...
...
@@ -805,7 +805,7 @@ static encodefuncentry encodefuncs[] = {
static
int
TextIOWrapper_init
(
PyTextIOWrapperObject
*
self
,
PyObject
*
args
,
PyObject
*
kwds
)
textiowrapper_init
(
textio
*
self
,
PyObject
*
args
,
PyObject
*
kwds
)
{
char
*
kwlist
[]
=
{
"buffer"
,
"encoding"
,
"errors"
,
"newline"
,
"line_buffering"
,
...
...
@@ -1068,7 +1068,7 @@ TextIOWrapper_init(PyTextIOWrapperObject *self, PyObject *args, PyObject *kwds)
}
static
int
_
TextIOWrapper_clear
(
PyTextIOWrapperObject
*
self
)
_
textiowrapper_clear
(
textio
*
self
)
{
if
(
self
->
ok
&&
_PyIOBase_finalize
((
PyObject
*
)
self
)
<
0
)
return
-
1
;
...
...
@@ -1087,9 +1087,9 @@ _TextIOWrapper_clear(PyTextIOWrapperObject *self)
}
static
void
TextIOWrapper_dealloc
(
PyTextIOWrapperObject
*
self
)
textiowrapper_dealloc
(
textio
*
self
)
{
if
(
_
TextIOW
rapper_clear
(
self
)
<
0
)
if
(
_
textiow
rapper_clear
(
self
)
<
0
)
return
;
_PyObject_GC_UNTRACK
(
self
);
if
(
self
->
weakreflist
!=
NULL
)
...
...
@@ -1099,7 +1099,7 @@ TextIOWrapper_dealloc(PyTextIOWrapperObject *self)
}
static
int
TextIOWrapper_traverse
(
PyTextIOWrapperObject
*
self
,
visitproc
visit
,
void
*
arg
)
textiowrapper_traverse
(
textio
*
self
,
visitproc
visit
,
void
*
arg
)
{
Py_VISIT
(
self
->
buffer
);
Py_VISIT
(
self
->
encoding
);
...
...
@@ -1117,16 +1117,16 @@ TextIOWrapper_traverse(PyTextIOWrapperObject *self, visitproc visit, void *arg)
}
static
int
TextIOWrapper_clear
(
PyTextIOWrapperObject
*
self
)
textiowrapper_clear
(
textio
*
self
)
{
if
(
_
TextIOW
rapper_clear
(
self
)
<
0
)
if
(
_
textiow
rapper_clear
(
self
)
<
0
)
return
-
1
;
Py_CLEAR
(
self
->
dict
);
return
0
;
}
static
PyObject
*
TextIOWrapper_closed_get
(
PyTextIOWrapperObject
*
self
,
void
*
context
);
textiowrapper_closed_get
(
textio
*
self
,
void
*
context
);
/* This macro takes some shortcuts to make the common case faster. */
#define CHECK_CLOSED(self) \
...
...
@@ -1137,7 +1137,7 @@ TextIOWrapper_closed_get(PyTextIOWrapperObject *self, void *context);
if (self->raw != NULL) \
r = _PyFileIO_closed(self->raw); \
else { \
_res =
TextIOW
rapper_closed_get(self, NULL); \
_res =
textiow
rapper_closed_get(self, NULL); \
if (_res == NULL) \
return NULL; \
r = PyObject_IsTrue(_res); \
...
...
@@ -1151,7 +1151,7 @@ TextIOWrapper_closed_get(PyTextIOWrapperObject *self, void *context);
return NULL; \
} \
} \
else if (_PyIOBase_check
C
losed((PyObject *)self, Py_True) == NULL) \
else if (_PyIOBase_check
_c
losed((PyObject *)self, Py_True) == NULL) \
return NULL; \
} while (0)
...
...
@@ -1181,7 +1181,7 @@ TextIOWrapper_closed_get(PyTextIOWrapperObject *self, void *context);
static
PyObject
*
TextIOWrapper_detach
(
PyTextIOWrapperObject
*
self
)
textiowrapper_detach
(
textio
*
self
)
{
PyObject
*
buffer
,
*
res
;
CHECK_INITIALIZED
(
self
);
...
...
@@ -1211,7 +1211,7 @@ findchar(const Py_UNICODE *s, Py_ssize_t size, Py_UNICODE ch)
/* Flush the internal write buffer. This doesn't explicitly flush the
underlying buffered object, though. */
static
int
_
TextIOWrapper_writeflush
(
PyTextIOWrapperObject
*
self
)
_
textiowrapper_writeflush
(
textio
*
self
)
{
PyObject
*
b
,
*
ret
;
...
...
@@ -1232,7 +1232,7 @@ _TextIOWrapper_writeflush(PyTextIOWrapperObject *self)
}
static
PyObject
*
TextIOWrapper_write
(
PyTextIOWrapperObject
*
self
,
PyObject
*
args
)
textiowrapper_write
(
textio
*
self
,
PyObject
*
args
)
{
PyObject
*
ret
;
PyObject
*
text
;
/* owned reference */
...
...
@@ -1305,7 +1305,7 @@ TextIOWrapper_write(PyTextIOWrapperObject *self, PyObject *args)
self
->
pending_bytes_count
+=
PyBytes_GET_SIZE
(
b
);
Py_DECREF
(
b
);
if
(
self
->
pending_bytes_count
>
self
->
chunk_size
||
needflush
)
{
if
(
_
TextIOW
rapper_writeflush
(
self
)
<
0
)
if
(
_
textiow
rapper_writeflush
(
self
)
<
0
)
return
NULL
;
}
...
...
@@ -1331,7 +1331,7 @@ TextIOWrapper_write(PyTextIOWrapperObject *self, PyObject *args)
/* Steal a reference to chars and store it in the decoded_char buffer;
*/
static
void
TextIOWrapper_set_decoded_chars
(
PyTextIOWrapperObject
*
self
,
PyObject
*
chars
)
textiowrapper_set_decoded_chars
(
textio
*
self
,
PyObject
*
chars
)
{
Py_CLEAR
(
self
->
decoded_chars
);
self
->
decoded_chars
=
chars
;
...
...
@@ -1339,7 +1339,7 @@ TextIOWrapper_set_decoded_chars(PyTextIOWrapperObject *self, PyObject *chars)
}
static
PyObject
*
TextIOWrapper_get_decoded_chars
(
PyTextIOWrapperObject
*
self
,
Py_ssize_t
n
)
textiowrapper_get_decoded_chars
(
textio
*
self
,
Py_ssize_t
n
)
{
PyObject
*
chars
;
Py_ssize_t
avail
;
...
...
@@ -1374,7 +1374,7 @@ TextIOWrapper_get_decoded_chars(PyTextIOWrapperObject *self, Py_ssize_t n)
/* Read and decode the next chunk of data from the BufferedReader.
*/
static
int
TextIOWrapper_read_chunk
(
PyTextIOWrapperObject
*
self
)
textiowrapper_read_chunk
(
textio
*
self
)
{
PyObject
*
dec_buffer
=
NULL
;
PyObject
*
dec_flags
=
NULL
;
...
...
@@ -1439,7 +1439,7 @@ TextIOWrapper_read_chunk(PyTextIOWrapperObject *self)
/* TODO sanity check: isinstance(decoded_chars, unicode) */
if
(
decoded_chars
==
NULL
)
goto
fail
;
TextIOW
rapper_set_decoded_chars
(
self
,
decoded_chars
);
textiow
rapper_set_decoded_chars
(
self
,
decoded_chars
);
if
(
PyUnicode_GET_SIZE
(
decoded_chars
)
>
0
)
eof
=
0
;
...
...
@@ -1467,7 +1467,7 @@ TextIOWrapper_read_chunk(PyTextIOWrapperObject *self)
}
static
PyObject
*
TextIOWrapper_read
(
PyTextIOWrapperObject
*
self
,
PyObject
*
args
)
textiowrapper_read
(
textio
*
self
,
PyObject
*
args
)
{
Py_ssize_t
n
=
-
1
;
PyObject
*
result
=
NULL
,
*
chunks
=
NULL
;
...
...
@@ -1484,7 +1484,7 @@ TextIOWrapper_read(PyTextIOWrapperObject *self, PyObject *args)
return
NULL
;
}
if
(
_
TextIOW
rapper_writeflush
(
self
)
<
0
)
if
(
_
textiow
rapper_writeflush
(
self
)
<
0
)
return
NULL
;
if
(
n
<
0
)
{
...
...
@@ -1499,7 +1499,7 @@ TextIOWrapper_read(PyTextIOWrapperObject *self, PyObject *args)
if
(
decoded
==
NULL
)
goto
fail
;
result
=
TextIOW
rapper_get_decoded_chars
(
self
,
-
1
);
result
=
textiow
rapper_get_decoded_chars
(
self
,
-
1
);
if
(
result
==
NULL
)
{
Py_DECREF
(
decoded
);
...
...
@@ -1517,14 +1517,14 @@ TextIOWrapper_read(PyTextIOWrapperObject *self, PyObject *args)
int
res
=
1
;
Py_ssize_t
remaining
=
n
;
result
=
TextIOW
rapper_get_decoded_chars
(
self
,
n
);
result
=
textiow
rapper_get_decoded_chars
(
self
,
n
);
if
(
result
==
NULL
)
goto
fail
;
remaining
-=
PyUnicode_GET_SIZE
(
result
);
/* Keep reading chunks until we have n characters to return */
while
(
remaining
>
0
)
{
res
=
TextIOW
rapper_read_chunk
(
self
);
res
=
textiow
rapper_read_chunk
(
self
);
if
(
res
<
0
)
goto
fail
;
if
(
res
==
0
)
/* EOF */
...
...
@@ -1537,7 +1537,7 @@ TextIOWrapper_read(PyTextIOWrapperObject *self, PyObject *args)
if
(
PyList_Append
(
chunks
,
result
)
<
0
)
goto
fail
;
Py_DECREF
(
result
);
result
=
TextIOW
rapper_get_decoded_chars
(
self
,
remaining
);
result
=
textiow
rapper_get_decoded_chars
(
self
,
remaining
);
if
(
result
==
NULL
)
goto
fail
;
remaining
-=
PyUnicode_GET_SIZE
(
result
);
...
...
@@ -1662,7 +1662,7 @@ _PyIO_find_line_ending(
}
static
PyObject
*
_
TextIOWrapper_readline
(
PyTextIOWrapperObject
*
self
,
Py_ssize_t
limit
)
_
textiowrapper_readline
(
textio
*
self
,
Py_ssize_t
limit
)
{
PyObject
*
line
=
NULL
,
*
chunks
=
NULL
,
*
remaining
=
NULL
;
Py_ssize_t
start
,
endpos
,
chunked
,
offset_to_buffer
;
...
...
@@ -1670,7 +1670,7 @@ _TextIOWrapper_readline(PyTextIOWrapperObject *self, Py_ssize_t limit)
CHECK_CLOSED
(
self
);
if
(
_
TextIOW
rapper_writeflush
(
self
)
<
0
)
if
(
_
textiow
rapper_writeflush
(
self
)
<
0
)
return
NULL
;
chunked
=
0
;
...
...
@@ -1684,7 +1684,7 @@ _TextIOWrapper_readline(PyTextIOWrapperObject *self, Py_ssize_t limit)
res
=
1
;
while
(
!
self
->
decoded_chars
||
!
PyUnicode_GET_SIZE
(
self
->
decoded_chars
))
{
res
=
TextIOW
rapper_read_chunk
(
self
);
res
=
textiow
rapper_read_chunk
(
self
);
if
(
res
<
0
)
goto
error
;
if
(
res
==
0
)
...
...
@@ -1692,7 +1692,7 @@ _TextIOWrapper_readline(PyTextIOWrapperObject *self, Py_ssize_t limit)
}
if
(
res
==
0
)
{
/* end of file */
TextIOW
rapper_set_decoded_chars
(
self
,
NULL
);
textiow
rapper_set_decoded_chars
(
self
,
NULL
);
Py_CLEAR
(
self
->
snapshot
);
start
=
endpos
=
offset_to_buffer
=
0
;
break
;
...
...
@@ -1763,7 +1763,7 @@ _TextIOWrapper_readline(PyTextIOWrapperObject *self, Py_ssize_t limit)
}
Py_CLEAR
(
line
);
/* We have consumed the buffer */
TextIOW
rapper_set_decoded_chars
(
self
,
NULL
);
textiow
rapper_set_decoded_chars
(
self
,
NULL
);
}
if
(
line
!=
NULL
)
{
...
...
@@ -1816,7 +1816,7 @@ _TextIOWrapper_readline(PyTextIOWrapperObject *self, Py_ssize_t limit)
}
static
PyObject
*
TextIOWrapper_readline
(
PyTextIOWrapperObject
*
self
,
PyObject
*
args
)
textiowrapper_readline
(
textio
*
self
,
PyObject
*
args
)
{
Py_ssize_t
limit
=
-
1
;
...
...
@@ -1824,7 +1824,7 @@ TextIOWrapper_readline(PyTextIOWrapperObject *self, PyObject *args)
if
(
!
PyArg_ParseTuple
(
args
,
"|n:readline"
,
&
limit
))
{
return
NULL
;
}
return
_
TextIOW
rapper_readline
(
self
,
limit
);
return
_
textiow
rapper_readline
(
self
,
limit
);
}
/* Seek and Tell */
...
...
@@ -1835,7 +1835,7 @@ typedef struct {
int
bytes_to_feed
;
int
chars_to_skip
;
char
need_eof
;
}
CookieStruct
;
}
cookie_type
;
/*
To speed up cookie packing/unpacking, we store the fields in a temporary
...
...
@@ -1876,7 +1876,7 @@ typedef struct {
#endif
static
int
TextIOWrapper_parseCookie
(
CookieStruct
*
cookie
,
PyObject
*
cookieObj
)
textiowrapper_parse_cookie
(
cookie_type
*
cookie
,
PyObject
*
cookieObj
)
{
unsigned
char
buffer
[
COOKIE_BUF_LEN
];
PyLongObject
*
cookieLong
=
(
PyLongObject
*
)
PyNumber_Long
(
cookieObj
);
...
...
@@ -1900,7 +1900,7 @@ TextIOWrapper_parseCookie(CookieStruct *cookie, PyObject *cookieObj)
}
static
PyObject
*
TextIOWrapper_buildCookie
(
CookieStruct
*
cookie
)
textiowrapper_build_cookie
(
cookie_type
*
cookie
)
{
unsigned
char
buffer
[
COOKIE_BUF_LEN
];
...
...
@@ -1915,8 +1915,7 @@ TextIOWrapper_buildCookie(CookieStruct *cookie)
#undef IS_LITTLE_ENDIAN
static
int
_TextIOWrapper_decoder_setstate
(
PyTextIOWrapperObject
*
self
,
CookieStruct
*
cookie
)
_textiowrapper_decoder_setstate
(
textio
*
self
,
cookie_type
*
cookie
)
{
PyObject
*
res
;
/* When seeking to the start of the stream, we call decoder.reset()
...
...
@@ -1937,11 +1936,10 @@ _TextIOWrapper_decoder_setstate(PyTextIOWrapperObject *self,
}
static
int
_TextIOWrapper_encoder_setstate
(
PyTextIOWrapperObject
*
self
,
CookieStruct
*
cookie
)
_textiowrapper_encoder_setstate
(
textio
*
self
,
cookie_type
*
cookie
)
{
PyObject
*
res
;
/* Same as _
TextIOW
rapper_decoder_setstate() above. */
/* Same as _
textiow
rapper_decoder_setstate() above. */
if
(
cookie
->
start_pos
==
0
&&
cookie
->
dec_flags
==
0
)
{
res
=
PyObject_CallMethodObjArgs
(
self
->
encoder
,
_PyIO_str_reset
,
NULL
);
self
->
encoding_start_of_stream
=
1
;
...
...
@@ -1958,10 +1956,10 @@ _TextIOWrapper_encoder_setstate(PyTextIOWrapperObject *self,
}
static
PyObject
*
TextIOWrapper_seek
(
PyTextIOWrapperObject
*
self
,
PyObject
*
args
)
textiowrapper_seek
(
textio
*
self
,
PyObject
*
args
)
{
PyObject
*
cookieObj
,
*
posobj
;
CookieStruct
cookie
;
cookie_type
cookie
;
int
whence
=
0
;
PyObject
*
res
;
int
cmp
;
...
...
@@ -2018,7 +2016,7 @@ TextIOWrapper_seek(PyTextIOWrapperObject *self, PyObject *args)
goto
fail
;
Py_DECREF
(
res
);
TextIOW
rapper_set_decoded_chars
(
self
,
NULL
);
textiow
rapper_set_decoded_chars
(
self
,
NULL
);
Py_CLEAR
(
self
->
snapshot
);
if
(
self
->
decoder
)
{
res
=
PyObject_CallMethod
(
self
->
decoder
,
"reset"
,
NULL
);
...
...
@@ -2055,7 +2053,7 @@ TextIOWrapper_seek(PyTextIOWrapperObject *self, PyObject *args)
/* The strategy of seek() is to go back to the safe start point
* and replay the effect of read(chars_to_skip) from there.
*/
if
(
TextIOWrapper_parseC
ookie
(
&
cookie
,
cookieObj
)
<
0
)
if
(
textiowrapper_parse_c
ookie
(
&
cookie
,
cookieObj
)
<
0
)
goto
fail
;
/* Seek back to the safe start point. */
...
...
@@ -2069,12 +2067,12 @@ TextIOWrapper_seek(PyTextIOWrapperObject *self, PyObject *args)
goto
fail
;
Py_DECREF
(
res
);
TextIOW
rapper_set_decoded_chars
(
self
,
NULL
);
textiow
rapper_set_decoded_chars
(
self
,
NULL
);
Py_CLEAR
(
self
->
snapshot
);
/* Restore the decoder to its state from the safe start point. */
if
(
self
->
decoder
)
{
if
(
_
TextIOW
rapper_decoder_setstate
(
self
,
&
cookie
)
<
0
)
if
(
_
textiow
rapper_decoder_setstate
(
self
,
&
cookie
)
<
0
)
goto
fail
;
}
...
...
@@ -2101,7 +2099,7 @@ TextIOWrapper_seek(PyTextIOWrapperObject *self, PyObject *args)
if
(
decoded
==
NULL
)
goto
fail
;
TextIOW
rapper_set_decoded_chars
(
self
,
decoded
);
textiow
rapper_set_decoded_chars
(
self
,
decoded
);
/* Skip chars_to_skip of the decoded characters. */
if
(
PyUnicode_GetSize
(
self
->
decoded_chars
)
<
cookie
.
chars_to_skip
)
{
...
...
@@ -2118,7 +2116,7 @@ TextIOWrapper_seek(PyTextIOWrapperObject *self, PyObject *args)
/* Finally, reset the encoder (merely useful for proper BOM handling) */
if
(
self
->
encoder
)
{
if
(
_
TextIOW
rapper_encoder_setstate
(
self
,
&
cookie
)
<
0
)
if
(
_
textiow
rapper_encoder_setstate
(
self
,
&
cookie
)
<
0
)
goto
fail
;
}
return
cookieObj
;
...
...
@@ -2129,11 +2127,11 @@ TextIOWrapper_seek(PyTextIOWrapperObject *self, PyObject *args)
}
static
PyObject
*
TextIOWrapper_tell
(
PyTextIOWrapperObject
*
self
,
PyObject
*
args
)
textiowrapper_tell
(
textio
*
self
,
PyObject
*
args
)
{
PyObject
*
res
;
PyObject
*
posobj
=
NULL
;
CookieStruct
cookie
=
{
0
,
0
,
0
,
0
,
0
};
cookie_type
cookie
=
{
0
,
0
,
0
,
0
,
0
};
PyObject
*
next_input
;
Py_ssize_t
chars_to_skip
,
chars_decoded
;
PyObject
*
saved_state
=
NULL
;
...
...
@@ -2153,7 +2151,7 @@ TextIOWrapper_tell(PyTextIOWrapperObject *self, PyObject *args)
goto
fail
;
}
if
(
_
TextIOW
rapper_writeflush
(
self
)
<
0
)
if
(
_
textiow
rapper_writeflush
(
self
)
<
0
)
return
NULL
;
res
=
PyObject_CallMethod
((
PyObject
*
)
self
,
"flush"
,
NULL
);
if
(
res
==
NULL
)
...
...
@@ -2189,7 +2187,7 @@ TextIOWrapper_tell(PyTextIOWrapperObject *self, PyObject *args)
if
(
self
->
decoded_chars_used
==
0
)
{
/* We haven't moved from the snapshot point. */
Py_DECREF
(
posobj
);
return
TextIOWrapper_buildC
ookie
(
&
cookie
);
return
textiowrapper_build_c
ookie
(
&
cookie
);
}
chars_to_skip
=
self
->
decoded_chars_used
;
...
...
@@ -2203,7 +2201,7 @@ TextIOWrapper_tell(PyTextIOWrapperObject *self, PyObject *args)
goto
fail
;
/* Note our initial start point. */
if
(
_
TextIOW
rapper_decoder_setstate
(
self
,
&
cookie
)
<
0
)
if
(
_
textiow
rapper_decoder_setstate
(
self
,
&
cookie
)
<
0
)
goto
fail
;
/* Feed the decoder one byte at a time. As we go, note the
...
...
@@ -2280,7 +2278,7 @@ TextIOWrapper_tell(PyTextIOWrapperObject *self, PyObject *args)
/* The returned cookie corresponds to the last safe start point. */
cookie
.
chars_to_skip
=
Py_SAFE_DOWNCAST
(
chars_to_skip
,
Py_ssize_t
,
int
);
return
TextIOWrapper_buildC
ookie
(
&
cookie
);
return
textiowrapper_build_c
ookie
(
&
cookie
);
fail:
Py_XDECREF
(
posobj
);
...
...
@@ -2300,7 +2298,7 @@ TextIOWrapper_tell(PyTextIOWrapperObject *self, PyObject *args)
}
static
PyObject
*
TextIOWrapper_truncate
(
PyTextIOWrapperObject
*
self
,
PyObject
*
args
)
textiowrapper_truncate
(
textio
*
self
,
PyObject
*
args
)
{
PyObject
*
pos
=
Py_None
;
PyObject
*
res
;
...
...
@@ -2327,7 +2325,7 @@ TextIOWrapper_truncate(PyTextIOWrapperObject *self, PyObject *args)
}
static
PyObject
*
TextIOWrapper_repr
(
PyTextIOWrapperObject
*
self
)
textiowrapper_repr
(
textio
*
self
)
{
PyObject
*
nameobj
,
*
res
;
...
...
@@ -2354,53 +2352,53 @@ TextIOWrapper_repr(PyTextIOWrapperObject *self)
/* Inquiries */
static
PyObject
*
TextIOWrapper_fileno
(
PyTextIOWrapperObject
*
self
,
PyObject
*
args
)
textiowrapper_fileno
(
textio
*
self
,
PyObject
*
args
)
{
CHECK_INITIALIZED
(
self
);
return
PyObject_CallMethod
(
self
->
buffer
,
"fileno"
,
NULL
);
}
static
PyObject
*
TextIOWrapper_seekable
(
PyTextIOWrapperObject
*
self
,
PyObject
*
args
)
textiowrapper_seekable
(
textio
*
self
,
PyObject
*
args
)
{
CHECK_INITIALIZED
(
self
);
return
PyObject_CallMethod
(
self
->
buffer
,
"seekable"
,
NULL
);
}
static
PyObject
*
TextIOWrapper_readable
(
PyTextIOWrapperObject
*
self
,
PyObject
*
args
)
textiowrapper_readable
(
textio
*
self
,
PyObject
*
args
)
{
CHECK_INITIALIZED
(
self
);
return
PyObject_CallMethod
(
self
->
buffer
,
"readable"
,
NULL
);
}
static
PyObject
*
TextIOWrapper_writable
(
PyTextIOWrapperObject
*
self
,
PyObject
*
args
)
textiowrapper_writable
(
textio
*
self
,
PyObject
*
args
)
{
CHECK_INITIALIZED
(
self
);
return
PyObject_CallMethod
(
self
->
buffer
,
"writable"
,
NULL
);
}
static
PyObject
*
TextIOWrapper_isatty
(
PyTextIOWrapperObject
*
self
,
PyObject
*
args
)
textiowrapper_isatty
(
textio
*
self
,
PyObject
*
args
)
{
CHECK_INITIALIZED
(
self
);
return
PyObject_CallMethod
(
self
->
buffer
,
"isatty"
,
NULL
);
}
static
PyObject
*
TextIOWrapper_flush
(
PyTextIOWrapperObject
*
self
,
PyObject
*
args
)
textiowrapper_flush
(
textio
*
self
,
PyObject
*
args
)
{
CHECK_INITIALIZED
(
self
);
CHECK_CLOSED
(
self
);
self
->
telling
=
self
->
seekable
;
if
(
_
TextIOW
rapper_writeflush
(
self
)
<
0
)
if
(
_
textiow
rapper_writeflush
(
self
)
<
0
)
return
NULL
;
return
PyObject_CallMethod
(
self
->
buffer
,
"flush"
,
NULL
);
}
static
PyObject
*
TextIOWrapper_close
(
PyTextIOWrapperObject
*
self
,
PyObject
*
args
)
textiowrapper_close
(
textio
*
self
,
PyObject
*
args
)
{
PyObject
*
res
;
CHECK_INITIALIZED
(
self
);
...
...
@@ -2416,7 +2414,7 @@ TextIOWrapper_close(PyTextIOWrapperObject *self, PyObject *args)
}
static
PyObject
*
TextIOWrapper_iternext
(
PyTextIOWrapperObject
*
self
)
textiowrapper_iternext
(
textio
*
self
)
{
PyObject
*
line
;
...
...
@@ -2425,7 +2423,7 @@ TextIOWrapper_iternext(PyTextIOWrapperObject *self)
self
->
telling
=
0
;
if
(
Py_TYPE
(
self
)
==
&
PyTextIOWrapper_Type
)
{
/* Skip method call overhead for speed */
line
=
_
TextIOW
rapper_readline
(
self
,
-
1
);
line
=
_
textiow
rapper_readline
(
self
,
-
1
);
}
else
{
line
=
PyObject_CallMethodObjArgs
((
PyObject
*
)
self
,
...
...
@@ -2454,21 +2452,21 @@ TextIOWrapper_iternext(PyTextIOWrapperObject *self)
}
static
PyObject
*
TextIOWrapper_name_get
(
PyTextIOWrapperObject
*
self
,
void
*
context
)
textiowrapper_name_get
(
textio
*
self
,
void
*
context
)
{
CHECK_INITIALIZED
(
self
);
return
PyObject_GetAttrString
(
self
->
buffer
,
"name"
);
}
static
PyObject
*
TextIOWrapper_closed_get
(
PyTextIOWrapperObject
*
self
,
void
*
context
)
textiowrapper_closed_get
(
textio
*
self
,
void
*
context
)
{
CHECK_INITIALIZED
(
self
);
return
PyObject_GetAttr
(
self
->
buffer
,
_PyIO_str_closed
);
}
static
PyObject
*
TextIOWrapper_newlines_get
(
PyTextIOWrapperObject
*
self
,
void
*
context
)
textiowrapper_newlines_get
(
textio
*
self
,
void
*
context
)
{
PyObject
*
res
;
CHECK_INITIALIZED
(
self
);
...
...
@@ -2488,22 +2486,21 @@ TextIOWrapper_newlines_get(PyTextIOWrapperObject *self, void *context)
}
static
PyObject
*
TextIOWrapper_errors_get
(
PyTextIOWrapperObject
*
self
,
void
*
context
)
textiowrapper_errors_get
(
textio
*
self
,
void
*
context
)
{
CHECK_INITIALIZED
(
self
);
return
PyUnicode_FromString
(
PyBytes_AS_STRING
(
self
->
errors
));
}
static
PyObject
*
TextIOWrapper_chunk_size_get
(
PyTextIOWrapperObject
*
self
,
void
*
context
)
textiowrapper_chunk_size_get
(
textio
*
self
,
void
*
context
)
{
CHECK_INITIALIZED
(
self
);
return
PyLong_FromSsize_t
(
self
->
chunk_size
);
}
static
int
TextIOWrapper_chunk_size_set
(
PyTextIOWrapperObject
*
self
,
PyObject
*
arg
,
void
*
context
)
textiowrapper_chunk_size_set
(
textio
*
self
,
PyObject
*
arg
,
void
*
context
)
{
Py_ssize_t
n
;
CHECK_INITIALIZED_INT
(
self
);
...
...
@@ -2519,56 +2516,56 @@ TextIOWrapper_chunk_size_set(PyTextIOWrapperObject *self,
return
0
;
}
static
PyMethodDef
TextIOW
rapper_methods
[]
=
{
{
"detach"
,
(
PyCFunction
)
TextIOW
rapper_detach
,
METH_NOARGS
},
{
"write"
,
(
PyCFunction
)
TextIOW
rapper_write
,
METH_VARARGS
},
{
"read"
,
(
PyCFunction
)
TextIOW
rapper_read
,
METH_VARARGS
},
{
"readline"
,
(
PyCFunction
)
TextIOW
rapper_readline
,
METH_VARARGS
},
{
"flush"
,
(
PyCFunction
)
TextIOW
rapper_flush
,
METH_NOARGS
},
{
"close"
,
(
PyCFunction
)
TextIOW
rapper_close
,
METH_NOARGS
},
static
PyMethodDef
textiow
rapper_methods
[]
=
{
{
"detach"
,
(
PyCFunction
)
textiow
rapper_detach
,
METH_NOARGS
},
{
"write"
,
(
PyCFunction
)
textiow
rapper_write
,
METH_VARARGS
},
{
"read"
,
(
PyCFunction
)
textiow
rapper_read
,
METH_VARARGS
},
{
"readline"
,
(
PyCFunction
)
textiow
rapper_readline
,
METH_VARARGS
},
{
"flush"
,
(
PyCFunction
)
textiow
rapper_flush
,
METH_NOARGS
},
{
"close"
,
(
PyCFunction
)
textiow
rapper_close
,
METH_NOARGS
},
{
"fileno"
,
(
PyCFunction
)
TextIOW
rapper_fileno
,
METH_NOARGS
},
{
"seekable"
,
(
PyCFunction
)
TextIOW
rapper_seekable
,
METH_NOARGS
},
{
"readable"
,
(
PyCFunction
)
TextIOW
rapper_readable
,
METH_NOARGS
},
{
"writable"
,
(
PyCFunction
)
TextIOW
rapper_writable
,
METH_NOARGS
},
{
"isatty"
,
(
PyCFunction
)
TextIOW
rapper_isatty
,
METH_NOARGS
},
{
"fileno"
,
(
PyCFunction
)
textiow
rapper_fileno
,
METH_NOARGS
},
{
"seekable"
,
(
PyCFunction
)
textiow
rapper_seekable
,
METH_NOARGS
},
{
"readable"
,
(
PyCFunction
)
textiow
rapper_readable
,
METH_NOARGS
},
{
"writable"
,
(
PyCFunction
)
textiow
rapper_writable
,
METH_NOARGS
},
{
"isatty"
,
(
PyCFunction
)
textiow
rapper_isatty
,
METH_NOARGS
},
{
"seek"
,
(
PyCFunction
)
TextIOW
rapper_seek
,
METH_VARARGS
},
{
"tell"
,
(
PyCFunction
)
TextIOW
rapper_tell
,
METH_NOARGS
},
{
"truncate"
,
(
PyCFunction
)
TextIOW
rapper_truncate
,
METH_VARARGS
},
{
"seek"
,
(
PyCFunction
)
textiow
rapper_seek
,
METH_VARARGS
},
{
"tell"
,
(
PyCFunction
)
textiow
rapper_tell
,
METH_NOARGS
},
{
"truncate"
,
(
PyCFunction
)
textiow
rapper_truncate
,
METH_VARARGS
},
{
NULL
,
NULL
}
};
static
PyMemberDef
TextIOW
rapper_members
[]
=
{
{
"encoding"
,
T_OBJECT
,
offsetof
(
PyTextIOWrapperObject
,
encoding
),
READONLY
},
{
"buffer"
,
T_OBJECT
,
offsetof
(
PyTextIOWrapperObject
,
buffer
),
READONLY
},
{
"line_buffering"
,
T_BOOL
,
offsetof
(
PyTextIOWrapperObject
,
line_buffering
),
READONLY
},
static
PyMemberDef
textiow
rapper_members
[]
=
{
{
"encoding"
,
T_OBJECT
,
offsetof
(
textio
,
encoding
),
READONLY
},
{
"buffer"
,
T_OBJECT
,
offsetof
(
textio
,
buffer
),
READONLY
},
{
"line_buffering"
,
T_BOOL
,
offsetof
(
textio
,
line_buffering
),
READONLY
},
{
NULL
}
};
static
PyGetSetDef
TextIOW
rapper_getset
[]
=
{
{
"name"
,
(
getter
)
TextIOW
rapper_name_get
,
NULL
,
NULL
},
{
"closed"
,
(
getter
)
TextIOW
rapper_closed_get
,
NULL
,
NULL
},
static
PyGetSetDef
textiow
rapper_getset
[]
=
{
{
"name"
,
(
getter
)
textiow
rapper_name_get
,
NULL
,
NULL
},
{
"closed"
,
(
getter
)
textiow
rapper_closed_get
,
NULL
,
NULL
},
/* {"mode", (getter)TextIOWrapper_mode_get, NULL, NULL},
*/
{
"newlines"
,
(
getter
)
TextIOW
rapper_newlines_get
,
NULL
,
NULL
},
{
"errors"
,
(
getter
)
TextIOW
rapper_errors_get
,
NULL
,
NULL
},
{
"_CHUNK_SIZE"
,
(
getter
)
TextIOW
rapper_chunk_size_get
,
(
setter
)
TextIOW
rapper_chunk_size_set
,
NULL
},
{
"newlines"
,
(
getter
)
textiow
rapper_newlines_get
,
NULL
,
NULL
},
{
"errors"
,
(
getter
)
textiow
rapper_errors_get
,
NULL
,
NULL
},
{
"_CHUNK_SIZE"
,
(
getter
)
textiow
rapper_chunk_size_get
,
(
setter
)
textiow
rapper_chunk_size_set
,
NULL
},
{
NULL
}
};
PyTypeObject
PyTextIOWrapper_Type
=
{
PyVarObject_HEAD_INIT
(
NULL
,
0
)
"_io.TextIOWrapper"
,
/*tp_name*/
sizeof
(
PyTextIOWrapperObject
),
/*tp_basicsize*/
sizeof
(
textio
),
/*tp_basicsize*/
0
,
/*tp_itemsize*/
(
destructor
)
TextIOW
rapper_dealloc
,
/*tp_dealloc*/
(
destructor
)
textiow
rapper_dealloc
,
/*tp_dealloc*/
0
,
/*tp_print*/
0
,
/*tp_getattr*/
0
,
/*tps_etattr*/
0
,
/*tp_compare */
(
reprfunc
)
TextIOW
rapper_repr
,
/*tp_repr*/
(
reprfunc
)
textiow
rapper_repr
,
/*tp_repr*/
0
,
/*tp_as_number*/
0
,
/*tp_as_sequence*/
0
,
/*tp_as_mapping*/
...
...
@@ -2580,22 +2577,22 @@ PyTypeObject PyTextIOWrapper_Type = {
0
,
/*tp_as_buffer*/
Py_TPFLAGS_DEFAULT
|
Py_TPFLAGS_BASETYPE
|
Py_TPFLAGS_HAVE_GC
,
/*tp_flags*/
TextIOW
rapper_doc
,
/* tp_doc */
(
traverseproc
)
TextIOW
rapper_traverse
,
/* tp_traverse */
(
inquiry
)
TextIOW
rapper_clear
,
/* tp_clear */
textiow
rapper_doc
,
/* tp_doc */
(
traverseproc
)
textiow
rapper_traverse
,
/* tp_traverse */
(
inquiry
)
textiow
rapper_clear
,
/* tp_clear */
0
,
/* tp_richcompare */
offsetof
(
PyTextIOWrapperObject
,
weakreflist
),
/*tp_weaklistoffset*/
offsetof
(
textio
,
weakreflist
),
/*tp_weaklistoffset*/
0
,
/* tp_iter */
(
iternextfunc
)
TextIOW
rapper_iternext
,
/* tp_iternext */
TextIOW
rapper_methods
,
/* tp_methods */
TextIOW
rapper_members
,
/* tp_members */
TextIOW
rapper_getset
,
/* tp_getset */
(
iternextfunc
)
textiow
rapper_iternext
,
/* tp_iternext */
textiow
rapper_methods
,
/* tp_methods */
textiow
rapper_members
,
/* tp_members */
textiow
rapper_getset
,
/* tp_getset */
0
,
/* tp_base */
0
,
/* tp_dict */
0
,
/* tp_descr_get */
0
,
/* tp_descr_set */
offsetof
(
PyTextIOWrapperObject
,
dict
),
/*tp_dictoffset*/
(
initproc
)
TextIOW
rapper_init
,
/* tp_init */
offsetof
(
textio
,
dict
),
/*tp_dictoffset*/
(
initproc
)
textiow
rapper_init
,
/* tp_init */
0
,
/* tp_alloc */
PyType_GenericNew
,
/* tp_new */
};
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment