summaryrefslogtreecommitdiffstats
path: root/Tools
diff options
context:
space:
mode:
authorBerker Peksag <berker.peksag@gmail.com>2014-07-11 17:44:39 (GMT)
committerBerker Peksag <berker.peksag@gmail.com>2014-07-11 17:44:39 (GMT)
commit6960c1a94bfdc0687595c96c7779bb8e02b6984c (patch)
tree8f40bb2185c8237bd3e3b86b9fa77be3ba718e28 /Tools
parentd8089e0d04a98ab7997eff7abc9abf2a4f6854b8 (diff)
parent7aee3ecd57c5d7a455420dd514206e239c7dbc39 (diff)
downloadcpython-6960c1a94bfdc0687595c96c7779bb8e02b6984c.zip
cpython-6960c1a94bfdc0687595c96c7779bb8e02b6984c.tar.gz
cpython-6960c1a94bfdc0687595c96c7779bb8e02b6984c.tar.bz2
Issue #21906: Merge from 3.4.
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))