py_ext/PythonFileCTNMixin.py
changeset 2459 21164625b393
parent 2442 b13f021c68a5
child 2679 2783906d5792
equal deleted inserted replaced
2458:2a70d5240300 2459:21164625b393
    25 
    25 
    26 
    26 
    27 from __future__ import absolute_import
    27 from __future__ import absolute_import
    28 import os
    28 import os
    29 import re
    29 import re
       
    30 from builtins import str as text
       
    31 
    30 import util.paths as paths
    32 import util.paths as paths
    31 
       
    32 from xmlclass import GenerateParserFromXSD
    33 from xmlclass import GenerateParserFromXSD
    33 
    34 
    34 from CodeFileTreeNode import CodeFile
    35 from CodeFileTreeNode import CodeFile
    35 from py_ext.PythonEditor import PythonEditor
    36 from py_ext.PythonEditor import PythonEditor
    36 
    37 
    60 
    61 
    61             pythonfile_xml = pythonfile_xml.replace(
    62             pythonfile_xml = pythonfile_xml.replace(
    62                 'xmlns="http://www.w3.org/2001/XMLSchema"',
    63                 'xmlns="http://www.w3.org/2001/XMLSchema"',
    63                 'xmlns:xhtml="http://www.w3.org/1999/xhtml"')
    64                 'xmlns:xhtml="http://www.w3.org/1999/xhtml"')
    64             for cre, repl in [
    65             for cre, repl in [
    65                     (re.compile("(?<!<xhtml:p>)(?:<!\[CDATA\[)"), "<xhtml:p><![CDATA["),
    66                     (re.compile(r"(?<!<xhtml:p>)(?:<!\[CDATA\[)"), "<xhtml:p><![CDATA["),
    66                     (re.compile("(?:]]>)(?!</xhtml:p>)"), "]]></xhtml:p>")]:
    67                     (re.compile(r"(?:]]>)(?!</xhtml:p>)"), "]]></xhtml:p>")]:
    67                 pythonfile_xml = cre.sub(repl, pythonfile_xml)
    68                 pythonfile_xml = cre.sub(repl, pythonfile_xml)
    68 
    69 
    69             try:
    70             try:
    70                 python_code, error = PythonParser.LoadXMLString(pythonfile_xml)
    71                 python_code, error = PythonParser.LoadXMLString(pythonfile_xml)
    71                 if error is None:
    72                 if error is None:
    72                     self.CodeFile.globals.setanyText(python_code.getanyText())
    73                     self.CodeFile.globals.setanyText(python_code.getanyText())
    73                     os.remove(filepath)
    74                     os.remove(filepath)
    74                     self.CreateCodeFileBuffer(False)
    75                     self.CreateCodeFileBuffer(False)
    75                     self.OnCTNSave()
    76                     self.OnCTNSave()
    76             except Exception as exc:
    77             except Exception as exc:
    77                 error = unicode(exc)
    78                 error = text(exc)
    78 
    79 
    79             if error is not None:
    80             if error is not None:
    80                 self.GetCTRoot().logger.write_error(
    81                 self.GetCTRoot().logger.write_error(
    81                     _("Couldn't import old %s file.") % self.CTNName())
    82                     _("Couldn't import old %s file.") % self.CTNName())
    82 
    83 
   315             self.GetCTRoot().GetIECLibPath())
   316             self.GetCTRoot().GetIECLibPath())
   316 
   317 
   317         return ([(Gen_PyCfile_path, matiec_CFLAGS)],
   318         return ([(Gen_PyCfile_path, matiec_CFLAGS)],
   318                 "",
   319                 "",
   319                 True,
   320                 True,
   320                 ("runtime_%s.py" % location_str, file(runtimefile_path, "rb")))
   321                 ("runtime_%s.py" % location_str, open(runtimefile_path, "rb")))