From adac46441d8bccab40dafcabfb9293823cbc5e10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Rapinat?= Date: Mon, 1 Oct 2012 09:51:47 +0000 Subject: [PATCH] try to support python 2.7 for iteration with ElementTree svn: r20477 --- po/update_po.py | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/po/update_po.py b/po/update_po.py index 40e2b8fd8..f670f8dd2 100644 --- a/po/update_po.py +++ b/po/update_po.py @@ -93,15 +93,6 @@ def TipsParse(filename, mark): tree = ElementTree.parse(filename) root = tree.getroot() - - python_v = sys.version_info - - #if python_v[1] != 6: - - # python 2.7 - # iter() is the new name for getiterator; - # in ET 1.3, it is implemented as a generator method, - # but is otherwise identical ''' @@ -132,7 +123,13 @@ def TipsParse(filename, mark): ''' tips = open('../gramps/data/tips.xml.in.h', 'w') + + # python 2.7 + # iter() is the new name for getiterator; + # in ET 1.3, it is implemented as a generator method, + # but is otherwise identical + # it works with python 2.6 only ! for key in root.getiterator(mark): tip = ElementTree.tostring(key, encoding="UTF-8") tip = tip.replace("", "") @@ -160,13 +157,18 @@ def HolidaysParse(filename, mark): root = tree.getroot() python_v = sys.version_info - - #if python_v[1] != 6: - + # python 2.7 # iter() is the new name for getiterator; # in ET 1.3, it is implemented as a generator method, # but is otherwise identical + + # getiterator() for python 2.6 + ITERATION = root.getiterator() + + # iter() for python 2.7 and greater versions + if sys.version_info[1] ==7: + ITERATION = root.iter() ''' @@ -188,7 +190,7 @@ def HolidaysParse(filename, mark): holidays = open('../gramps/plugins/lib/holidays.xml.in.h', 'w') - for key in root.getiterator(): + for key in ITERATION: if key.attrib.get(mark): line = key.attrib string = line.items