drop support for Python 2.x
[~helmut/debian-dedup.git] / dedup / debpkg.py
index 3a30b3e..38086ec 100644 (file)
@@ -1,4 +1,3 @@
-import sys
 import tarfile
 
 from debian import deb822
@@ -7,7 +6,7 @@ from dedup.arreader import ArReader
 from dedup.compression import decompress
 from dedup.hashing import hash_file
 
-class MultiHash(object):
+class MultiHash:
     def __init__(self, *hashes):
         self.hashes = hashes
 
@@ -38,32 +37,11 @@ def get_tar_hashes(tar, hash_functions):
                 hashes[hashobj.name] = hashvalue
         yield (elem.name, elem.size, hashes)
 
-if sys.version_info.major >= 3:
-    def opentar(filelike):
-        return tarfile.open(fileobj=filelike, mode="r|", encoding="utf8",
-                            errors="surrogateescape")
+def opentar(filelike):
+    return tarfile.open(fileobj=filelike, mode="r|", encoding="utf8",
+                        errors="surrogateescape")
 
-    def decodetarname(name):
-        """Decoded name of a tarinfo.
-        @raises UnicodeDecodeError:
-        """
-        try:
-            name.encode("utf8", "strict")
-        except UnicodeEncodeError as e:
-            if e.reason == "surrogates not allowed":
-                name.encode("utf8", "surrogateescape").decode("utf8", "strict")
-        return name
-else:
-    def opentar(filelike):
-        return tarfile.open(fileobj=filelike, mode="r|")
-
-    def decodetarname(name):
-        """Decoded name of a tarinfo.
-        @raises UnicodeDecodeError:
-        """
-        return name.decode("utf8")
-
-class DebExtractor(object):
+class DebExtractor:
     "Base class for extracting desired features from a Debian package."
 
     def __init__(self):