code: def calc_digest(origin, algorithm="sha1", block_size=None):
      
      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()
docs: 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