Mercurial > hg
comparison tests/md5sum.py @ 33873:904bc1dc2694
md5sum: assume hashlib exists now that we're 2.7 only
author | Augie Fackler <raf@durin42.com> |
---|---|
date | Tue, 22 Aug 2017 14:57:10 -0400 |
parents | 3a64ac39b893 |
children | 2372284d9457 |
comparison
equal
deleted
inserted
replaced
33872:5d9890d8ca77 | 33873:904bc1dc2694 |
---|---|
6 # of the PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2, which is | 6 # of the PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2, which is |
7 # GPL-compatible. | 7 # GPL-compatible. |
8 | 8 |
9 from __future__ import absolute_import | 9 from __future__ import absolute_import |
10 | 10 |
11 import hashlib | |
11 import os | 12 import os |
12 import sys | 13 import sys |
13 | |
14 try: | |
15 import hashlib | |
16 md5 = hashlib.md5 | |
17 except ImportError: | |
18 import md5 | |
19 md5 = md5.md5 | |
20 | 14 |
21 try: | 15 try: |
22 import msvcrt | 16 import msvcrt |
23 msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY) | 17 msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY) |
24 msvcrt.setmode(sys.stderr.fileno(), os.O_BINARY) | 18 msvcrt.setmode(sys.stderr.fileno(), os.O_BINARY) |
30 fp = open(filename, 'rb') | 24 fp = open(filename, 'rb') |
31 except IOError as msg: | 25 except IOError as msg: |
32 sys.stderr.write('%s: Can\'t open: %s\n' % (filename, msg)) | 26 sys.stderr.write('%s: Can\'t open: %s\n' % (filename, msg)) |
33 sys.exit(1) | 27 sys.exit(1) |
34 | 28 |
35 m = md5() | 29 m = hashlib.md5() |
36 try: | 30 try: |
37 for data in iter(lambda: fp.read(8192), b''): | 31 for data in iter(lambda: fp.read(8192), b''): |
38 m.update(data) | 32 m.update(data) |
39 except IOError as msg: | 33 except IOError as msg: |
40 sys.stderr.write('%s: I/O error: %s\n' % (filename, msg)) | 34 sys.stderr.write('%s: I/O error: %s\n' % (filename, msg)) |