def _decode_file(path):
 fp = open(path, 'r')
 txt = fp.readline()
 m = re.search('#encoding[:\\s]+(\\S+)', txt)
 if (m and m.group(1)):
  encoding = m.group(1)
 else:
  encoding = 'latin-1'
 source = fp.read()
 fp.close()
 try:
  return source.decode(encoding)
 except:
  return ''

def _decode_file ( path ) : fp = open ( path , 'r' ) txt = fp . readline ( ) m = re . search ( '#encoding[:\\s]+(\\S+)' , txt ) if ( m and m . group ( 1 ) ) : encoding = m . group ( 1 ) else : encoding = 'latin-1' source = fp . read ( ) fp . close ( ) try : return source . decode ( encoding ) except : return ''
return content of file in unicode string using encoding as specified in the file .