def hash_infile(afile, chunk_len=8192, crypto=hashlib.md5):
 hex = None
 if os.path.isfile(afile):
  crypto_obj = crypto()
  with open(afile, u'rb') as fp:
   while True:
    data = fp.read(chunk_len)
    if (not data):
     break
    crypto_obj.update(data)
  hex = crypto_obj.hexdigest()
 return hex

def hash_infile ( afile , chunk_len = 8192 , crypto = hashlib . md5 ) : hex = None if os . path . isfile ( afile ) : crypto_obj = crypto ( ) with open ( afile , u'rb' ) as fp : while True : data = fp . read ( chunk_len ) if ( not data ) : break crypto_obj . update ( data ) hex = crypto_obj . hexdigest ( ) return hex
computes hash of a file using crypto module .