<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def calc_digest(origin, algorithm="sha1", block_size=None):
 """Calculate digest of a readable object Args: origin -- a readable object for which calculate digest algorithn -- the algorithm to use. See ``hashlib.algorithms_available`` for supported algorithms. block_size -- the size of the block to read at each iteration """

    try:
        hashM = hashlib.new(algorithm)
    except ValueError:
        raise ValueError('hash algorithm not supported by the underlying platform: "{0}"'.format(algorithm))

    while True:
        chunk = origin.read(block_size) if block_size else origin.read()
        if not chunk:
            break
        hashM.update(chunk)
    return hashM.hexdigest()