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

tcllib.requests.checksumrequest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
eloc 35
dl 0
loc 43
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A ChecksumRequest.get_params() 0 7 1
A ChecksumRequest.is_done() 0 14 3
A ChecksumRequest.get_headers() 0 2 1
A ChecksumRequest.__init__() 0 7 1
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