def _read_file_safe_xml(test_file, write_back_sanitized=True):
 f = None
 try:
  if (not os.path.isfile(test_file)):
   raise Exception('test file does not exist')
  try:
   f = codecs.open(test_file, 'r', 'utf-8')
   x = f.read()
  except:
   if (f is not None):
    f.close()
   f = codecs.open(test_file, 'r', 'iso8859-1')
   x = f.read()
  for match in _safe_xml_regex.finditer(x):
   x = ((x[:match.start()] + '?') + x[match.end():])
  x = x.encode('utf-8')
  if write_back_sanitized:
   with open(test_file, 'wb') as h:
    h.write(x)
  return x
 finally:
  if (f is not None):
   f.close()

def _read_file_safe_xml ( test_file , write_back_sanitized = True ) : f = None try : if ( not os . path . isfile ( test_file ) ) : raise Exception ( 'test file does not exist' ) try : f = codecs . open ( test_file , 'r' , 'utf-8' ) x = f . read ( ) except : if ( f is not None ) : f . close ( ) f = codecs . open ( test_file , 'r' , 'iso8859-1' ) x = f . read ( ) for match in _safe_xml_regex . finditer ( x ) : x = ( ( x [ : match . start ( ) ] + '?' ) + x [ match . end ( ) : ] ) x = x . encode ( 'utf-8' ) if write_back_sanitized : with open ( test_file , 'wb' ) as h : h . write ( x ) return x finally : if ( f is not None ) : f . close ( )
read in file .