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('&', '&')
self._object.query = xml_query
评论列表
文章目录