Mercurial > cpython-lru_cache-weakref
annotate Tools/scripts/md5sum.py @ 22360:c8a6ea00a9e1 legacy-trunk
restructure a bit to not rely on test case execution ordering
add test case for bug #482460
| author | Skip Montanaro <skip@pobox.com> |
|---|---|
| date | Sun, 17 Mar 2002 23:03:42 +0000 |
| parents | 6991ddafe382 |
| children | fde878bc0e3b |
| 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 |
|
6991ddafe382
This is a trivial command line utility to print MD5 checksums.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
5 Works with Python 1.5.2 and later. |
|
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 hexify(s): |
|
6991ddafe382
This is a trivial command line utility to print MD5 checksums.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
13 return ("%02x"*len(s)) % tuple(map(ord, s)) |
|
6991ddafe382
This is a trivial command line utility to print MD5 checksums.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
14 |
|
6991ddafe382
This is a trivial command line utility to print MD5 checksums.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
15 def main(): |
|
6991ddafe382
This is a trivial command line utility to print MD5 checksums.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
16 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
|
17 if not args: |
|
6991ddafe382
This is a trivial command line utility to print MD5 checksums.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
18 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
|
19 sys.exit(2) |
|
6991ddafe382
This is a trivial command line utility to print MD5 checksums.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
20 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
|
21 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
|
22 sum = md5.new() |
|
6991ddafe382
This is a trivial command line utility to print MD5 checksums.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
23 while 1: |
|
6991ddafe382
This is a trivial command line utility to print MD5 checksums.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
24 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
|
25 if not block: |
|
6991ddafe382
This is a trivial command line utility to print MD5 checksums.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
26 break |
|
6991ddafe382
This is a trivial command line utility to print MD5 checksums.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
27 sum.update(block) |
|
6991ddafe382
This is a trivial command line utility to print MD5 checksums.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
28 f.close() |
|
6991ddafe382
This is a trivial command line utility to print MD5 checksums.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
29 print hexify(sum.digest()), file |
|
6991ddafe382
This is a trivial command line utility to print MD5 checksums.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
30 |
|
6991ddafe382
This is a trivial command line utility to print MD5 checksums.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
31 if __name__ == "__main__": |
|
6991ddafe382
This is a trivial command line utility to print MD5 checksums.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
32 main() |
