def calculate_sha256(body, as_hex=False):
 checksum = hashlib.sha256()
 for chunk in iter((lambda : body.read((1024 * 1024))), ''):
  checksum.update(chunk)
 if as_hex:
  return checksum.hexdigest()
 else:
  return checksum.digest()

def calculate_sha256 ( body , as_hex = False ) : checksum = hashlib . sha256 ( ) for chunk in iter ( ( lambda : body . read ( ( 1024 * 1024 ) ) ) , '' ) : checksum . update ( chunk ) if as_hex : return checksum . hexdigest ( ) else : return checksum . digest ( )
calculate a sha256 checksum .