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:
parent
fa69786b0f
commit
ba9c782824
@ -311,13 +311,28 @@ class PyQIODevice(io.BufferedIOBase):
|
|||||||
raise OSError(self._dev.errorString())
|
raise OSError(self._dev.errorString())
|
||||||
return num
|
return num
|
||||||
|
|
||||||
def read(self, size):
|
def read(self, size=-1):
|
||||||
self._check_open()
|
self._check_open()
|
||||||
buf = bytes()
|
self._check_readable()
|
||||||
num = self._dev.read(buf, size)
|
if size == 0:
|
||||||
if num == -1:
|
# Read no data
|
||||||
raise OSError(self._dev.errorString())
|
return b''
|
||||||
return num
|
elif size < 0:
|
||||||
|
# Read all data
|
||||||
|
if self._dev.bytesAvailable() > 0:
|
||||||
|
buf = self._dev.readAll()
|
||||||
|
if not buf:
|
||||||
|
raise OSError(self._dev.errorString())
|
||||||
|
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):
|
class QtValueError(ValueError):
|
||||||
|
Loading…
Reference in New Issue
Block a user