Skip to content

Commit 78643f0

Browse files
committed
Add conditional code for platforms without os.readv
1 parent b4c985a commit 78643f0

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

Lib/_pyio.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1695,12 +1695,18 @@ def readall(self):
16951695
def readinto(self, b):
16961696
"""Same as RawIOBase.readinto()."""
16971697
m = memoryview(b).cast('B')
1698-
self._checkClosed()
1699-
self._checkReadable()
1700-
try:
1701-
return os.readv(self._fd, (m, ))
1702-
except BlockingIOError:
1703-
return None
1698+
if hasattr(os, 'readv'):
1699+
self._checkClosed()
1700+
self._checkReadable()
1701+
try:
1702+
return os.readv(self._fd, (m, ))
1703+
except BlockingIOError:
1704+
return None
1705+
else:
1706+
data = self.read(len(m))
1707+
n = len(data)
1708+
m[:n] = data
1709+
return n
17041710

17051711
def write(self, b):
17061712
"""Write bytes b to file, return number written.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Change ``_pyio.FileIO.readinto`` to use :func:`os.readv` avoiding a copy that was present when using :func:`os.read`
1+
Change ``_pyio.FileIO.readinto`` to use :func:`os.readv` avoiding a copy that was present when using :func:`os.read` on platforms with :func:`os.readv`

0 commit comments

Comments
 (0)