def safe_minidom_parse_string(xml_string): """Parse an XML string using minidom safely. """ try: return minidom.parseString(xml_string, parser=ProtectedExpatParser()) except sax.SAXParseException: raise expat.ExpatError()
def safe_minidom_parse_string(xml_string): """Parse an XML string using minidom safely. """ try: if six.PY3 and isinstance(xml_string, bytes): # On Python 3, minidom.parseString() requires Unicode when # the parser parameter is used. # # Bet that XML used in Cinder is always encoded to UTF-8. xml_string = xml_string.decode('utf-8') return minidom.parseString(xml_string, parser=ProtectedExpatParser()) except sax.SAXParseException: raise expat.ExpatError()
def feed(self, data, isfinal=False): try: self._parser.Parse(data, isfinal) except expat.ExpatError, e: e.filename = self._filename e.source = self._source try: e = 'Error parsing XML%s:\n%s%s' % ( e.filename and e.filename != '<string>' and (' file %r' % e.filename) or '', get_expat_error(e), str(e)) except Exception: pass raise expat.ExpatError(e)