def __init__(self): CodeFile.__init__(self) filepath = self.PythonFileName() if os.path.isfile(filepath): PythonParser = GenerateParserFromXSD( os.path.join(os.path.dirname(__file__), "py_ext_xsd.xsd")) xmlfile = open(filepath, 'r') pythonfile_xml = xmlfile.read() xmlfile.close() pythonfile_xml = pythonfile_xml.replace( 'xmlns="http://www.w3.org/2001/XMLSchema"', 'xmlns:xhtml="http://www.w3.org/1999/xhtml"') for cre, repl in [ (re.compile("(?<!<xhtml:p>)(?:<!\[CDATA\[)"), "<xhtml:p><![CDATA["), (re.compile("(?:]]>)(?!</xhtml:p>)"), "]]></xhtml:p>")]: pythonfile_xml = cre.sub(repl, pythonfile_xml) try: python_code, error = PythonParser.LoadXMLString(pythonfile_xml) if error is None: self.CodeFile.globals.setanyText(python_code.getanyText()) os.remove(filepath) self.CreateCodeFileBuffer(False) self.OnCTNSave() except Exception, exc: error = unicode(exc) if error is not None: self.GetCTRoot().logger.write_error( _("Couldn't import old %s file.") % self.CTNName())
def __init__(self): CodeFile.__init__(self) filepath = self.PythonFileName() if os.path.isfile(filepath): PythonParser = GenerateParserFromXSD( paths.AbsNeighbourFile(__file__, "py_ext_xsd.xsd")) xmlfile = open(filepath, 'r') pythonfile_xml = xmlfile.read() xmlfile.close() pythonfile_xml = pythonfile_xml.replace( 'xmlns="http://www.w3.org/2001/XMLSchema"', 'xmlns:xhtml="http://www.w3.org/1999/xhtml"') for cre, repl in [(re.compile("(?<!<xhtml:p>)(?:<!\[CDATA\[)"), "<xhtml:p><![CDATA["), (re.compile("(?:]]>)(?!</xhtml:p>)"), "]]></xhtml:p>")]: pythonfile_xml = cre.sub(repl, pythonfile_xml) try: python_code, error = PythonParser.LoadXMLString(pythonfile_xml) if error is None: self.CodeFile.globals.setanyText(python_code.getanyText()) os.remove(filepath) self.CreateCodeFileBuffer(False) self.OnCTNSave() except Exception, exc: error = unicode(exc) if error is not None: self.GetCTRoot().logger.write_error( _("Couldn't import old %s file.") % self.CTNName())