parameters: (filename)
return_statement: return True
docstring: read in file, screen out unsafe unicode characters, write back file in utf-8
  
      :param filename: str
      :returns: False if unable to read from file
docstring_summary: read in file, screen out unsafe unicode characters, write back file in utf-8
docstring_tokens: read in file screen out unsafe unicode characters write back file in utf - 8
function: def tidy_xml(filename):
      '''
      read in file, screen out unsafe unicode characters, write back file in utf-8
  
      :param filename: str
      :returns: False if unable to read from file
      '''
      if not os.path.isfile(filename):
          raise ValueError('file does not exist')
  
      # try first utf-8 then iso. This is ugly, but the files in
      # question that are problematic do not declare unicode type
      data = None
      for ftype in ['utf-8', 'iso8859-1']:
          fhand = None
          try:
              fhand = codecs.open(filename, 'r', ftype)
              data = fhand.read()
              break
          except ValueError:
              continue
          finally:
              if fhand is not None:
                  fhand.close()
  
      if data is None:
          return False
  
      for match in _SAFE_XML_REGEX.finditer(data):
          data = data[:match.start()] + '?' + data[match.end():]
  
      with open(filename, 'w') as fhand:
          fhand.write(data)
      return True
function_tokens: def tidy_xml ( filename ) : if not os . path . isfile ( filename ) : raise ValueError ( 'file does not exist' ) # try first utf-8 then iso. This is ugly, but the files in # question that are problematic do not declare unicode type data = None for ftype in [ 'utf-8' , 'iso8859-1' ] : fhand = None try : fhand = codecs . open ( filename , 'r' , ftype ) data = fhand . read ( ) break except ValueError : continue finally : if fhand is not None : fhand . close ( ) if data is None : return False for match in _SAFE_XML_REGEX . finditer ( data ) : data = data [ : match . start ( ) ] + '?' + data [ match . end ( ) : ] with open ( filename , 'w' ) as fhand : fhand . write ( data ) return True