Passed
Push — master ( 2adcb6...75d235 )
by Markus
01:50
created

ChecksumRequest.is_done()   A

Complexity

Conditions 3

Size

Total Lines 14
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 14
rs 9.4285
c 0
b 0
f 0
cc 3
nop 3
1
# -*- coding: utf-8 -*-
0 ignored issues
show
Coding Style introduced by
This module should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
2
3
from collections import OrderedDict
4
import json
5
from .. import credentials, devices
0 ignored issues
show
Unused Code introduced by
The import devices seems to be unused.
Loading history...
6
from .tclrequest import TclRequest
7
from .tclresult import ChecksumResult
8
9
class ChecksumRequest(TclRequest):
0 ignored issues
show
Coding Style introduced by
This class should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
best-practice introduced by
Too many instance attributes (8/7)
Loading history...
Unused Code introduced by
The variable __class__ seems to be unused.
Loading history...
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