annotate Tools/scripts/md5sum.py @ 25135:0f0016632be4 legacy-trunk

_formatparam(), set_param(): RFC 2231 encoding support by Oleg Broytmann in SF patch #600096. Specifically, the former function now encodes the triplets, while the latter adds optional charset and language arguments.
author Barry Warsaw <barry@python.org>
date Fri, 06 Sep 2002 03:55:04 +0000
parents fde878bc0e3b
children a5e99e7e7ff0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
18218
6991ddafe382 This is a trivial command line utility to print MD5 checksums.
Guido van Rossum <guido@python.org>
parents:
diff changeset
1 #! /usr/bin/env python
6991ddafe382 This is a trivial command line utility to print MD5 checksums.
Guido van Rossum <guido@python.org>
parents:
diff changeset
2
6991ddafe382 This is a trivial command line utility to print MD5 checksums.
Guido van Rossum <guido@python.org>
parents:
diff changeset
3 """Python utility to print MD5 checksums of argument files.
6991ddafe382 This is a trivial command line utility to print MD5 checksums.
Guido van Rossum <guido@python.org>
parents:
diff changeset
4
23116
fde878bc0e3b Use 2.1's .hexdigest() method
Andrew M. Kuchling <amk@amk.ca>
parents: 18218
diff changeset
5 Works with Python 2.1 and later.
18218
6991ddafe382 This is a trivial command line utility to print MD5 checksums.
Guido van Rossum <guido@python.org>
parents:
diff changeset
6 """
6991ddafe382 This is a trivial command line utility to print MD5 checksums.
Guido van Rossum <guido@python.org>
parents:
diff changeset
7
6991ddafe382 This is a trivial command line utility to print MD5 checksums.
Guido van Rossum <guido@python.org>
parents:
diff changeset
8 import sys, md5
6991ddafe382 This is a trivial command line utility to print MD5 checksums.
Guido van Rossum <guido@python.org>
parents:
diff changeset
9
6991ddafe382 This is a trivial command line utility to print MD5 checksums.
Guido van Rossum <guido@python.org>
parents:
diff changeset
10 BLOCKSIZE = 1024*1024
6991ddafe382 This is a trivial command line utility to print MD5 checksums.
Guido van Rossum <guido@python.org>
parents:
diff changeset
11
6991ddafe382 This is a trivial command line utility to print MD5 checksums.
Guido van Rossum <guido@python.org>
parents:
diff changeset
12 def main():
6991ddafe382 This is a trivial command line utility to print MD5 checksums.
Guido van Rossum <guido@python.org>
parents:
diff changeset
13 args = sys.argv[1:]
6991ddafe382 This is a trivial command line utility to print MD5 checksums.
Guido van Rossum <guido@python.org>
parents:
diff changeset
14 if not args:
6991ddafe382 This is a trivial command line utility to print MD5 checksums.
Guido van Rossum <guido@python.org>
parents:
diff changeset
15 sys.stderr.write("usage: %s file ...\n" % sys.argv[0])
6991ddafe382 This is a trivial command line utility to print MD5 checksums.
Guido van Rossum <guido@python.org>
parents:
diff changeset
16 sys.exit(2)
6991ddafe382 This is a trivial command line utility to print MD5 checksums.
Guido van Rossum <guido@python.org>
parents:
diff changeset
17 for file in sys.argv[1:]:
6991ddafe382 This is a trivial command line utility to print MD5 checksums.
Guido van Rossum <guido@python.org>
parents:
diff changeset
18 f = open(file, "rb")
6991ddafe382 This is a trivial command line utility to print MD5 checksums.
Guido van Rossum <guido@python.org>
parents:
diff changeset
19 sum = md5.new()
6991ddafe382 This is a trivial command line utility to print MD5 checksums.
Guido van Rossum <guido@python.org>
parents:
diff changeset
20 while 1:
6991ddafe382 This is a trivial command line utility to print MD5 checksums.
Guido van Rossum <guido@python.org>
parents:
diff changeset
21 block = f.read(BLOCKSIZE)
6991ddafe382 This is a trivial command line utility to print MD5 checksums.
Guido van Rossum <guido@python.org>
parents:
diff changeset
22 if not block:
6991ddafe382 This is a trivial command line utility to print MD5 checksums.
Guido van Rossum <guido@python.org>
parents:
diff changeset
23 break
6991ddafe382 This is a trivial command line utility to print MD5 checksums.
Guido van Rossum <guido@python.org>
parents:
diff changeset
24 sum.update(block)
6991ddafe382 This is a trivial command line utility to print MD5 checksums.
Guido van Rossum <guido@python.org>
parents:
diff changeset
25 f.close()
23116
fde878bc0e3b Use 2.1's .hexdigest() method
Andrew M. Kuchling <amk@amk.ca>
parents: 18218
diff changeset
26 print sum.hexdigest(), file
18218
6991ddafe382 This is a trivial command line utility to print MD5 checksums.
Guido van Rossum <guido@python.org>
parents:
diff changeset
27
6991ddafe382 This is a trivial command line utility to print MD5 checksums.
Guido van Rossum <guido@python.org>
parents:
diff changeset
28 if __name__ == "__main__":
6991ddafe382 This is a trivial command line utility to print MD5 checksums.
Guido van Rossum <guido@python.org>
parents:
diff changeset
29 main()