EventLogDataSource.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:docker-zenoss4 作者: krull 项目源码 文件源码
def set_query(self, value):
        if self._object.query != value:
            try:
                in_filter_xml = xml.dom.minidom.parseString(value)
            except ExpatError:
                self._object.query = value
                return
            for node in in_filter_xml.getElementsByTagName('Select'):
                filter_text = node.childNodes[0].data
                time_match = re.match('(.*TimeCreated)(\[.*?\])(.*)', filter_text)
                if time_match:
                    # easy to replace with our time filter
                    filter_text = time_match.group(1)+TIME_CREATED+time_match.group(3)
                else:
                    # need to insert our time filter
                    notime_match = re.match('(\*\[System\[)(.*)', filter_text)
                    filter_text = notime_match.group(1)+INSERT_TIME+notime_match.group(2)
                node.childNodes[0].data = filter_text
            xml_query = prettify_xml(in_filter_xml)
            # undo replacement of single quotes with double            
            xml_query = re.sub(r"(\w+)='(\w+)'", r'\1="\2"', xml_query)
            # remove the xml header and replace any "&" with "&"
            header = '<?xml version=\'1.0\' encoding=\'UTF-8\'?>\n'
            xml_query = xml_query.replace(header, '').replace('&amp;', '&')
            self._object.query = xml_query
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号