Fix deprecated use of elementtree XML objects' getchildren method.

This commit is contained in:
Cas Cremers 2021-06-02 08:56:23 +02:00
parent 52fe41d421
commit 0feaf905e3

View File

@ -20,17 +20,6 @@
# #
# XMLReader # 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 import sys
@ -70,6 +59,12 @@ from . import Attack
from . import Trace from . import Trace
from . import Claim 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): class XMLReader(object):
def __init__ (self): def __init__ (self):
@ -123,8 +118,8 @@ class XMLReader(object):
# If this is a term variable read it directly # If this is a term variable read it directly
if (xml.tag in ('tuple','const','apply','encrypt','var')): if (xml.tag in ('tuple','const','apply','encrypt','var')):
return self.readSubTerm(xml) return self.readSubTerm(xml)
# Otherwise read from it's first child # Otherwise read from its first child
children = xml.getchildren() children = getchildren(xml)
assert(len(children) == 1) assert(len(children) == 1)
return self.readSubTerm(children[0]) return self.readSubTerm(children[0])
@ -249,7 +244,7 @@ class XMLReader(object):
def readClaim(self, xml): def readClaim(self, xml):
claim = Claim.Claim() claim = Claim.Claim()
for event in xml.getchildren(): for event in getchildren(xml):
if event.tag == 'claimtype': if event.tag == 'claimtype':
claim.claimtype = self.readTerm(event) claim.claimtype = self.readTerm(event)
elif event.tag == 'label': elif event.tag == 'label':
@ -288,7 +283,7 @@ class XMLReader(object):
# A state contains 4 direct child nodes: # A state contains 4 direct child nodes:
# broken, system, variables and semitrace # broken, system, variables and semitrace
# optionally a fifth: dot # optionally a fifth: dot
for event in xml.getchildren(): for event in getchildren(xml):
if event.tag == 'broken': if event.tag == 'broken':
attack.broken.append((self.readTerm(event.find('claim')), attack.broken.append((self.readTerm(event.find('claim')),
self.readTerm(event.find('label')))) self.readTerm(event.find('label'))))