Commit 06930540 authored by Vincent Ardisson's avatar Vincent Ardisson Committed by Vincent A

lxml: replace deprecated etree getiterator/getchildren

These methods were deprecated in stdlib xml.etree and also in lxml, and
are ultimately removed in python 3.9.
parent c19a0f02
Pipeline #3379 passed with stages
in 25 minutes and 45 seconds
......@@ -36,8 +36,8 @@ class ChannelsPage(XMLPage):
Extract all possible channels (paths) from the page
"""
channels = list()
for elem in self.doc[2].getchildren():
for e in elem.getchildren():
for elem in self.doc[2]:
for e in elem:
if e.tag == "NOM":
fid, name = self._clean_name(e.text)
channels.append(Collection([fid], name))
......
......@@ -97,7 +97,7 @@ class HousingPage(XMLPage):
def build_doc(self, content):
doc = super(HousingPage, self).build_doc(content).getroot()
for elem in doc.getiterator():
for elem in doc.iter():
if not hasattr(elem.tag, 'find'):
continue
i = elem.tag.find('}')
......
......@@ -103,7 +103,7 @@ class GenericNewsPage(HTMLPage):
return __article
def drop_comments(self, base_element):
for comment in base_element.getiterator(Comment):
for comment in base_element.iter(Comment):
comment.drop_tree()
def try_remove(self, base_element, selector):
......
......@@ -129,7 +129,7 @@ class AuthorPage(HTMLPage):
def obj_description(self):
description = u''
for para in self.el.xpath('//td[has-class("t0")]')[0].getchildren():
for para in self.el.xpath('//td[has-class("t0")]')[0]:
if para.tag not in ('b', 'br'):
continue
if para.text is not None:
......
......@@ -142,7 +142,7 @@ class IndexPage(HTMLPage):
return tide
def _is_low_tide_first(self, jour):
return XPath('//tr[@id="MareeJours_%s"]/td[1]' % jour)(self)[0].getchildren()[0].tag != 'b'
return list(XPath('//tr[@id="MareeJours_%s"]/td[1]' % jour)(self)[0])[0].tag != 'b'
def _get_low_tide_value(self, AM=True, jour=0):
slow_tide_pos = 1 if self._is_low_tide_first(jour) else 2
......
......@@ -184,11 +184,11 @@ class IssuesPage(BaseIssuePage):
# No results.
return
for tr in issues.getiterator('tr'):
for tr in issues.iter('tr'):
if not tr.attrib.get('id', '').startswith('issue-'):
continue
issue = {'id': tr.attrib['id'].replace('issue-', '')}
for td in tr.getiterator('td'):
for td in tr.iter('td'):
field = td.attrib.get('class', '')
if field in ('checkbox','todo',''):
continue
......
......@@ -275,7 +275,7 @@ class AMFHSBCPage(LoggedPage, XMLPage, CodePage):
def build_doc(self, content):
doc = super(AMFHSBCPage, self).build_doc(content).getroot()
# Remove namespaces
for el in doc.getiterator():
for el in doc.iter():
if not hasattr(el.tag, 'find'):
continue
i = el.tag.find('}')
......
......@@ -38,7 +38,7 @@ class RoadMapDuration(Duration):
class DepartureTypeFilter(Filter):
def filter(self, el):
result = []
for img in el[0].getiterator(tag='img'):
for img in el[0].iter(tag='img'):
result.append(img.attrib['alt'])
return u' '.join(result)
......
......@@ -196,7 +196,7 @@ class MappedVirtKeyboard(VirtKeyboard):
map = document.find('//map[@name="%s"]' % map_id)
coords = {}
for area in map.getiterator("area"):
for area in map.iter("area"):
code = area.attrib.get(map_attr)
area_coords = []
for coord in area.attrib.get("coords").split(' ')[0].split(','):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment