fix deprecation warning in ElementTree (#27317)

This commit is contained in:
Benjamin Dauvergne 2018-10-04 23:26:48 +02:00
parent 16571e6ff8
commit edc28522f1
6 changed files with 20 additions and 20 deletions

View File

@ -257,12 +257,12 @@ class Field(object):
continue
if el is None:
continue
if el.getchildren():
if list(el):
if type(getattr(self, attribute)) is list:
v = [x.text.encode(charset) for x in el.getchildren()]
v = [x.text.encode(charset) for x in el]
elif type(getattr(self, attribute)) is dict:
v = {}
for e in el.getchildren():
for e in el:
v[e.tag] = e.text.encode(charset)
else:
print 'currently:', self.__dict__

View File

@ -1063,7 +1063,7 @@ class FormDef(StorableObject):
roles_node = tree.find(node_name)
roles = []
setattr(formdef, attr_name, roles)
for child in roles_node.getchildren():
for child in roles_node:
role_id = None
value = child.text.encode(charset)
if value.startswith('_') or value == 'logged-users':
@ -1084,7 +1084,7 @@ class FormDef(StorableObject):
if tree.find('roles') is not None:
roles_node = tree.find('roles')
formdef.workflow_roles = {}
for child in roles_node.getchildren():
for child in roles_node:
role_key = child.attrib['role_key']
role_id = None
value = child.text.encode(charset)
@ -1106,7 +1106,7 @@ class FormDef(StorableObject):
if tree.find('geolocations') is not None:
geolocations_node = tree.find('geolocations')
formdef.geolocations = {}
for child in geolocations_node.getchildren():
for child in geolocations_node:
geoloc_key = child.attrib['key']
geoloc_value = child.text.encode(charset)
formdef.geolocations[geoloc_key] = geoloc_value
@ -1114,7 +1114,7 @@ class FormDef(StorableObject):
if tree.find('required_authentication_contexts') is not None:
node = tree.find('required_authentication_contexts')
formdef.required_authentication_contexts = []
for child in node.getchildren():
for child in node:
formdef.required_authentication_contexts.append(str(child.text))
return formdef

View File

@ -869,16 +869,16 @@ class QommonPublisher(Publisher, object):
return
cfg = {}
for elem in tree.getroot().getchildren():
for elem in tree.getroot():
sub_cfg = {}
cfg[elem.tag] = sub_cfg
for child in elem.getchildren():
for child in elem:
sub_cfg[child.tag] = None
if child.getchildren():
if child.getchildren()[0].tag == 'item':
if list(child):
if list(child)[0].tag == 'item':
# list
sub_cfg[child.tag] = []
for c in child.getchildren():
for c in child:
if c.text in ('True', 'False'):
value = (c.text == 'True')
else:
@ -887,7 +887,7 @@ class QommonPublisher(Publisher, object):
else:
# dict
sub_cfg[child.tag] = {}
for c in child.getchildren():
for c in child:
if c.text in ('True', 'False'):
value = (c.text == 'True')
else:

View File

@ -53,11 +53,11 @@ for icon_id, icon_name in mapping.items():
tree = ET.fromstring(file(svg_path).read())
author = None
for elem in tree.getchildren():
for elem in tree:
if elem.tag == '{http://www.w3.org/2000/svg}text' and elem.text.startswith('Created by'):
author = elem.text[len('Created by')+1:]
tree.remove(elem)
for elem in tree.getchildren():
for elem in tree:
if elem.tag == '{http://www.w3.org/2000/svg}text' and 'Noun Project' in elem.text:
tree.remove(elem)

View File

@ -443,7 +443,7 @@ class ExportToModel(WorkflowStatusItem):
continue
if not hasattr(variable_image, 'get_content'):
continue
image = [x for x in node.getchildren() if x.tag == DRAW_IMAGE][0]
image = [x for x in node if x.tag == DRAW_IMAGE][0]
new_images[image.attrib.get(XLINK_HREF)] = variable_image
for attr in ('text', 'tail'):

View File

@ -818,12 +818,12 @@ class XmlSerialisable(object):
continue
if el is None:
continue
if el.getchildren():
if list(el):
if type(getattr(self, attribute)) is list:
v = [x.text.encode(charset) for x in el.getchildren()]
v = [x.text.encode(charset) for x in el]
elif type(getattr(self, attribute)) is dict:
v = {}
for e in el.getchildren():
for e in el:
v[e.tag] = e.text.encode(charset)
else:
# ???
@ -863,7 +863,7 @@ class XmlSerialisable(object):
setattr(self, attribute, [])
else:
imported_roles = []
for child in elem.getchildren():
for child in elem:
imported_roles.append(self._get_role_id_from_xml(child,
charset, include_id=include_id))
setattr(self, attribute, imported_roles)