Salome HOME
spns #34338: post build script is not embedded in archive
[tools/sat.git] / src / ElementTree.py
1
2
3 """
4 using VERSION 1.3.0 native xml.etree.ElementTree for python3
5 appending method tostring serialize 'pretty_xml'
6 """
7
8 import sys
9 import debug as DBG
10
11 _versionPython = sys.version_info[0]
12
13 if _versionPython < 3:
14   # python2 previous historic mode
15   import src.ElementTreePython2 as etree
16   DBG.write("ElementTree Python2 %s" % etree.VERSION, etree.__file__, DBG.isDeveloper())
17   tostring = etree.tostring
18
19 else:
20   # python3 mode
21   # import xml.etree.ElementTree as etree # native version
22   import src.ElementTreePython3 as etree # VERSION 1.3.0 plus _serialize 'pretty_xml'
23   DBG.write("ElementTree Python3 %s" % etree.VERSION, etree.__file__, DBG.isDeveloper())
24
25   def tostring(node, encoding='utf-8'):
26     """
27     fix output as str with encoding='unicode' because python3
28     If encoding is "unicode", a string is returned.
29     Otherwise a bytestring is returned
30     """
31     try:
32       aStr = etree.tostring(node, encoding='unicode', method="pretty_xml")
33     except:
34       print("*****************************\n problem node", node)
35       # try no pretty
36       aStr = etree.tostring(node, encoding='unicode')
37     # if be byte
38     # aStr = aStr.decode('utf-8')
39     return aStr
40
41 # common use
42 Element = etree.Element
43 parse = etree.parse
44