Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4fb01ff

Browse files
committed
backout 0fb7789b5eeb for test breakage (#20578)
1 parent eac2194 commit 4fb01ff

5 files changed

Lines changed: 14 additions & 194 deletions

File tree

Doc/library/io.rst

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -385,8 +385,8 @@ I/O Base Classes
385385
.. method:: readinto(b)
386386

387387
Read up to ``len(b)`` bytes into :class:`bytearray` *b* and return the
388-
number of bytes read. If the object is in non-blocking mode and no bytes
389-
are available, ``None`` is returned.
388+
number of bytes read. If the object is in non-blocking mode and no
389+
bytes are available, ``None`` is returned.
390390

391391
.. method:: write(b)
392392

@@ -459,11 +459,10 @@ I/O Base Classes
459459

460460
.. method:: read1(size=-1)
461461

462-
Read and return up to *size* bytes, with at most one call to the
463-
underlying raw stream's :meth:`~RawIOBase.read` (or
464-
:meth:`~RawIOBase.readinto`) method. This can be useful if you
465-
are implementing your own buffering on top of a
466-
:class:`BufferedIOBase` object.
462+
Read and return up to *size* bytes, with at most one call to the underlying
463+
raw stream's :meth:`~RawIOBase.read` method. This can be useful if you
464+
are implementing your own buffering on top of a :class:`BufferedIOBase`
465+
object.
467466

468467
.. method:: readinto(b)
469468

@@ -473,19 +472,8 @@ I/O Base Classes
473472
Like :meth:`read`, multiple reads may be issued to the underlying raw
474473
stream, unless the latter is interactive.
475474

476-
A :exc:`BlockingIOError` is raised if the underlying raw stream is in non
477-
blocking-mode, and has no data available at the moment.
478-
479-
.. method:: readinto1(b)
480-
481-
Read up to ``len(b)`` bytes into bytearray *b*, using at most one call to
482-
the underlying raw stream's :meth:`~RawIOBase.read` (or
483-
:meth:`~RawIOBase.readinto`) method. Return the number of bytes read.
484-
485475
A :exc:`BlockingIOError` is raised if the underlying raw stream is in
486-
non-blocking mode and has no data available at the moment.
487-
488-
.. versionadded:: 3.5
476+
non blocking-mode, and has no data available at the moment.
489477

490478
.. method:: write(b)
491479

@@ -602,11 +590,6 @@ than raw I/O does.
602590

603591
In :class:`BytesIO`, this is the same as :meth:`read`.
604592

605-
.. method:: readinto1()
606-
607-
In :class:`BytesIO`, this is the same as :meth:`readinto`.
608-
609-
.. versionadded:: 3.5
610593

611594
.. class:: BufferedReader(raw, buffer_size=DEFAULT_BUFFER_SIZE)
612595

Lib/_pyio.py

Lines changed: 1 addition & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -655,26 +655,8 @@ def readinto(self, b):
655655
Raises BlockingIOError if the underlying raw stream has no
656656
data at the moment.
657657
"""
658-
659-
return self._readinto(b, read1=False)
660-
661-
def readinto1(self, b):
662-
"""Read up to len(b) bytes into *b*, using at most one system call
663-
664-
Returns an int representing the number of bytes read (0 for EOF).
665-
666-
Raises BlockingIOError if the underlying raw stream has no
667-
data at the moment.
668-
"""
669-
670-
return self._readinto(b, read1=True)
671-
672-
def _readinto(self, b, read1):
673658
# XXX This ought to work with anything that supports the buffer API
674-
if read1:
675-
data = self.read1(len(b))
676-
else:
677-
data = self.read(len(b))
659+
data = self.read(len(b))
678660
n = len(data)
679661
try:
680662
b[:n] = data
@@ -1076,62 +1058,6 @@ def read1(self, size):
10761058
return self._read_unlocked(
10771059
min(size, len(self._read_buf) - self._read_pos))
10781060

1079-
# Implementing readinto() and readinto1() is not strictly necessary (we
1080-
# could rely on the base class that provides an implementation in terms of
1081-
# read() and read1()). We do ai anyway to keep the _pyio implementation
1082-
# similar to the io implementation (which implements the methods for
1083-
# performance reasons).
1084-
def readinto(self, buf):
1085-
"""Read data into *buf*."""
1086-
return self._readinto(buf, read1=False)
1087-
def readinto1(self, buf):
1088-
"""Read data into *buf* with at most one system call."""
1089-
return self._readinto(buf, read1=True)
1090-
1091-
def _readinto(self, buf, read1):
1092-
"""Read data into *buf* with at most one system call."""
1093-
1094-
if len(buf) == 0:
1095-
return 0
1096-
1097-
written = 0
1098-
with self._read_lock:
1099-
while written < len(buf):
1100-
1101-
# First try to read from internal buffer
1102-
avail = min(len(self._read_buf) - self._read_pos, len(buf))
1103-
if avail:
1104-
buf[written:written+avail] = \
1105-
self._read_buf[self._read_pos:self._read_pos+avail]
1106-
self._read_pos += avail
1107-
written += avail
1108-
if written == len(buf):
1109-
break
1110-
1111-
# If remaining space in callers buffer is larger than
1112-
# internal buffer, read directly into callers buffer
1113-
if len(buf) - written > self.buffer_size:
1114-
# If we don't use a memoryview, slicing buf will create
1115-
# a new object
1116-
if not isinstance(buf, memoryview):
1117-
buf = memoryview(buf)
1118-
n = self.raw.readinto(buf[written:])
1119-
if not n:
1120-
break # eof
1121-
written += n
1122-
1123-
# Otherwise refill internal buffer - unless we're
1124-
# in read1 mode and already got some data
1125-
elif not (read1 and written):
1126-
if not self._peek_unlocked(1):
1127-
break # eof
1128-
1129-
# In readinto1 mode, return as soon as we have some data
1130-
if read1 and written:
1131-
break
1132-
1133-
return written
1134-
11351061
def tell(self):
11361062
return _BufferedIOMixin.tell(self) - len(self._read_buf) + self._read_pos
11371063

@@ -1281,9 +1207,6 @@ def peek(self, size=0):
12811207
def read1(self, size):
12821208
return self.reader.read1(size)
12831209

1284-
def readinto1(self, b):
1285-
return self.reader.readinto1(b)
1286-
12871210
def readable(self):
12881211
return self.reader.readable()
12891212

@@ -1366,10 +1289,6 @@ def read1(self, size):
13661289
self.flush()
13671290
return BufferedReader.read1(self, size)
13681291

1369-
def readinto1(self, b):
1370-
self.flush()
1371-
return BufferedReader.readinto1(self, b)
1372-
13731292
def write(self, b):
13741293
if self._read_buf:
13751294
# Undo readahead

Lib/test/test_io.py

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -911,29 +911,6 @@ def test_readinto(self):
911911
self.assertEqual(bufio.readinto(b), 1)
912912
self.assertEqual(b, b"cb")
913913

914-
def test_readinto1(self):
915-
buffer_size = 10
916-
rawio = self.MockRawIO((b"abc", b"de", b"fgh", b"jkl"))
917-
bufio = self.tp(rawio, buffer_size=buffer_size)
918-
b = bytearray(2)
919-
self.assertEqual(bufio.peek(3), b'abc')
920-
self.assertEqual(rawio._reads, 1)
921-
self.assertEqual(bufio.readinto1(b), 2)
922-
self.assertEqual(b, b"ab")
923-
self.assertEqual(rawio._reads, 1)
924-
self.assertEqual(bufio.readinto1(b), 1)
925-
self.assertEqual(b[:1], b"c")
926-
self.assertEqual(rawio._reads, 1)
927-
self.assertEqual(bufio.readinto1(b), 2)
928-
self.assertEqual(b, b"de")
929-
self.assertEqual(rawio._reads, 2)
930-
b = bytearray(2*buffer_size)
931-
self.assertEqual(bufio.peek(3), b'fgh')
932-
self.assertEqual(rawio._reads, 3)
933-
self.assertEqual(bufio.readinto1(b), 6)
934-
self.assertEqual(b[:6], b"fghjkl")
935-
self.assertEqual(rawio._reads, 4)
936-
937914
def test_readlines(self):
938915
def bufio():
939916
rawio = self.MockRawIO((b"abc\n", b"d\n", b"ef"))
@@ -3008,8 +2985,6 @@ def test_io_after_close(self):
30082985
self.assertRaises(ValueError, f.readall)
30092986
if hasattr(f, "readinto"):
30102987
self.assertRaises(ValueError, f.readinto, bytearray(1024))
3011-
if hasattr(f, "readinto1"):
3012-
self.assertRaises(ValueError, f.readinto1, bytearray(1024))
30132988
self.assertRaises(ValueError, f.readline)
30142989
self.assertRaises(ValueError, f.readlines)
30152990
self.assertRaises(ValueError, f.seek, 0)

Misc/NEWS

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,6 @@ Core and Builtins
9292
Library
9393
-------
9494

95-
- Issue #20578: Add io.BufferedIOBase.readinto1.
96-
9795
- Issue #11709: Fix the pydoc.help function to not fail when sys.stdin is not a
9896
valid file.
9997

Modules/_io/bufferedio.c

Lines changed: 6 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ _Py_IDENTIFIER(read);
2424
_Py_IDENTIFIER(read1);
2525
_Py_IDENTIFIER(readable);
2626
_Py_IDENTIFIER(readinto);
27-
_Py_IDENTIFIER(readinto1);
2827
_Py_IDENTIFIER(writable);
2928
_Py_IDENTIFIER(write);
3029

@@ -48,21 +47,17 @@ PyDoc_STRVAR(bufferediobase_doc,
4847
);
4948

5049
static PyObject *
51-
_bufferediobase_readinto_generic(PyObject *self, PyObject *args, char readinto1)
50+
bufferediobase_readinto(PyObject *self, PyObject *args)
5251
{
5352
Py_buffer buf;
5453
Py_ssize_t len;
5554
PyObject *data;
5655

57-
if (!PyArg_ParseTuple(args,
58-
readinto1 ? "w*:readinto1" : "w*:readinto",
59-
&buf)) {
56+
if (!PyArg_ParseTuple(args, "w*:readinto", &buf)) {
6057
return NULL;
6158
}
6259

63-
data = _PyObject_CallMethodId(self,
64-
readinto1 ? &PyId_read1 : &PyId_read,
65-
"n", buf.len);
60+
data = _PyObject_CallMethodId(self, &PyId_read, "n", buf.len);
6661
if (data == NULL)
6762
goto error;
6863

@@ -93,18 +88,6 @@ _bufferediobase_readinto_generic(PyObject *self, PyObject *args, char readinto1)
9388
return NULL;
9489
}
9590

96-
static PyObject *
97-
bufferediobase_readinto(PyObject *self, PyObject *args)
98-
{
99-
return _bufferediobase_readinto_generic(self, args, 0);
100-
}
101-
102-
static PyObject *
103-
bufferediobase_readinto1(PyObject *self, PyObject *args)
104-
{
105-
return _bufferediobase_readinto_generic(self, args, 1);
106-
}
107-
10891
static PyObject *
10992
bufferediobase_unsupported(const char *message)
11093
{
@@ -184,7 +167,6 @@ static PyMethodDef bufferediobase_methods[] = {
184167
{"read", bufferediobase_read, METH_VARARGS, bufferediobase_read_doc},
185168
{"read1", bufferediobase_read1, METH_VARARGS, bufferediobase_read1_doc},
186169
{"readinto", bufferediobase_readinto, METH_VARARGS, NULL},
187-
{"readinto1", bufferediobase_readinto1, METH_VARARGS, NULL},
188170
{"write", bufferediobase_write, METH_VARARGS, bufferediobase_write_doc},
189171
{NULL, NULL}
190172
};
@@ -1006,17 +988,15 @@ buffered_read1(buffered *self, PyObject *args)
1006988
}
1007989

1008990
static PyObject *
1009-
_buffered_readinto_generic(buffered *self, PyObject *args, char readinto1)
991+
buffered_readinto(buffered *self, PyObject *args)
1010992
{
1011993
Py_buffer buf;
1012994
Py_ssize_t n, written = 0, remaining;
1013995
PyObject *res = NULL;
1014996

1015997
CHECK_INITIALIZED(self)
1016998

1017-
if (!PyArg_ParseTuple(args,
1018-
readinto1 ? "w*:readinto1" : "w*:readinto",
1019-
&buf))
999+
if (!PyArg_ParseTuple(args, "w*:readinto", &buf))
10201000
return NULL;
10211001

10221002
n = Py_SAFE_DOWNCAST(READAHEAD(self), Py_off_t, Py_ssize_t);
@@ -1054,10 +1034,7 @@ _buffered_readinto_generic(buffered *self, PyObject *args, char readinto1)
10541034
n = _bufferedreader_raw_read(self, (char *) buf.buf + written,
10551035
remaining);
10561036
}
1057-
1058-
/* In readinto1 mode, we do not want to fill the internal
1059-
buffer if we already have some data to return */
1060-
else if (!(readinto1 && written)) {
1037+
else {
10611038
n = _bufferedreader_fill_buffer(self);
10621039
if (n > 0) {
10631040
if (n > remaining)
@@ -1068,10 +1045,6 @@ _buffered_readinto_generic(buffered *self, PyObject *args, char readinto1)
10681045
continue; /* short circuit */
10691046
}
10701047
}
1071-
else {
1072-
n = 0;
1073-
}
1074-
10751048
if (n == 0 || (n == -2 && written > 0))
10761049
break;
10771050
if (n < 0) {
@@ -1081,12 +1054,6 @@ _buffered_readinto_generic(buffered *self, PyObject *args, char readinto1)
10811054
}
10821055
goto end;
10831056
}
1084-
1085-
/* At most one read in readinto1 mode */
1086-
if (readinto1) {
1087-
written += n;
1088-
break;
1089-
}
10901057
}
10911058
res = PyLong_FromSsize_t(written);
10921059

@@ -1097,19 +1064,6 @@ _buffered_readinto_generic(buffered *self, PyObject *args, char readinto1)
10971064
return res;
10981065
}
10991066

1100-
static PyObject *
1101-
buffered_readinto(buffered *self, PyObject *args)
1102-
{
1103-
return _buffered_readinto_generic(self, args, 0);
1104-
}
1105-
1106-
static PyObject *
1107-
buffered_readinto1(buffered *self, PyObject *args)
1108-
{
1109-
return _buffered_readinto_generic(self, args, 1);
1110-
}
1111-
1112-
11131067
static PyObject *
11141068
_buffered_readline(buffered *self, Py_ssize_t limit)
11151069
{
@@ -1795,7 +1749,6 @@ static PyMethodDef bufferedreader_methods[] = {
17951749
{"peek", (PyCFunction)buffered_peek, METH_VARARGS},
17961750
{"read1", (PyCFunction)buffered_read1, METH_VARARGS},
17971751
{"readinto", (PyCFunction)buffered_readinto, METH_VARARGS},
1798-
{"readinto1", (PyCFunction)buffered_readinto1, METH_VARARGS},
17991752
{"readline", (PyCFunction)buffered_readline, METH_VARARGS},
18001753
{"seek", (PyCFunction)buffered_seek, METH_VARARGS},
18011754
{"tell", (PyCFunction)buffered_tell, METH_NOARGS},
@@ -2394,12 +2347,6 @@ bufferedrwpair_readinto(rwpair *self, PyObject *args)
23942347
return _forward_call(self->reader, &PyId_readinto, args);
23952348
}
23962349

2397-
static PyObject *
2398-
bufferedrwpair_readinto1(rwpair *self, PyObject *args)
2399-
{
2400-
return _forward_call(self->reader, &PyId_readinto1, args);
2401-
}
2402-
24032350
static PyObject *
24042351
bufferedrwpair_write(rwpair *self, PyObject *args)
24052352
{
@@ -2465,7 +2412,6 @@ static PyMethodDef bufferedrwpair_methods[] = {
24652412
{"peek", (PyCFunction)bufferedrwpair_peek, METH_VARARGS},
24662413
{"read1", (PyCFunction)bufferedrwpair_read1, METH_VARARGS},
24672414
{"readinto", (PyCFunction)bufferedrwpair_readinto, METH_VARARGS},
2468-
{"readinto1", (PyCFunction)bufferedrwpair_readinto1, METH_VARARGS},
24692415

24702416
{"write", (PyCFunction)bufferedrwpair_write, METH_VARARGS},
24712417
{"flush", (PyCFunction)bufferedrwpair_flush, METH_NOARGS},
@@ -2614,7 +2560,6 @@ static PyMethodDef bufferedrandom_methods[] = {
26142560
{"read", (PyCFunction)buffered_read, METH_VARARGS},
26152561
{"read1", (PyCFunction)buffered_read1, METH_VARARGS},
26162562
{"readinto", (PyCFunction)buffered_readinto, METH_VARARGS},
2617-
{"readinto1", (PyCFunction)buffered_readinto1, METH_VARARGS},
26182563
{"readline", (PyCFunction)buffered_readline, METH_VARARGS},
26192564
{"peek", (PyCFunction)buffered_peek, METH_VARARGS},
26202565
{"write", (PyCFunction)bufferedwriter_write, METH_VARARGS},

0 commit comments

Comments
 (0)