Пример #1
0
def process_message(message):
    """
    Process a message dict and return a Message Object
    :param message: Message dict returned by `parse_xml` function
    :return: Message Object
    """
    message["type"] = message.pop("MsgType").lower()
    message_type = MESSAGE_TYPES.get(message["type"], UnknownMessage)
    return message_type(message)
Пример #2
0
def parse_user_msg(xml):
    """
    Parse xml from wechat server and return an Message
    :param xml: raw xml from wechat server.
    :return: an Message object
    """
    if not xml:
        return

    wechat_message = dict((child.tag, to_text(child.text))
                          for child in ElementTree.fromstring(xml))
    wechat_message["raw"] = xml
    wechat_message["type"] = wechat_message.pop("MsgType").lower()

    message_type = MESSAGE_TYPES.get(wechat_message["type"], UnknownMessage)
    return message_type(wechat_message)
Пример #3
0
def parse_user_msg(xml):
    """
    Parse xml from wechat server and return an Message
    :param xml: raw xml from wechat server.
    :return: an Message object
    """
    if not xml:
        return

    root = ElementTree.fromstring(xml)
    wechat_message = dict((child.tag, to_text(child.text)) for child in root)
    locationinfo = root.find('SendLocationInfo')
    if locationinfo:
        wechat_message.pop("SendLocationInfo")
        wechat_message.update(
            dict((child.tag, to_text(child.text)) for child in locationinfo))
    wechat_message["raw"] = xml
    wechat_message["type"] = wechat_message.pop("MsgType")

    message_type = MESSAGE_TYPES.get(wechat_message["type"], UnknownMessage)
    return message_type(wechat_message)
Пример #4
0
def parse_user_msg(xml):
    """
    Parse xml from wechat server and return an Message
    :param xml: raw xml from wechat server.
    :return: an Message object
    """
    if not xml:
        return

    root = ElementTree.fromstring(xml)
    wechat_message = dict((child.tag, to_text(child.text))
                          for child in root)
    locationinfo = root.find('SendLocationInfo')
    if locationinfo:
        wechat_message.pop("SendLocationInfo")
        wechat_message.update(dict((child.tag, to_text(child.text))
                          for child in locationinfo))
    wechat_message["raw"] = xml
    wechat_message["type"] = wechat_message.pop("MsgType")

    message_type = MESSAGE_TYPES.get(wechat_message["type"], UnknownMessage)
    return message_type(wechat_message)