# Path: wxpy/utils/misc.py
# def match_attributes(obj, **attributes):
#     """
#     判断对象是否匹配输入的属性条件
# 
#     :param obj: 对象
#     :param attributes: 属性键值对
#     :return: 若匹配则为 True，否则为 False
#     """
# 
#     has_raw = hasattr(obj, 'raw')
# 
#     for attr, value in attributes.items():
#         if (getattr(obj, attr, None) or (obj.raw.get(attr) if has_raw else None)) != value:
#             return False
#     return True
# 
# def match_text(text, keywords):
#     """
#     判断文本内容中是否包含了所有的关键词 (不区分大小写)
# 
#     :param text: 文本内容
#     :param keywords: 关键词，可以是空白分割的 str，或是多个精准关键词组成的 list
#     :return: 若包含了所有的关键词则为 True，否则为 False
#     """
# 
#     if not text:
#         text = ''
#     else:
#         text = text.lower()
# 
#     keywords = prepare_keywords(keywords)
# 
#     for kw in keywords:
#         if kw not in text:
#             return False
#     return True


import threading
from wxpy.utils import match_attributes, match_text
    """
    多条消息的合集，可用于记录或搜索
    """

    def __init__(self, msg_list=None, max_history=200):
        if msg_list:
            super(Messages, self).__init__(msg_list)
        self.max_history = max_history
        self._thread_lock = threading.Lock()

    def append(self, msg):
        """
        仅当 self.max_history 为 int 类型，且大于 0 时才保存历史消息
        """
        with self._thread_lock:
            if isinstance(self.max_history, int) and self.max_history > 0:
                del self[:-self.max_history + 1]
                return super(Messages, self).append(msg)

    def search(self, keywords=None, **attributes):
        """
        搜索消息记录

        :param keywords: 文本关键词
        :param attributes: 属性键值对
        :return: 所有匹配的消息
        :rtype: :class:`wxpy.Messages`
        """

        def match(msg):

# Path: wxpy/utils/misc.py
# def match_attributes(obj, **attributes):
#     """
#     判断对象是否匹配输入的属性条件
# 
#     :param obj: 对象
#     :param attributes: 属性键值对
#     :return: 若匹配则为 True，否则为 False
#     """
# 
#     has_raw = hasattr(obj, 'raw')
# 
#     for attr, value in attributes.items():
#         if (getattr(obj, attr, None) or (obj.raw.get(attr) if has_raw else None)) != value:
#             return False
#     return True
# 
# def match_text(text, keywords):
#     """
#     判断文本内容中是否包含了所有的关键词 (不区分大小写)
# 
#     :param text: 文本内容
#     :param keywords: 关键词，可以是空白分割的 str，或是多个精准关键词组成的 list
#     :return: 若包含了所有的关键词则为 True，否则为 False
#     """
# 
#     if not text:
#         text = ''
#     else:
#         text = text.lower()
# 
#     keywords = prepare_keywords(keywords)
# 
#     for kw in keywords:
#         if kw not in text:
#             return False
#     return True


# Path: wxpy/api/messages/messages.py
import threading
from wxpy.utils import match_attributes, match_text

    """
    多条消息的合集，可用于记录或搜索
    """

    def __init__(self, msg_list=None, max_history=200):
        if msg_list:
            super(Messages, self).__init__(msg_list)
        self.max_history = max_history
        self._thread_lock = threading.Lock()

    def append(self, msg):
        """
        仅当 self.max_history 为 int 类型，且大于 0 时才保存历史消息
        """
        with self._thread_lock:
            if isinstance(self.max_history, int) and self.max_history > 0:
                del self[:-self.max_history + 1]
                return super(Messages, self).append(msg)

    def search(self, keywords=None, **attributes):
        """
        搜索消息记录

        :param keywords: 文本关键词
        :param attributes: 属性键值对
        :return: 所有匹配的消息
        :rtype: :class:`wxpy.Messages`
        """

        def match(msg):

            if not match_text(msg.text, keywords):