refactor parse.py
All checks were successful
Build and publish Image / build-and-push (push) Successful in 12s
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:
@@ -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
|
||||
Reference in New Issue
Block a user