Total Complexity | 4 |
Total Lines | 40 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | # -*- coding: utf-8 -*- |
||
|
|||
2 | |||
3 | import json |
||
4 | from defusedxml import ElementTree |
||
5 | |||
6 | class TclChecksumMixin: |
||
7 | def do_checksum(self, encslave, address, uri): |
||
8 | url = "http://" + encslave + "/checksum.php" |
||
9 | params = self.get_creds2() |
||
10 | |||
11 | payload = {address: uri} |
||
12 | payload_json = json.dumps(payload) |
||
13 | params[b"address"] = bytes(payload_json, "utf-8") |
||
14 | |||
15 | #print(repr(dict(params))) |
||
16 | req = self.sess.post(url, data=params) |
||
17 | if req.status_code == 200: |
||
18 | req.encoding = "utf-8" # Force encoding as server doesn't give one |
||
1 ignored issue
–
show
|
|||
19 | self.write_dump(req.text) |
||
20 | # <ENCRYPT_FOOTER>2abfa6f6507044fec995efede5d818e62a0b19b5</ENCRYPT_FOOTER> means ERROR (invalid ADDRESS!) |
||
1 ignored issue
–
show
|
|||
21 | if "<ENCRYPT_FOOTER>2abfa6f6507044fec995efede5d818e62a0b19b5</ENCRYPT_FOOTER>" in req.text: |
||
1 ignored issue
–
show
|
|||
22 | print("INVALID URI: {}".format(uri)) |
||
23 | raise SystemExit |
||
24 | return req.text |
||
25 | else: |
||
26 | print("CHECKSUM: " + repr(req)) |
||
27 | print(repr(req.headers)) |
||
28 | print(repr(req.text)) |
||
29 | raise SystemExit |
||
30 | |||
31 | @staticmethod |
||
32 | def parse_checksum(xmlstr): |
||
33 | root = ElementTree.fromstring(xmlstr) |
||
34 | file = root.find("FILE_CHECKSUM_LIST").find("FILE") |
||
35 | file_addr = file.find("ADDRESS").text |
||
36 | sha1_enc_footer = file.find("ENCRYPT_FOOTER").text |
||
37 | sha1_footer = file.find("FOOTER").text |
||
38 | sha1_body = file.find("BODY").text |
||
39 | return file_addr, sha1_body, sha1_enc_footer, sha1_footer |
||
40 |
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.