PyQIODevice: First attempt at fixing read().

This was completely broken because one read overload doesn't exist in PyQt and
apparently it was never tested...
This commit is contained in:
Florian Bruhin 2015-05-25 20:43:28 +02:00
parent fa69786b0f
commit ba9c782824

View File

@ -311,13 +311,28 @@ class PyQIODevice(io.BufferedIOBase):
raise OSError(self._dev.errorString())
return num
def read(self, size):
def read(self, size=-1):
self._check_open()
buf = bytes()
num = self._dev.read(buf, size)
if num == -1:
self._check_readable()
if size == 0:
# Read no data
return b''
elif size < 0:
# Read all data
if self._dev.bytesAvailable() > 0:
buf = self._dev.readAll()
if not buf:
raise OSError(self._dev.errorString())
return num
else:
return b''
else:
if self._dev.bytesAvailable() > 0:
buf = self._dev.read(size)
if not buf:
raise OSError(self._dev.errorString())
else:
return b''
return buf
class QtValueError(ValueError):