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!
This commit is contained in:
parent
c58a3a10a9
commit
1a3abcb648
|
@ -52,6 +52,12 @@ Library
|
||||||
Tools/Demos
|
Tools/Demos
|
||||||
-----------
|
-----------
|
||||||
|
|
||||||
|
- md5sum.py mistakenly opened input files in text mode by default, a
|
||||||
|
silent and dangerous change from previous releases. It once again
|
||||||
|
opens input files in binary mode by default. The -t and -b flags
|
||||||
|
remain for compatibility with the 2.3 release, but -b is the default
|
||||||
|
now.
|
||||||
|
|
||||||
- py-electric-colon now works when pending-delete/delete-selection mode is
|
- py-electric-colon now works when pending-delete/delete-selection mode is
|
||||||
in effect
|
in effect
|
||||||
|
|
||||||
|
|
|
@ -6,12 +6,12 @@
|
||||||
|
|
||||||
bufsize = 8096
|
bufsize = 8096
|
||||||
fnfilter = None
|
fnfilter = None
|
||||||
rmode = 'r'
|
rmode = 'rb'
|
||||||
|
|
||||||
usage = """
|
usage = """
|
||||||
usage: sum5 [-b] [-t] [-l] [-s bufsize] [file ...]
|
usage: sum5 [-b] [-t] [-l] [-s bufsize] [file ...]
|
||||||
-b : read files in binary mode
|
-b : read files in binary mode (default)
|
||||||
-t : read files in text mode (default)
|
-t : read files in text mode (you almost certainly don't want this!)
|
||||||
-l : print last pathname component only
|
-l : print last pathname component only
|
||||||
-s bufsize: read buffer size (default %d)
|
-s bufsize: read buffer size (default %d)
|
||||||
file ... : files to sum; '-' or no files means stdin
|
file ... : files to sum; '-' or no files means stdin
|
||||||
|
@ -40,7 +40,7 @@ def sum(*files):
|
||||||
sts = sum(f, out) or sts
|
sts = sum(f, out) or sts
|
||||||
return sts
|
return sts
|
||||||
|
|
||||||
def printsum(filename, out = sys.stdout):
|
def printsum(filename, out=sys.stdout):
|
||||||
try:
|
try:
|
||||||
fp = open(filename, rmode)
|
fp = open(filename, rmode)
|
||||||
except IOError, msg:
|
except IOError, msg:
|
||||||
|
@ -52,12 +52,13 @@ def printsum(filename, out = sys.stdout):
|
||||||
fp.close()
|
fp.close()
|
||||||
return sts
|
return sts
|
||||||
|
|
||||||
def printsumfp(fp, filename, out = sys.stdout):
|
def printsumfp(fp, filename, out=sys.stdout):
|
||||||
m = md5.new()
|
m = md5.new()
|
||||||
try:
|
try:
|
||||||
while 1:
|
while 1:
|
||||||
data = fp.read(bufsize)
|
data = fp.read(bufsize)
|
||||||
if not data: break
|
if not data:
|
||||||
|
break
|
||||||
m.update(data)
|
m.update(data)
|
||||||
except IOError, msg:
|
except IOError, msg:
|
||||||
sys.stderr.write('%s: I/O error: %s\n' % (filename, 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))
|
out.write('%s %s\n' % (m.hexdigest(), filename))
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
def main(args = sys.argv[1:], out = sys.stdout):
|
def main(args = sys.argv[1:], out=sys.stdout):
|
||||||
global fnfilter, rmode, bufsize
|
global fnfilter, rmode, bufsize
|
||||||
try:
|
try:
|
||||||
opts, args = getopt.getopt(args, 'blts:')
|
opts, args = getopt.getopt(args, 'blts:')
|
||||||
|
@ -75,11 +76,11 @@ def main(args = sys.argv[1:], out = sys.stdout):
|
||||||
for o, a in opts:
|
for o, a in opts:
|
||||||
if o == '-l':
|
if o == '-l':
|
||||||
fnfilter = os.path.basename
|
fnfilter = os.path.basename
|
||||||
if o == '-b':
|
elif o == '-b':
|
||||||
rmode = 'rb'
|
rmode = 'rb'
|
||||||
if o == '-t':
|
elif o == '-t':
|
||||||
rmode = 'r'
|
rmode = 'r'
|
||||||
if o == '-s':
|
elif o == '-s':
|
||||||
bufsize = int(a)
|
bufsize = int(a)
|
||||||
if not args:
|
if not args:
|
||||||
args = ['-']
|
args = ['-']
|
||||||
|
|
Loading…
Reference in New Issue