Mercurial > hgrepos > Python > apps > py-cutils
comparison shasum.py @ 4:67d10529ce88
FIX: "-" filename handling now consistent with Perl shasum
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Fri, 04 Dec 2020 12:37:29 +0100 |
| parents | 5a6ed622846c |
| children | bbcb225640de |
comparison
equal
deleted
inserted
replaced
| 3:5a6ed622846c | 4:67d10529ce88 |
|---|---|
| 40 if opts.text_mode: | 40 if opts.text_mode: |
| 41 print("ERROR: text mode not supported", file=sys.stderr) | 41 print("ERROR: text mode not supported", file=sys.stderr) |
| 42 sys.exit(78) # :manpage:`sysexits(3)` EX_CONFIG | 42 sys.exit(78) # :manpage:`sysexits(3)` EX_CONFIG |
| 43 if not opts.files: | 43 if not opts.files: |
| 44 opts.files.append("-") | 44 opts.files.append("-") |
| 45 for fn in opts.files: | 45 if len(opts.files) == 1 and opts.files[0] == "-": |
| 46 if fn == "-": | 46 if PY2: |
| 47 if PY2: | 47 if sys.platform == "win32": |
| 48 if sys.platform == "win32": | 48 import os. msvcrt |
| 49 import os. msvcrt | 49 msvcrt.setmode(sys.stdin.fileno(), os.O_BINARY) |
| 50 msvcrt.setmode(sys.stdin.fileno(), os.O_BINARY) | 50 source = sys.stdin |
| 51 source = sys.stdin | |
| 52 else: | |
| 53 source = sys.stdin.buffer | |
| 54 print(compute_digest(hashlib.sha256, source)) | |
| 55 else: | 51 else: |
| 52 source = sys.stdin.buffer | |
| 53 print(compute_digest(hashlib.sha256, source)) | |
| 54 else: | |
| 55 for fn in opts.files: | |
| 56 with open(fn, "rb") as source: | 56 with open(fn, "rb") as source: |
| 57 print(compute_digest(hashlib.sha256, source)) | 57 print(compute_digest(hashlib.sha256, source)) |
| 58 | 58 |
| 59 | 59 |
| 60 def compute_digest(hashobj, instream): | 60 def compute_digest(hashobj, instream): |
