From 0feaf905e30d1d190c0cf973ffa5b4f08636b136 Mon Sep 17 00:00:00 2001 From: Cas Cremers Date: Wed, 2 Jun 2021 08:56:23 +0200 Subject: [PATCH] Fix deprecated use of elementtree XML objects' getchildren method. --- gui/Scyther/XMLReader.py | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/gui/Scyther/XMLReader.py b/gui/Scyther/XMLReader.py index f78f12a..487b9b5 100644 --- a/gui/Scyther/XMLReader.py +++ b/gui/Scyther/XMLReader.py @@ -20,17 +20,6 @@ # # XMLReader # -# Note: -# This requires python elementtree to work -# See: http://effbot.org/zone/element-index.htm -# -# On Fedora Core you can install this by installing the python-elementtree rpm -# Things will be a lot faster and consume less memory if you install the -# cElementTree module -# -# In python 2.5 cElementTree is in the core, so you don't need to install -# extra packages -# import sys @@ -69,7 +58,13 @@ from . import Term from . import Attack from . import Trace from . import Claim - + +def getchildren(xml): + """ + (c)elementree xml objects used to have a getchildren() method, but this has been deprecated. This function provides similar functionality. The only catch is that the list/iter replacements also contain the object itself, so we need to filter this. + """ + return [ x for x in list(xml) if x != xml ] + class XMLReader(object): def __init__ (self): @@ -123,8 +118,8 @@ class XMLReader(object): # If this is a term variable read it directly if (xml.tag in ('tuple','const','apply','encrypt','var')): return self.readSubTerm(xml) - # Otherwise read from it's first child - children = xml.getchildren() + # Otherwise read from its first child + children = getchildren(xml) assert(len(children) == 1) return self.readSubTerm(children[0]) @@ -249,7 +244,7 @@ class XMLReader(object): def readClaim(self, xml): claim = Claim.Claim() - for event in xml.getchildren(): + for event in getchildren(xml): if event.tag == 'claimtype': claim.claimtype = self.readTerm(event) elif event.tag == 'label': @@ -288,7 +283,7 @@ class XMLReader(object): # A state contains 4 direct child nodes: # broken, system, variables and semitrace # optionally a fifth: dot - for event in xml.getchildren(): + for event in getchildren(xml): if event.tag == 'broken': attack.broken.append((self.readTerm(event.find('claim')), self.readTerm(event.find('label'))))