#NEWLINE# def rehash( path , algo = 'sha256' , blocksize = ( 1 << 20 ) ) : #NEWLINE# #INDENT# 'Return (hash, length) for path using hashlib.new(algo)' #NEWLINE# h = hashlib . new ( algo ) #NEWLINE# length = 0 #NEWLINE# with open ( path , 'rb' ) as f : #NEWLINE# #INDENT# block = f . read ( block ) #NEWLINE# while block : #NEWLINE# #INDENT# length += len ( block ) #NEWLINE# h . update ( block ) #NEWLINE# block = f . read ( blocksize ) #NEWLINE# #UNINDENT# #UNINDENT# digest = ( 'sha256=' + urlsafe_b64encode ( h . digest ( ) ) . decode ( 'latin1' ) . rstrip ( '=' ) ) #NEWLINE# return ( digest , length )