From ba9c782824ddf479dd5ed76594c0defa1ae88838 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Mon, 25 May 2015 20:43:28 +0200 Subject: [PATCH] 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... --- qutebrowser/utils/qtutils.py | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/qutebrowser/utils/qtutils.py b/qutebrowser/utils/qtutils.py index 4525a5c32..841e94d87 100644 --- a/qutebrowser/utils/qtutils.py +++ b/qutebrowser/utils/qtutils.py @@ -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: - raise OSError(self._dev.errorString()) - return num + 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()) + 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):