Test Failed
Push — master ( 8192fe...83ef1f )
by Steffen
02:25
created

saucenao.http.verify_status_code()   C

Complexity

Conditions 7

Size

Total Lines 25
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 25
rs 5.5
c 0
b 0
f 0
cc 7
nop 2
1
#!/usr/bin/python
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
# -*- coding: utf-8 -*-
3
import requests
4
5
from saucenao.exceptions import *
0 ignored issues
show
Coding Style introduced by
The usage of wildcard imports like saucenao.exceptions should generally be avoided.
Loading history...
Unused Code introduced by
UnknownStatusCodeException was imported with wildcard, but is not used.
Loading history...
6
7
PREVIOUS_STATUS_CODE = None
8
9
STATUS_CODE_OK = 1
10
STATUS_CODE_SKIP = 2
11
STATUS_CODE_REPEAT = 3
12
13
14
def verify_status_code(request_response: requests.Response, file_name: str) -> tuple:
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (85/80).

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

Loading history...
Comprehensibility Best Practice introduced by
The variable requests does not seem to be defined.
Loading history...
15
    """Verify the status code of the post request to the search url and raise exceptions if the code is unexpected
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (114/80).

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

Loading history...
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
16
17
    :type request_response: requests.Response
18
    :type file_name: str
19
    :return:
20
    """
21
    if request_response.status_code == 200:
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
22
        return STATUS_CODE_OK, ''
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
23
24
    elif request_response.status_code == 429:
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
25
        if 'limit of 150 searches' in request_response.text:
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
26
            raise DailyLimitReachedException('Daily search limit for unregistered users reached')
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (97/80).

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

Loading history...
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
Comprehensibility Best Practice introduced by
The variable DailyLimitReachedException does not seem to be defined.
Loading history...
27
        elif 'limit of 300 searches' in request_response.text:
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
28
            raise DailyLimitReachedException('Daily search limit for basic users reached')
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (90/80).

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

Loading history...
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
29
        else:
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
30
            raise DailyLimitReachedException('Daily search limit reached')
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
31
    elif request_response.status_code == 403:
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
32
        raise InvalidOrWrongApiKeyException("Invalid or wrong API key")
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
Comprehensibility Best Practice introduced by
The variable InvalidOrWrongApiKeyException does not seem to be defined.
Loading history...
33
    elif request_response.status_code == 413:
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
34
        msg = "Payload too large, skipping file: {0:s}".format(file_name)
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
35
        return STATUS_CODE_SKIP, msg
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
36
    else:
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
37
        msg = "Unknown status code: {0:d}".format(request_response.status_code)
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
38
        return STATUS_CODE_REPEAT, msg
0 ignored issues
show
Coding Style introduced by
Found indentation with spaces instead of tabs
Loading history...
39