Replace all IOError by OSErrors.

Starting with Python 3.3, IOError is just an alias for OSError.
This commit is contained in:
Florian Bruhin 2014-12-10 16:48:23 +01:00
parent 206b5f548e
commit ea76bdfb0f
7 changed files with 18 additions and 18 deletions

View File

@ -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):

View File

@ -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)

View File

@ -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())

View File

@ -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

View File

@ -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

View File

@ -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))

View File

@ -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 = {}