from xml.etree import ElementTree as ET
from lib.core.decorators import locked
from lib.core.settings import (
COMMAND,
DEFAULT_ENCODING,
START_TIME,
)
from lib.report.factory import BaseReport, FileReportMixin
class XMLReport(FileReportMixin, BaseReport):
__format__ = "xml"
__extension__ = "xml"
def new(self):
return ET.Element("dirsearchscan", args=COMMAND, time=START_TIME)
def parse(self, file):
return ET.parse(file).getroot()
@locked
def save(self, file, result):
root = self.parse(file)
target = ET.SubElement(root, "result", url=result.url)
ET.SubElement(target, "status").text = str(result.status)
ET.SubElement(target, "contentLength").text = str(result.length)
ET.SubElement(target, "contentType").text = result.type
ET.SubElement(target, "redirect").text = result.redirect
self.write(file, root)
def write(self, file, root):
ET.indent(root)
xml_ = ET.tostring(root, encoding=DEFAULT_ENCODING, method="xml").decode()
super().write(file, xml_)