From ea76bdfb0fd11bfe7e48be2ec6eda5a19367642d Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Wed, 10 Dec 2014 16:48:23 +0100 Subject: [PATCH] Replace all IOError by OSErrors. Starting with Python 3.3, IOError is just an alias for OSError. --- qutebrowser/browser/adblock.py | 2 +- qutebrowser/browser/downloads.py | 4 ++-- qutebrowser/network/qutescheme.py | 2 +- qutebrowser/utils/qtutils.py | 22 +++++++++++----------- qutebrowser/utils/version.py | 2 +- scripts/hostblock_blame.py | 2 +- scripts/run_checks.py | 2 +- 7 files changed, 18 insertions(+), 18 deletions(-) diff --git a/qutebrowser/browser/adblock.py b/qutebrowser/browser/adblock.py index 1e48adf2f..6aa7ca548 100644 --- a/qutebrowser/browser/adblock.py +++ b/qutebrowser/browser/adblock.py @@ -196,7 +196,7 @@ class HostBlocker: if urls is None: try: os.remove(self._hosts_file) - except IOError: + except OSError: log.misc.exception("Failed to delete hosts file.") def on_download_finished(self, download): diff --git a/qutebrowser/browser/downloads.py b/qutebrowser/browser/downloads.py index 1c06c8b9b..9a3a78ab4 100644 --- a/qutebrowser/browser/downloads.py +++ b/qutebrowser/browser/downloads.py @@ -421,7 +421,7 @@ class DownloadItem(QObject): # qute:log for example). return if not self.reply.isOpen(): - raise IOError("Reply is closed!") + raise OSError("Reply is closed!") try: self.fileobj.write(self.reply.readAll()) except OSError as e: @@ -439,7 +439,7 @@ class DownloadItem(QObject): def on_read_timer_timeout(self): """Read some bytes from the QNetworkReply periodically.""" if not self.reply.isOpen(): - raise IOError("Reply is closed!") + raise OSError("Reply is closed!") data = self.reply.read(1024) self._buffer.write(data) diff --git a/qutebrowser/network/qutescheme.py b/qutebrowser/network/qutescheme.py index 30d7932d3..12c3c27d9 100644 --- a/qutebrowser/network/qutescheme.py +++ b/qutebrowser/network/qutescheme.py @@ -73,7 +73,7 @@ class QuteSchemeHandler(schemehandler.SchemeHandler): self.parent()) try: data = handler(self._win_id, request) - except IOError as e: + except OSError as e: return networkreply.ErrorNetworkReply( request, str(e), QNetworkReply.ContentNotFoundError, self.parent()) diff --git a/qutebrowser/utils/qtutils.py b/qutebrowser/utils/qtutils.py index 950e74438..e56e95fb0 100644 --- a/qutebrowser/utils/qtutils.py +++ b/qutebrowser/utils/qtutils.py @@ -128,7 +128,7 @@ def ensure_valid(obj): def _check_qdatastream(stream): - """Check the status of a QDataStream and raise IOError if it's not ok.""" + """Check the status of a QDataStream and raise OSError if it's not ok.""" status_to_str = { QDataStream.Ok: "The data stream is operating normally.", QDataStream.ReadPastEnd: ("The data stream has read past the end of " @@ -138,7 +138,7 @@ def _check_qdatastream(stream): "underlying device."), } if stream.status() != QDataStream.Ok: - raise IOError(status_to_str[stream.status()]) + raise OSError(status_to_str[stream.status()]) def serialize(obj): @@ -164,7 +164,7 @@ def savefile_open(filename, binary=False, encoding='utf-8'): try: ok = f.open(QIODevice.WriteOnly) if not ok: # pylint: disable=used-before-assignment - raise IOError(f.errorString()) + raise OSError(f.errorString()) if binary: new_f = PyQIODevice(f) else: @@ -177,7 +177,7 @@ def savefile_open(filename, binary=False, encoding='utf-8'): new_f.flush() ok = f.commit() if not ok: - raise IOError(f.errorString()) + raise OSError(f.errorString()) class PyQIODevice(io.BufferedIOBase): @@ -197,14 +197,14 @@ class PyQIODevice(io.BufferedIOBase): return self._dev.size() def _check_open(self): - """Check if the device is open, raise IOError if not.""" + """Check if the device is open, raise OSError if not.""" if not self._dev.isOpen(): - raise IOError("IO operation on closed device!") + raise OSError("IO operation on closed device!") def _check_random(self): - """Check if the device supports random access, raise IOError if not.""" + """Check if the device supports random access, raise OSError if not.""" if not self.seekable(): - raise IOError("Random access not allowed!") + raise OSError("Random access not allowed!") def fileno(self): raise io.UnsupportedOperation @@ -222,7 +222,7 @@ class PyQIODevice(io.BufferedIOBase): raise io.UnsupportedOperation("whence = {} is not " "supported!".format(whence)) if not ok: - raise IOError(self._dev.errorString()) + raise OSError(self._dev.errorString()) def truncate(self, size=None): # pylint: disable=unused-argument raise io.UnsupportedOperation @@ -270,7 +270,7 @@ class PyQIODevice(io.BufferedIOBase): self._check_open() num = self._dev.write(b) if num == -1 or num < len(b): - raise IOError(self._dev.errorString()) + raise OSError(self._dev.errorString()) return num def read(self, size): @@ -278,7 +278,7 @@ class PyQIODevice(io.BufferedIOBase): buf = bytes() num = self._dev.read(buf, size) if num == -1: - raise IOError(self._dev.errorString()) + raise OSError(self._dev.errorString()) return num diff --git a/qutebrowser/utils/version.py b/qutebrowser/utils/version.py index 09bf5dc1c..b401c542a 100644 --- a/qutebrowser/utils/version.py +++ b/qutebrowser/utils/version.py @@ -111,7 +111,7 @@ def _release_info(): try: with open(fn, 'r', encoding='utf-8') as f: data.append((fn, ''.join(f.readlines()))) - except IOError: + except OSError: log.misc.exception("Error while reading {}.".format(fn)) return data diff --git a/scripts/hostblock_blame.py b/scripts/hostblock_blame.py index 49a46aa84..8c4060542 100644 --- a/scripts/hostblock_blame.py +++ b/scripts/hostblock_blame.py @@ -49,7 +49,7 @@ def main(): print("config path: {}".format(confpath)) successful = parser.read(confpath, encoding='utf-8') if not successful: - raise IOError("configparser did not read files successfully!") + raise OSError("configparser did not read files successfully!") lists = parser['content']['host-block-lists'] for url in lists.split(','): print("checking {}...".format(url)) diff --git a/scripts/run_checks.py b/scripts/run_checks.py index d55ce8b59..9b4fa307a 100755 --- a/scripts/run_checks.py +++ b/scripts/run_checks.py @@ -278,7 +278,7 @@ def main(): utils.change_cwd() read_files = config.read('.run_checks') if not read_files: - raise IOError("Could not read config!") + raise OSError("Could not read config!") exit_status = collections.OrderedDict() exit_status_bool = {}