view 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
line wrap: on
line source

#! /usr/bin/env python

"""Python utility to print MD5 checksums of argument files.

Works with Python 2.1 and later.
"""

import sys, md5

BLOCKSIZE = 1024*1024

def main():
    args = sys.argv[1:]
    if not args:
        sys.stderr.write("usage: %s file ...\n" % sys.argv[0])
        sys.exit(2)
    for file in sys.argv[1:]:
        f = open(file, "rb")
        sum = md5.new()
        while 1:
            block = f.read(BLOCKSIZE)
            if not block:
                break
            sum.update(block)
        f.close()
        print sum.hexdigest(), file

if __name__ == "__main__":
    main()