Passed
Push — master ( 2f86f7...74d48b )
by Markus
01:48
created

tcllib.tclchecksum.TclChecksumMixin.do_checksum()   A

Complexity

Conditions 3

Size

Total Lines 23
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 18
nop 4
dl 0
loc 23
rs 9.0856
c 0
b 0
f 0
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
import json
4
from defusedxml import ElementTree
5
6
class TclChecksumMixin:
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...
Unused Code introduced by
The variable __class__ seems to be unused.
Loading history...
7
    def do_checksum(self, encslave, address, uri):
0 ignored issues
show
Coding Style introduced by
This method 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...
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")
0 ignored issues
show
Coding Style introduced by
Exactly one space required before assignment
Loading history...
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
Coding Style introduced by
This line is too long as per the coding-style (81/80).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
19
            self.write_dump(req.text)
20
            # <ENCRYPT_FOOTER>2abfa6f6507044fec995efede5d818e62a0b19b5</ENCRYPT_FOOTER> means ERROR (invalid ADDRESS!)
1 ignored issue
show
Coding Style introduced by
This line is too long as per the coding-style (118/80).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
21
            if "<ENCRYPT_FOOTER>2abfa6f6507044fec995efede5d818e62a0b19b5</ENCRYPT_FOOTER>" in req.text:
1 ignored issue
show
Coding Style introduced by
This line is too long as per the coding-style (103/80).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
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):
0 ignored issues
show
Coding Style introduced by
This method 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...
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