1
|
|
|
# -*- coding: utf-8 -*- |
|
|
|
|
2
|
|
|
|
3
|
|
|
import xml.dom.minidom |
4
|
|
|
|
5
|
|
|
from defusedxml import ElementTree |
6
|
|
|
|
7
|
|
|
from .. import dumpmgr |
8
|
|
|
|
9
|
|
|
|
10
|
|
|
class TclResult: |
|
|
|
|
11
|
|
|
def __init__(self, xml: str): |
|
|
|
|
12
|
|
|
self.raw_xml = xml |
13
|
|
|
self.dumper = dumpmgr.DumpMgr() |
14
|
|
|
self.dumper.write_dump(xml) |
15
|
|
|
|
16
|
|
|
def delete_dump(self): |
|
|
|
|
17
|
|
|
self.dumper.delete_last_dump() |
18
|
|
|
|
19
|
|
|
def pretty_xml(self): |
20
|
|
|
"""Return prettified input XML with ``xml.dom.minidom``.""" |
21
|
|
|
mdx = xml.dom.minidom.parseString(self.raw_xml) |
22
|
|
|
return mdx.toprettyxml(indent=" ") |
23
|
|
|
|
24
|
|
|
class CheckResult(TclResult): |
|
|
|
|
25
|
|
|
def __init__(self, xml: str): |
|
|
|
|
26
|
|
|
super().__init__(xml) |
27
|
|
|
root = ElementTree.fromstring(xml) |
28
|
|
|
self.curef = root.find("CUREF").text |
29
|
|
|
self.fvver = root.find("VERSION").find("FV").text |
30
|
|
|
self.tvver = root.find("VERSION").find("TV").text |
31
|
|
|
self.fw_id = root.find("FIRMWARE").find("FW_ID").text |
32
|
|
|
fileinfo = root.find("FIRMWARE").find("FILESET").find("FILE") |
33
|
|
|
self.fileid = fileinfo.find("FILE_ID").text |
34
|
|
|
self.filename = fileinfo.find("FILENAME").text |
35
|
|
|
self.filesize = fileinfo.find("SIZE").text |
36
|
|
|
self.filehash = fileinfo.find("CHECKSUM").text |
37
|
|
|
|
38
|
|
|
class DownloadResult(TclResult): |
|
|
|
|
39
|
|
|
def __init__(self, xml: str): |
|
|
|
|
40
|
|
|
super().__init__(xml) |
41
|
|
|
root = ElementTree.fromstring(xml) |
42
|
|
|
file = root.find("FILE_LIST").find("FILE") |
43
|
|
|
self.fileid = file.find("FILE_ID").text |
44
|
|
|
self.fileurl = file.find("DOWNLOAD_URL").text |
45
|
|
|
s3_fileurl_node = file.find("S3_DOWNLOAD_URL") |
46
|
|
|
self.s3_fileurl = None |
47
|
|
|
if s3_fileurl_node is not None: |
48
|
|
|
self.s3_fileurl = s3_fileurl_node.text |
49
|
|
|
slave_list = root.find("SLAVE_LIST").findall("SLAVE") |
50
|
|
|
enc_list = root.find("SLAVE_LIST").findall("ENCRYPT_SLAVE") |
51
|
|
|
s3_slave_list = root.find("SLAVE_LIST").findall("S3_SLAVE") |
52
|
|
|
self.slaves = [s.text for s in slave_list] |
53
|
|
|
self.encslaves = [s.text for s in enc_list] |
54
|
|
|
self.s3_slaves = [s.text for s in s3_slave_list] |
55
|
|
|
|
56
|
|
|
class ChecksumResult(TclResult): |
|
|
|
|
57
|
|
|
def __init__(self, xml: str): |
|
|
|
|
58
|
|
|
super().__init__(xml) |
59
|
|
|
root = ElementTree.fromstring(xml) |
60
|
|
|
file = root.find("FILE_CHECKSUM_LIST").find("FILE") |
61
|
|
|
self.file_addr = file.find("ADDRESS").text |
62
|
|
|
self.sha1_enc_footer = file.find("ENCRYPT_FOOTER").text |
63
|
|
|
self.sha1_footer = file.find("FOOTER").text |
64
|
|
|
self.sha1_body = file.find("BODY").text |
65
|
|
|
|
66
|
|
|
class EncryptHeaderResult(TclResult): |
|
|
|
|
67
|
|
|
def __init__(self, contents: str): |
|
|
|
|
68
|
|
|
self.rawdata = contents |
69
|
|
|
|
The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:
If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.