summaryrefslogtreecommitdiffstats
path: root/Tools/scripts/sum5.py
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2001-01-17 08:48:39 (GMT)
committerTim Peters <tim.peters@gmail.com>2001-01-17 08:48:39 (GMT)
commit70c4378dbcfdcbeef6fb3aa348f32ed862fe8eb7 (patch)
treecf47b67db3753288cfd9fa2adc45e7c5cd2f8741 /Tools/scripts/sum5.py
parenta88854059309667092000da55d4d5a5804267e9f (diff)
downloadcpython-70c4378dbcfdcbeef6fb3aa348f32ed862fe8eb7.zip
cpython-70c4378dbcfdcbeef6fb3aa348f32ed862fe8eb7.tar.gz
cpython-70c4378dbcfdcbeef6fb3aa348f32ed862fe8eb7.tar.bz2
Whitespace normalization.
Diffstat (limited to 'Tools/scripts/sum5.py')
-rwxr-xr-xTools/scripts/sum5.py120
1 files changed, 60 insertions, 60 deletions
diff --git a/Tools/scripts/sum5.py b/Tools/scripts/sum5.py
index 09bc686..6d3b965 100755
--- a/Tools/scripts/sum5.py
+++ b/Tools/scripts/sum5.py
@@ -25,73 +25,73 @@ StringType = type('')
FileType = type(sys.stdin)
def sum(*files):
- sts = 0
- if files and type(files[-1]) == FileType:
- out, files = files[-1], files[:-1]
- else:
- out = sys.stdout
- if len(files) == 1 and type(files[0]) != StringType:
- files = files[0]
- for f in files:
- if type(f) == StringType:
- if f == '-':
- sts = printsumfp(sys.stdin, '<stdin>', out) or sts
- else:
- sts = printsum(f, out) or sts
- else:
- sts = sum(f, out) or sts
- return sts
+ sts = 0
+ if files and type(files[-1]) == FileType:
+ out, files = files[-1], files[:-1]
+ else:
+ out = sys.stdout
+ if len(files) == 1 and type(files[0]) != StringType:
+ files = files[0]
+ for f in files:
+ if type(f) == StringType:
+ if f == '-':
+ sts = printsumfp(sys.stdin, '<stdin>', out) or sts
+ else:
+ sts = printsum(f, out) or sts
+ else:
+ sts = sum(f, out) or sts
+ return sts
def printsum(file, out = sys.stdout):
- try:
- fp = open(file, rmode)
- except IOError, msg:
- sys.stderr.write('%s: Can\'t open: %s\n' % (file, msg))
- return 1
- if fnfilter:
- file = fnfilter(file)
- sts = printsumfp(fp, file, out)
- fp.close()
- return sts
+ try:
+ fp = open(file, rmode)
+ except IOError, msg:
+ sys.stderr.write('%s: Can\'t open: %s\n' % (file, msg))
+ return 1
+ if fnfilter:
+ file = fnfilter(file)
+ sts = printsumfp(fp, file, out)
+ fp.close()
+ return sts
def printsumfp(fp, file, out = sys.stdout):
- m = md5.md5()
- try:
- while 1:
- data = fp.read(bufsize)
- if not data: break
- m.update(data)
- except IOError, msg:
- sys.stderr.write('%s: I/O error: %s\n' % (file, msg))
- return 1
- out.write('%s %s\n' % (hexify(m.digest()), file))
- return 0
+ m = md5.md5()
+ try:
+ while 1:
+ data = fp.read(bufsize)
+ if not data: break
+ m.update(data)
+ except IOError, msg:
+ sys.stderr.write('%s: I/O error: %s\n' % (file, msg))
+ return 1
+ out.write('%s %s\n' % (hexify(m.digest()), file))
+ return 0
def hexify(s):
- res = ''
- for c in s:
- res = res + '%02x' % ord(c)
- return res
+ res = ''
+ for c in s:
+ res = res + '%02x' % ord(c)
+ return res
def main(args = sys.argv[1:], out = sys.stdout):
- global fnfilter, rmode, bufsize
- import getopt
- try:
- opts, args = getopt.getopt(args, 'blts:')
- except getopt.error, msg:
- sys.stderr.write('%s: %s\n%s' % (sys.argv[0], msg, usage))
- return 2
- for o, a in opts:
- if o == '-l':
- fnfilter = os.path.basename
- if o == '-b':
- rmode = 'rb'
- if o == '-t':
- rmode = 'r'
- if o == '-s':
- bufsize = string.atoi(a)
- if not args: args = ['-']
- return sum(args, out)
+ global fnfilter, rmode, bufsize
+ import getopt
+ try:
+ opts, args = getopt.getopt(args, 'blts:')
+ except getopt.error, msg:
+ sys.stderr.write('%s: %s\n%s' % (sys.argv[0], msg, usage))
+ return 2
+ for o, a in opts:
+ if o == '-l':
+ fnfilter = os.path.basename
+ if o == '-b':
+ rmode = 'rb'
+ if o == '-t':
+ rmode = 'r'
+ if o == '-s':
+ bufsize = string.atoi(a)
+ if not args: args = ['-']
+ return sum(args, out)
if __name__ == '__main__' or __name__ == sys.argv[0]:
- sys.exit(main(sys.argv[1:], sys.stdout))
+ sys.exit(main(sys.argv[1:], sys.stdout))