Skip to content

Commit

Permalink
Fix more problems with "/usr/bin/env python" picking python3.
Browse files Browse the repository at this point in the history
Open files in 'rb' (read binary) mode to prevent useless default utf8
encoding in python3, without breaking python2 compatibility.

Reported-by: Tharre <tharre3@gmail.com>
  • Loading branch information
apenwarr committed May 15, 2019
1 parent 2e4d3d5 commit fb0a5bd
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion docs/cookbook/container/default.sha256.do
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions docs/cookbook/container/fileids.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
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' % (
Expand Down

0 comments on commit fb0a5bd

Please sign in to comment.