Refactor code to be more readable #46

Closed
erichardson wants to merge 4 commits from refactor-code into master
Showing only changes of commit a7243bf2c1 - Show all commits

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.
Returns:
messages.Message: The parsed message object.
"""
root = ET.fromstring(xmlText)
assert root.tag == "rainforest"
child = root[0]
msgClass = messages.tagMap.get( child.tag, None )
if not msgClass:
return None
return msgClass( child )
#==========================================================================
msgClass = messages.tagMap.get(child.tag, None)
return msgClass(child) if msgClass else None