refactor parse.py
All checks were successful
Build and publish Image / build-and-push (push) Successful in 12s

make code more readable and up to standards
This commit is contained in:
2024-02-10 05:00:19 +00:00
parent 14ec31d1cc
commit a7243bf2c1

View File

@@ -1,26 +1,20 @@
#===========================================================================
#
# Parse XML messages into an object.
#
#===========================================================================
import defusedxml.ElementTree as ET
from . import messages
#==========================================================================
def parse(xmlText):
"""
Parse XML messages into an object.
# <rainForest ...>
# <[Message]>...</[Message]>
# </rainForest>
def parse( xmlText ):
root = ET.fromstring( xmlText )
assert( root.tag == "rainforest" )
Args:
xmlText (str): The XML text to parse.
child = root[0]
Returns:
messages.Message: The parsed message object.
"""
root = ET.fromstring(xmlText)
assert root.tag == "rainforest"
msgClass = messages.tagMap.get( child.tag, None )
if not msgClass:
return None
child = root[0]
return msgClass( child )
#==========================================================================
msgClass = messages.tagMap.get(child.tag, None)
return msgClass(child) if msgClass else None