use OSError instead of IOError
authorPhilipp Gesang <philipp.gesang@intra2net.com>
Fri, 7 Apr 2017 14:59:19 +0000 (16:59 +0200)
committerThomas Jarosch <thomas.jarosch@intra2net.com>
Mon, 2 Apr 2018 11:34:08 +0000 (13:34 +0200)
IOError is a synonym for OSError, so the latter should be used
everywhere to avoid confusion, especially when throwing the one
but catching the other.

Cf. PEP 3151.

deltatar/tarfile.py
testing/test_multivol.py

index 62b76f6..65513c5 100644 (file)
@@ -876,7 +876,7 @@ class _Stream:
             if self.cmp is not None:
                 try:
                     buf = self.cmp.decompress(buf)
-                except IOError:
+                except OSError:
                     raise ReadError("invalid compressed data")
                 except Exception as e:
                     # happens at the end of the file
@@ -2859,7 +2859,7 @@ class TarFile(object):
             iterate = False
             try:
                 copyfileobj(source, target, tarinfo.size)
-            except IOError: # on *any* IOError even in the target?
+            except OSError:
                 source.close()
                 # only if we are extracting a multivolume this can be treated
                 if not self.new_volume_handler:
index a7a4772..c99f521 100644 (file)
@@ -731,7 +731,7 @@ class MultivolGnuFormatTest(BaseTest):
             try:
                 tarobj.fileobj.close()
                 tarobj.open_volume(volume_path)
-            except IOError as e:
+            except OSError as e:
                 # only volume number 2 is missing
                 assert volume_number == 2
                 raise e
@@ -742,7 +742,7 @@ class MultivolGnuFormatTest(BaseTest):
                               new_volume_handler=new_volume_handler2)
         try:
             tarobj.extractall()
-        except IOError as e:
+        except OSError as e:
             pass
         tarobj.close()
         assert os.path.exists("big")