Total Complexity | 6 |
Total Lines | 43 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | # -*- coding: utf-8 -*- |
||
|
|||
2 | |||
3 | from collections import OrderedDict |
||
4 | import json |
||
5 | from .. import credentials, devices |
||
6 | from .tclrequest import TclRequest |
||
7 | from .tclresult import ChecksumResult |
||
8 | |||
9 | class ChecksumRequest(TclRequest): |
||
10 | def __init__(self, address, file_uri): |
||
11 | super().__init__() |
||
12 | # NOTE: THIS HAS TO BE RUN ON AN ENCSLAVE |
||
13 | self.uri = "/checksum.php" |
||
14 | self.method = "POST" |
||
15 | self.address = address |
||
16 | self.file_uri = file_uri |
||
17 | |||
18 | def get_headers(self): |
||
19 | return {"User-Agent": "tcl"} |
||
20 | |||
21 | def get_params(self): |
||
22 | params = OrderedDict() |
||
23 | params.update(credentials.get_creds2()) |
||
24 | payload = {self.address: self.file_uri} |
||
25 | payload_json = json.dumps(payload) |
||
26 | params["address"] = bytes(payload_json, "utf-8") |
||
27 | return params |
||
28 | |||
29 | def is_done(self, http_status: int, contents: str) -> bool: |
||
30 | if http_status == 200: |
||
31 | # <ENCRYPT_FOOTER>2abfa6f6507044fec995efede5d818e62a0b19b5</ENCRYPT_FOOTER> means ERROR (invalid ADDRESS!) |
||
32 | if "<ENCRYPT_FOOTER>2abfa6f6507044fec995efede5d818e62a0b19b5</ENCRYPT_FOOTER>" in contents: |
||
33 | self.error = "INVALID URI: {}".format(self.file_uri) |
||
34 | self.success = False |
||
35 | return True |
||
36 | self.response = contents |
||
37 | self.result = ChecksumResult(contents) |
||
38 | self.success = True |
||
39 | return True |
||
40 | self.error = "HTTP {}".format(http_status) |
||
41 | self.success = False |
||
42 | return True |
||
43 |
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.