1
0
mirror of https://github.com/bkerler/edl synced 2024-11-22 05:16:24 +00:00
edl/edlclient/Library/xmlparser.py
ColdWindScholar 7f14a79019 Reformat code
Remove Some useless Codes
Replace '2018-2023' to '2018-2024'
2024-06-10 01:19:09 +08:00

51 lines
1.7 KiB
Python
Executable File

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# (c) B.Kerler 2018-2024 under GPLv3 license
# If you use my code, make sure you refer to my name
#
# !!!!! If you use this code in commercial products, your product is automatically
# GPLv3 and has to be open sourced under GPLv3 as well. !!!!!
import xml.etree.ElementTree as ET
class xmlparser:
def getresponse(self, input):
lines = input.split(b"<?xml")
content = {}
for line in lines:
if line == b'':
continue
line = b"<?xml" + line
if b"\xf0\xe9\x88\x14" in line:
line = line.replace(b"\xf0\xe9\x88\x14", b"")
parser = ET.XMLParser(encoding="utf-8")
try:
tree = ET.fromstring(line, parser=parser)
except Exception as err:
continue
e = ET.ElementTree(tree).getroot()
for atype in e.findall('response'):
for field in atype.attrib:
content[field] = atype.attrib[field]
return content
def getlog(self, input):
lines = input.split(b"<?xml")
data = []
for line in lines:
if line == b'':
continue
line = b"<?xml" + line
if b"\xf0\xe9\x88\x14" in line:
line = line.replace(b"\xf0\xe9\x88\x14", b"")
parser = ET.XMLParser(encoding="utf-8")
try:
tree = ET.fromstring(line, parser=parser)
except Exception as err:
continue
e = ET.ElementTree(tree).getroot()
for atype in e.findall('log'):
if 'value' in atype.attrib:
data.append(atype.attrib['value'])
return data