From fb0a5bd69c49fce9addf999491a1dcc2c6eecb89 Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Wed, 15 May 2019 16:53:49 -0700 Subject: [PATCH] Fix more problems with "/usr/bin/env python" picking python3. Open files in 'rb' (read binary) mode to prevent useless default utf8 encoding in python3, without breaking python2 compatibility. Reported-by: Tharre --- docs/cookbook/container/default.sha256.do | 2 +- docs/cookbook/container/fileids.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/cookbook/container/default.sha256.do b/docs/cookbook/container/default.sha256.do index 67f1e83..d3007e9 100644 --- a/docs/cookbook/container/default.sha256.do +++ b/docs/cookbook/container/default.sha256.do @@ -8,7 +8,7 @@ subprocess.check_call([ ], close_fds=False) h = hashlib.sha256() -f = open(sys.argv[2]) +f = open(sys.argv[2], 'rb') while 1: b = f.read(65536) if not b: break diff --git a/docs/cookbook/container/fileids.py b/docs/cookbook/container/fileids.py index 0bc6319..68d9982 100755 --- a/docs/cookbook/container/fileids.py +++ b/docs/cookbook/container/fileids.py @@ -6,14 +6,14 @@ for name in sys.stdin: st = os.lstat(name) if stat.S_ISREG(st.st_mode): h = hashlib.sha256() - f = open(name) + f = open(name, 'rb') while 1: b = f.read(65536) if not b: break h.update(b) digest = h.hexdigest() elif stat.S_ISLNK(st.st_mode): - digest = hashlib.sha256(os.readlink(name)).hexdigest() + digest = hashlib.sha256(os.readlink(name).encode('utf8')).hexdigest() else: digest = '0' print('%s %07o-%s-%s-%s' % (