#NEWLINE# def get_hash( path , form = 'sha1' , chunk_size = 4096 ) : #NEWLINE# #INDENT# 'Generate a hash digest string for a file.' #NEWLINE# try : #NEWLINE# #INDENT# hash_type = getattr ( hashlib , form ) #NEWLINE# #UNINDENT# except AttributeError : #NEWLINE# #INDENT# raise ValueError ( 'Invalid hash type: {0}' . format ( form ) ) #NEWLINE# #UNINDENT# with open ( path , 'rb' ) as ifile : #NEWLINE# #INDENT# hash_obj = hash_type ( ) #NEWLINE# for chunk in iter ( ( lambda : ifile . read ( chunk_size ) ) , b'' ) : #NEWLINE# #INDENT# hash_obj . update ( chunk ) #NEWLINE# #UNINDENT# return hash_obj . hexdigest ( )