Replace all IOError by OSErrors.
Starting with Python 3.3, IOError is just an alias for OSError.
This commit is contained in:
parent
206b5f548e
commit
ea76bdfb0f
@ -196,7 +196,7 @@ class HostBlocker:
|
|||||||
if urls is None:
|
if urls is None:
|
||||||
try:
|
try:
|
||||||
os.remove(self._hosts_file)
|
os.remove(self._hosts_file)
|
||||||
except IOError:
|
except OSError:
|
||||||
log.misc.exception("Failed to delete hosts file.")
|
log.misc.exception("Failed to delete hosts file.")
|
||||||
|
|
||||||
def on_download_finished(self, download):
|
def on_download_finished(self, download):
|
||||||
|
@ -421,7 +421,7 @@ class DownloadItem(QObject):
|
|||||||
# qute:log for example).
|
# qute:log for example).
|
||||||
return
|
return
|
||||||
if not self.reply.isOpen():
|
if not self.reply.isOpen():
|
||||||
raise IOError("Reply is closed!")
|
raise OSError("Reply is closed!")
|
||||||
try:
|
try:
|
||||||
self.fileobj.write(self.reply.readAll())
|
self.fileobj.write(self.reply.readAll())
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
@ -439,7 +439,7 @@ class DownloadItem(QObject):
|
|||||||
def on_read_timer_timeout(self):
|
def on_read_timer_timeout(self):
|
||||||
"""Read some bytes from the QNetworkReply periodically."""
|
"""Read some bytes from the QNetworkReply periodically."""
|
||||||
if not self.reply.isOpen():
|
if not self.reply.isOpen():
|
||||||
raise IOError("Reply is closed!")
|
raise OSError("Reply is closed!")
|
||||||
data = self.reply.read(1024)
|
data = self.reply.read(1024)
|
||||||
self._buffer.write(data)
|
self._buffer.write(data)
|
||||||
|
|
||||||
|
@ -73,7 +73,7 @@ class QuteSchemeHandler(schemehandler.SchemeHandler):
|
|||||||
self.parent())
|
self.parent())
|
||||||
try:
|
try:
|
||||||
data = handler(self._win_id, request)
|
data = handler(self._win_id, request)
|
||||||
except IOError as e:
|
except OSError as e:
|
||||||
return networkreply.ErrorNetworkReply(
|
return networkreply.ErrorNetworkReply(
|
||||||
request, str(e), QNetworkReply.ContentNotFoundError,
|
request, str(e), QNetworkReply.ContentNotFoundError,
|
||||||
self.parent())
|
self.parent())
|
||||||
|
@ -128,7 +128,7 @@ def ensure_valid(obj):
|
|||||||
|
|
||||||
|
|
||||||
def _check_qdatastream(stream):
|
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 = {
|
status_to_str = {
|
||||||
QDataStream.Ok: "The data stream is operating normally.",
|
QDataStream.Ok: "The data stream is operating normally.",
|
||||||
QDataStream.ReadPastEnd: ("The data stream has read past the end of "
|
QDataStream.ReadPastEnd: ("The data stream has read past the end of "
|
||||||
@ -138,7 +138,7 @@ def _check_qdatastream(stream):
|
|||||||
"underlying device."),
|
"underlying device."),
|
||||||
}
|
}
|
||||||
if stream.status() != QDataStream.Ok:
|
if stream.status() != QDataStream.Ok:
|
||||||
raise IOError(status_to_str[stream.status()])
|
raise OSError(status_to_str[stream.status()])
|
||||||
|
|
||||||
|
|
||||||
def serialize(obj):
|
def serialize(obj):
|
||||||
@ -164,7 +164,7 @@ def savefile_open(filename, binary=False, encoding='utf-8'):
|
|||||||
try:
|
try:
|
||||||
ok = f.open(QIODevice.WriteOnly)
|
ok = f.open(QIODevice.WriteOnly)
|
||||||
if not ok: # pylint: disable=used-before-assignment
|
if not ok: # pylint: disable=used-before-assignment
|
||||||
raise IOError(f.errorString())
|
raise OSError(f.errorString())
|
||||||
if binary:
|
if binary:
|
||||||
new_f = PyQIODevice(f)
|
new_f = PyQIODevice(f)
|
||||||
else:
|
else:
|
||||||
@ -177,7 +177,7 @@ def savefile_open(filename, binary=False, encoding='utf-8'):
|
|||||||
new_f.flush()
|
new_f.flush()
|
||||||
ok = f.commit()
|
ok = f.commit()
|
||||||
if not ok:
|
if not ok:
|
||||||
raise IOError(f.errorString())
|
raise OSError(f.errorString())
|
||||||
|
|
||||||
|
|
||||||
class PyQIODevice(io.BufferedIOBase):
|
class PyQIODevice(io.BufferedIOBase):
|
||||||
@ -197,14 +197,14 @@ class PyQIODevice(io.BufferedIOBase):
|
|||||||
return self._dev.size()
|
return self._dev.size()
|
||||||
|
|
||||||
def _check_open(self):
|
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():
|
if not self._dev.isOpen():
|
||||||
raise IOError("IO operation on closed device!")
|
raise OSError("IO operation on closed device!")
|
||||||
|
|
||||||
def _check_random(self):
|
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():
|
if not self.seekable():
|
||||||
raise IOError("Random access not allowed!")
|
raise OSError("Random access not allowed!")
|
||||||
|
|
||||||
def fileno(self):
|
def fileno(self):
|
||||||
raise io.UnsupportedOperation
|
raise io.UnsupportedOperation
|
||||||
@ -222,7 +222,7 @@ class PyQIODevice(io.BufferedIOBase):
|
|||||||
raise io.UnsupportedOperation("whence = {} is not "
|
raise io.UnsupportedOperation("whence = {} is not "
|
||||||
"supported!".format(whence))
|
"supported!".format(whence))
|
||||||
if not ok:
|
if not ok:
|
||||||
raise IOError(self._dev.errorString())
|
raise OSError(self._dev.errorString())
|
||||||
|
|
||||||
def truncate(self, size=None): # pylint: disable=unused-argument
|
def truncate(self, size=None): # pylint: disable=unused-argument
|
||||||
raise io.UnsupportedOperation
|
raise io.UnsupportedOperation
|
||||||
@ -270,7 +270,7 @@ class PyQIODevice(io.BufferedIOBase):
|
|||||||
self._check_open()
|
self._check_open()
|
||||||
num = self._dev.write(b)
|
num = self._dev.write(b)
|
||||||
if num == -1 or num < len(b):
|
if num == -1 or num < len(b):
|
||||||
raise IOError(self._dev.errorString())
|
raise OSError(self._dev.errorString())
|
||||||
return num
|
return num
|
||||||
|
|
||||||
def read(self, size):
|
def read(self, size):
|
||||||
@ -278,7 +278,7 @@ class PyQIODevice(io.BufferedIOBase):
|
|||||||
buf = bytes()
|
buf = bytes()
|
||||||
num = self._dev.read(buf, size)
|
num = self._dev.read(buf, size)
|
||||||
if num == -1:
|
if num == -1:
|
||||||
raise IOError(self._dev.errorString())
|
raise OSError(self._dev.errorString())
|
||||||
return num
|
return num
|
||||||
|
|
||||||
|
|
||||||
|
@ -111,7 +111,7 @@ def _release_info():
|
|||||||
try:
|
try:
|
||||||
with open(fn, 'r', encoding='utf-8') as f:
|
with open(fn, 'r', encoding='utf-8') as f:
|
||||||
data.append((fn, ''.join(f.readlines())))
|
data.append((fn, ''.join(f.readlines())))
|
||||||
except IOError:
|
except OSError:
|
||||||
log.misc.exception("Error while reading {}.".format(fn))
|
log.misc.exception("Error while reading {}.".format(fn))
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@ def main():
|
|||||||
print("config path: {}".format(confpath))
|
print("config path: {}".format(confpath))
|
||||||
successful = parser.read(confpath, encoding='utf-8')
|
successful = parser.read(confpath, encoding='utf-8')
|
||||||
if not successful:
|
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']
|
lists = parser['content']['host-block-lists']
|
||||||
for url in lists.split(','):
|
for url in lists.split(','):
|
||||||
print("checking {}...".format(url))
|
print("checking {}...".format(url))
|
||||||
|
@ -278,7 +278,7 @@ def main():
|
|||||||
utils.change_cwd()
|
utils.change_cwd()
|
||||||
read_files = config.read('.run_checks')
|
read_files = config.read('.run_checks')
|
||||||
if not read_files:
|
if not read_files:
|
||||||
raise IOError("Could not read config!")
|
raise OSError("Could not read config!")
|
||||||
exit_status = collections.OrderedDict()
|
exit_status = collections.OrderedDict()
|
||||||
exit_status_bool = {}
|
exit_status_bool = {}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user