def secure_hash(filename, hash_func=sha1):
 if ((not os.path.exists(to_bytes(filename, errors='surrogate_or_strict'))) or os.path.isdir(to_bytes(filename, errors='strict'))):
  return None
 digest = hash_func()
 blocksize = (64 * 1024)
 try:
  infile = open(to_bytes(filename, errors='surrogate_or_strict'), 'rb')
  block = infile.read(blocksize)
  while block:
   digest.update(block)
   block = infile.read(blocksize)
  infile.close()
 except IOError as e:
  raise AnsibleError(('error while accessing the file %s, error was: %s' % (filename, e)))
 return digest.hexdigest()

def secure_hash ( filename , hash_func = sha1 ) : if ( ( not os . path . exists ( to_bytes ( filename , errors = 'surrogate_or_strict' ) ) ) or os . path . isdir ( to_bytes ( filename , errors = 'strict' ) ) ) : return None digest = hash_func ( ) blocksize = ( 64 * 1024 ) try : infile = open ( to_bytes ( filename , errors = 'surrogate_or_strict' ) , 'rb' ) block = infile . read ( blocksize ) while block : digest . update ( block ) block = infile . read ( blocksize ) infile . close ( ) except IOError as e : raise AnsibleError ( ( 'error while accessing the file %s, error was: %s' % ( filename , e ) ) ) return digest . hexdigest ( )
return a secure hash hex digest of local file .