From 8a9f83410fc20fc9540bc833f582d95bc12ebfdb Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Thu, 4 Oct 2018 23:26:48 +0200 Subject: [PATCH 1/5] fix deprecation warning in ElementTree --- wcs/fields.py | 6 +++--- wcs/formdef.py | 8 ++++---- wcs/qommon/publisher.py | 12 ++++++------ wcs/qommon/static/images/categories/generate.py | 4 ++-- wcs/wf/export_to_model.py | 2 +- wcs/workflows.py | 8 ++++---- 6 files changed, 20 insertions(+), 20 deletions(-) diff --git a/wcs/fields.py b/wcs/fields.py index 1b33451b..8672d23a 100644 --- a/wcs/fields.py +++ b/wcs/fields.py @@ -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__ diff --git a/wcs/formdef.py b/wcs/formdef.py index eee25230..63c79bb9 100644 --- a/wcs/formdef.py +++ b/wcs/formdef.py @@ -1040,7 +1040,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': @@ -1061,7 +1061,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) @@ -1083,7 +1083,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 @@ -1091,7 +1091,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 diff --git a/wcs/qommon/publisher.py b/wcs/qommon/publisher.py index f1f91ed8..55eedd05 100644 --- a/wcs/qommon/publisher.py +++ b/wcs/qommon/publisher.py @@ -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: diff --git a/wcs/qommon/static/images/categories/generate.py b/wcs/qommon/static/images/categories/generate.py index 00bb6cfa..f399bd04 100644 --- a/wcs/qommon/static/images/categories/generate.py +++ b/wcs/qommon/static/images/categories/generate.py @@ -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) diff --git a/wcs/wf/export_to_model.py b/wcs/wf/export_to_model.py index e30e52a6..c7a034cf 100644 --- a/wcs/wf/export_to_model.py +++ b/wcs/wf/export_to_model.py @@ -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'): diff --git a/wcs/workflows.py b/wcs/workflows.py index 5e154e43..0f723db5 100644 --- a/wcs/workflows.py +++ b/wcs/workflows.py @@ -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) -- 2.18.0