import hashlib


def compute_md5(file_to_checksum, chunk_size=1024*64):
    """Computes MD5 checksum of specified file.

    file_to_checksum should be an open, readable, file handle, with
    its position at the beginning, i.e. so that .read() gets the
    entire contents of the file.
    NOTE: under python3, the file should have been open in binary mode ("rb")
    so that bytes (not strings) are returned when iterating over the file.
    """
    md5gen = hashlib.md5()
    while True:
        chunk = file_to_checksum.read(chunk_size)
        if not chunk:
            return md5gen.hexdigest()
        md5gen.update(chunk)