def _set_version(self): if self.version: printdbg("Bugzilla version: %s" % self.version) return info_url = self._get_info_url(self.url) f = self._urlopen_auth(info_url) try: printdbg("Getting bugzilla version from %s" % info_url) contents = f.read() except Exception: printerr("Error retrieving URL %s" % info_url) raise f.close() handler = BugzillaHandler() parser = xml.sax.make_parser() parser.setContentHandler(handler) try: cleaned_contents = ''. \ join(c for c in contents if valid_XML_char_ordinal(ord(c))) parser.feed(cleaned_contents) except Exception: printerr("Error parsing URL %s" % info_url) raise parser.close() self.version = handler.get_version() printdbg("Bugzilla version: %s" % self.version)
def _safe_xml_parse(self, bugs_url, handler): f = self._urlopen_auth(bugs_url) parser = xml.sax.make_parser() parser.setContentHandler(handler) try: contents = f.read() except Exception: printerr("Error retrieving URL: %s" % (bugs_url)) raise try: parser.feed(contents) parser.close() except Exception: # Clean only the invalid XML try: parser2 = xml.sax.make_parser() parser2.setContentHandler(handler) parser2.setContentHandler(handler) printdbg("Cleaning dirty XML") cleaned_contents = ''. \ join(c for c in contents if valid_XML_char_ordinal(ord(c))) parser2.feed(cleaned_contents) parser2.close() except Exception: printerr("Error parsing URL: %s" % (bugs_url)) raise f.close()