summaryrefslogtreecommitdiffstats
path: root/Tools
diff options
context:
space:
mode:
authorBerker Peksag <berker.peksag@gmail.com>2014-07-11 17:42:18 (GMT)
committerBerker Peksag <berker.peksag@gmail.com>2014-07-11 17:42:18 (GMT)
commit7aee3ecd57c5d7a455420dd514206e239c7dbc39 (patch)
treed1ec736cc9d2697c708e649584c86ffc81d16983 /Tools
parent778015b3bc19a3ae3bdaaef82352a9aa2ea48d4e (diff)
downloadcpython-7aee3ecd57c5d7a455420dd514206e239c7dbc39.zip
cpython-7aee3ecd57c5d7a455420dd514206e239c7dbc39.tar.gz
cpython-7aee3ecd57c5d7a455420dd514206e239c7dbc39.tar.bz2
Issue #21906: Make Tools/scripts/md5sum.py work in Python 3.
Patch by Zachary Ware.
Diffstat (limited to 'Tools')
-rwxr-xr-xTools/scripts/md5sum.py9
1 files changed, 6 insertions, 3 deletions
diff --git a/Tools/scripts/md5sum.py b/Tools/scripts/md5sum.py
index 521960c..9cf4bdc 100755
--- a/Tools/scripts/md5sum.py
+++ b/Tools/scripts/md5sum.py
@@ -9,7 +9,7 @@ fnfilter = None
rmode = 'rb'
usage = """
-usage: sum5 [-b] [-t] [-l] [-s bufsize] [file ...]
+usage: md5sum.py [-b] [-t] [-l] [-s bufsize] [file ...]
-b : read files in binary mode (default)
-t : read files in text mode (you almost certainly don't want this!)
-l : print last pathname component only
@@ -17,6 +17,7 @@ usage: sum5 [-b] [-t] [-l] [-s bufsize] [file ...]
file ... : files to sum; '-' or no files means stdin
""" % bufsize
+import io
import sys
import os
import getopt
@@ -24,7 +25,7 @@ from hashlib import md5
def sum(*files):
sts = 0
- if files and isinstance(files[-1], file):
+ if files and isinstance(files[-1], io.IOBase):
out, files = files[-1], files[:-1]
else:
out = sys.stdout
@@ -53,12 +54,14 @@ def printsum(filename, out=sys.stdout):
return sts
def printsumfp(fp, filename, out=sys.stdout):
- m = md5.new()
+ m = md5()
try:
while 1:
data = fp.read(bufsize)
if not data:
break
+ if isinstance(data, str):
+ data = data.encode(fp.encoding)
m.update(data)
except IOError as msg:
sys.stderr.write('%s: I/O error: %s\n' % (filename, msg))