use binary stdin on py3k
authorHelmut Grohne <helmut@subdivi.de>
Thu, 16 Apr 2015 15:43:48 +0000 (17:43 +0200)
committerHelmut Grohne <helmut@subdivi.de>
Thu, 16 Apr 2015 15:43:48 +0000 (17:43 +0200)
importpkg.py

index 6dced21..99e9850 100755 (executable)
@@ -110,10 +110,14 @@ def main():
                       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
+        stdin = sys.stdin
     if options.hash:
-        gen = process_package_with_hash(sys.stdin, hash_functions, options.hash)
+        gen = process_package_with_hash(stdin, hash_functions, options.hash)
     else:
-        gen = process_package(sys.stdin, hash_functions)
+        gen = process_package(stdin, hash_functions)
     yaml.safe_dump_all(gen, sys.stdout)
 
 if __name__ == "__main__":