Improve TipsParse for python3 support

This commit is contained in:
Jérôme Rapinat 2015-03-20 09:06:06 +01:00
parent f727d6b4a9
commit 727d96cc22

View File

@ -169,12 +169,13 @@ def TipsParse(filename, mark):
tips = open('../data/tips.xml.in.h', 'w') tips = open('../data/tips.xml.in.h', 'w')
marklist = root.iter(mark) marklist = root.iter(mark)
for key in marklist: for key in marklist:
tip = ElementTree.tostring(key, encoding="UTF-8", method="xml")
if sys.version_info[0] < 3: if sys.version_info[0] < 3:
tip = ElementTree.tostring(key, encoding="UTF-8") tip = tip.replace("<?xml version='1.0' encoding='UTF-8'?>", "")
else: # no python3 support yet tip = tip.replace('\n<_tip number="%(number)s">' % key.attrib, "")
return else: # python3 support
tip = tip.replace("<?xml version='1.0' encoding='UTF-8'?>", "") tip = tip.decode(encoding="UTF-8")
tip = tip.replace('\n<_tip number="%(number)s">' % key.attrib, "") tip = tip.replace('<_tip number="%(number)s">' % key.attrib, "")
tip = tip.replace("<br />", "<br/>") tip = tip.replace("<br />", "<br/>")
#tip = tip.replace("\n</_tip>\n", "</_tip>\n") # special case tip 7 #tip = tip.replace("\n</_tip>\n", "</_tip>\n") # special case tip 7
#tip = tip.replace("\n<b>", "<b>") # special case tip 18 #tip = tip.replace("\n<b>", "<b>") # special case tip 18