diff options
author | Tim Peters <tim.peters@gmail.com> | 2003-08-18 23:52:09 (GMT) |
---|---|---|
committer | Tim Peters <tim.peters@gmail.com> | 2003-08-18 23:52:09 (GMT) |
commit | 1a3abcb648565b1c521c41d49ecd7c93a45c6d97 (patch) | |
tree | 6fec86e244cd7944a53f1c99c4b829a5af733788 /Tools | |
parent | c58a3a10a91f0c0c2debc2c386bfeee8184e0f86 (diff) | |
download | cpython-1a3abcb648565b1c521c41d49ecd7c93a45c6d97.zip cpython-1a3abcb648565b1c521c41d49ecd7c93a45c6d97.tar.gz cpython-1a3abcb648565b1c521c41d49ecd7c93a45c6d97.tar.bz2 |
This started opening files in text mode by default in the 2.3 release,
which is a disaster on Windows. Restored the binary default of all
previous releases. Also minor code cleanups.
Bugfix candidate!
Diffstat (limited to 'Tools')
-rw-r--r-- | Tools/scripts/md5sum.py | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/Tools/scripts/md5sum.py b/Tools/scripts/md5sum.py index 0711db8..e045f1a 100644 --- a/Tools/scripts/md5sum.py +++ b/Tools/scripts/md5sum.py @@ -6,12 +6,12 @@ bufsize = 8096 fnfilter = None -rmode = 'r' +rmode = 'rb' usage = """ usage: sum5 [-b] [-t] [-l] [-s bufsize] [file ...] --b : read files in binary mode --t : read files in text mode (default) +-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 -s bufsize: read buffer size (default %d) file ... : files to sum; '-' or no files means stdin @@ -40,7 +40,7 @@ def sum(*files): sts = sum(f, out) or sts return sts -def printsum(filename, out = sys.stdout): +def printsum(filename, out=sys.stdout): try: fp = open(filename, rmode) except IOError, msg: @@ -52,12 +52,13 @@ def printsum(filename, out = sys.stdout): fp.close() return sts -def printsumfp(fp, filename, out = sys.stdout): +def printsumfp(fp, filename, out=sys.stdout): m = md5.new() try: while 1: data = fp.read(bufsize) - if not data: break + if not data: + break m.update(data) except IOError, msg: sys.stderr.write('%s: I/O error: %s\n' % (filename, msg)) @@ -65,7 +66,7 @@ def printsumfp(fp, filename, out = sys.stdout): out.write('%s %s\n' % (m.hexdigest(), filename)) return 0 -def main(args = sys.argv[1:], out = sys.stdout): +def main(args = sys.argv[1:], out=sys.stdout): global fnfilter, rmode, bufsize try: opts, args = getopt.getopt(args, 'blts:') @@ -75,11 +76,11 @@ def main(args = sys.argv[1:], out = sys.stdout): for o, a in opts: if o == '-l': fnfilter = os.path.basename - if o == '-b': + elif o == '-b': rmode = 'rb' - if o == '-t': + elif o == '-t': rmode = 'r' - if o == '-s': + elif o == '-s': bufsize = int(a) if not args: args = ['-'] |