importpkg: move the hash function list to the extractor class
authorHelmut Grohne <helmut@subdivi.de>
Thu, 21 Apr 2016 21:15:22 +0000 (23:15 +0200)
committerHelmut Grohne <helmut@subdivi.de>
Thu, 21 Apr 2016 21:15:22 +0000 (23:15 +0200)
They really are an aspect of the particular extractor and can easily be
changed by subclassing.

importpkg.py

index 0798f13..01ec87a 100755 (executable)
@@ -57,9 +57,10 @@ class ProcessingFinished(Exception):
     pass
 
 class ImportpkgExtractor(DebExtractor):
-    def __init__(self, hash_functions, callback):
+    hash_functions = [sha512_nontrivial, gziphash, pnghash, gifhash]
+
+    def __init__(self, callback):
         self.state = "start"
-        self.hash_functions = hash_functions
         self.callback = callback
 
     def handle_ar_member(self, name, filelike):
@@ -99,7 +100,6 @@ def main():
     parser.add_option("-H", "--hash", action="store",
                       help="verify that stdin hash given sha256 hash")
     options, args = parser.parse_args()
-    hash_functions = [sha512_nontrivial, gziphash, pnghash, gifhash]
     try:
         stdin = sys.stdin.buffer
     except AttributeError: # python2
@@ -109,7 +109,7 @@ def main():
     if options.hash:
         stdin = HashedStream(stdin, hashlib.sha256())
     try:
-        ImportpkgExtractor(hash_functions, dumper.represent).process(stdin)
+        ImportpkgExtractor(dumper.represent).process(stdin)
     except ProcessingFinished:
         pass
     else: