def parse_message(xml):
if not xml:<EOL><INDENT>return<EOL><DEDENT>message = xmltodict.parse(to_text(xml))['<STR_LIT>']<EOL>message_type = message['<STR_LIT>'].lower()<EOL>event_type = None<EOL>if message_type == '<STR_LIT>' or message_type.startswith('<STR_LIT>'):<EOL><INDENT>if '<STR_LIT>' in message:<EOL><INDENT>event_type = message['<STR_LIT>'].lower()<EOL><DEDENT>if event_type is None and message_type.startswith('<STR_LIT>'):<EOL><INDENT>event_type = message_type<EOL><DEDENT>elif message_type.startswith('<STR_LIT>'):<EOL><INDENT>event_type = '<STR_LIT>'.format(event=event_type)<EOL><DEDENT>if event_type == '<STR_LIT>' and message.get('<STR_LIT>'):<EOL><INDENT>event_key = message['<STR_LIT>']<EOL>if event_key.startswith(('<STR_LIT>', '<STR_LIT>')):<EOL><INDENT>event_type = '<STR_LIT>'<EOL>message['<STR_LIT>'] = event_type<EOL><DEDENT>elif event_key.startswith('<STR_LIT>'):<EOL><INDENT>event_type = '<STR_LIT>'<EOL>message['<STR_LIT>'] = event_type<EOL>message['<STR_LIT>'] = event_key[len('<STR_LIT>'):]<EOL><DEDENT><DEDENT>message_class = EVENT_TYPES.get(event_type, UnknownMessage)<EOL><DEDENT>else:<EOL><INDENT>message_class = MESSAGE_TYPES.get(message_type, UnknownMessage)<EOL><DEDENT>return message_class(message)<EOL>
解析微信服务器推送的 XML 消息

:param xml: XML 消息
:return: 解析成功返回对应的消息或事件，否则返回 ``UnknownMessage``