GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

b2blaze.b2_exceptions   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 117
Duplicated Lines 0 %

Test Coverage

Coverage 93.33%

Importance

Changes 0
Metric Value
eloc 55
dl 0
loc 117
ccs 42
cts 45
cp 0.9333
rs 10
c 0
b 0
f 0
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A B2Exception.parse() 0 30 3
1
"""
2
Copyright George Sibble 2018
3
"""
4
5 1
import json
0 ignored issues
show
Unused Code introduced by
The import json seems to be unused.
Loading history...
6
7
8 1
class B2ApplicationKeyNotSet(Exception):
9
    """ You must set the B2_KEY_ID environment variable before running the application """
10 1
    pass
11
12
13 1
class B2KeyIDNotSet(Exception):
14
    """ You must set the B2_APPLICATION_KEY environment variable before running the application """
15 1
    pass
16
17
18 1
class B2Exception(Exception):
19
    """ Base exception class for the Backblaze API """
20
21 1
    @staticmethod
22
    def parse(response):
23
        """ Parse the response error code and return the related error type. """
24
25 1
        API_EXCEPTION_CODES = {
0 ignored issues
show
Coding Style Naming introduced by
The name API_EXCEPTION_CODES does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
26
            400 : B2RequestError,
27
            401 : B2UnauthorizedError,
28
            403 : B2ForbiddenError,
29
            404 : B2FileNotFoundError,
30
            408 : B2RequestTimeoutError,
31
            429 : B2TooManyRequestsError,
32
            500 : B2InternalError,
33
            503 : B2ServiceUnavailableError,
34
        }
35
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
36 1
        try:
37 1
            response_json = response.json()
38 1
            message = response_json['message']
39 1
            code = response_json['code']
40 1
            status = int(response_json['status'])
41
42
            # Return B2Exception if unrecognized status code
43 1
            if not status in API_EXCEPTION_CODES:
0 ignored issues
show
Unused Code introduced by
Consider changing "not status in API_EXCEPTION_CODES" to "status not in API_EXCEPTION_CODES"
Loading history...
44
                return B2Exception('{} - {}: {}'.format(status, code, message))
45
            
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
46 1
            ErrorClass = API_EXCEPTION_CODES[status]
0 ignored issues
show
Coding Style Naming introduced by
The name ErrorClass does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
47 1
            return ErrorClass('{} - {}: {}'.format(status, code, message))
48
49
        except:
0 ignored issues
show
Coding Style Best Practice introduced by
General except handlers without types should be used sparingly.

Typically, you would use general except handlers when you intend to specifically handle all types of errors, f.e. when logging. Otherwise, such general error handlers can mask errors in your application that you want to know of.

Loading history...
50
            return Exception('error parsing response. status code - {} Response JSON: {}'.format(response.status_code, response_json) )
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (135/100).

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

Loading history...
Coding Style introduced by
No space allowed before bracket
Loading history...
51
52 1
class B2FileNotFoundError(Exception):
53
    """ 404 Not Found """
54 1
    pass
55
56
57 1
class B2RequestError(Exception):
58
    """ There is a problem with a passed in request parameters. See returned message for details """
59 1
    pass
60
61
62 1
class B2UnauthorizedError(Exception):
63
    """ When calling b2_authorize_account, this means that there was something wrong with the accountId/applicationKeyId or with the applicationKey that was provided. The code unauthorized means that the application key is bad. The code unsupported means that the application key is only valid in a later version of the API. 
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
Coding Style introduced by
This line is too long as per the coding-style (324/100).

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

Loading history...
64
65
    The code unauthorized means that the auth token is valid, but does not allow you to make this call with these parameters. When the code is either bad_auth_token or expired_auth_token you should call b2_authorize_account again to get a new auth token.
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (254/100).

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

Loading history...
66
    """
67 1
    pass
68
69
70 1
class B2ForbiddenError(Exception):
71
    """ You have a reached a storage cap limit, or account access may be impacted in some other way; see the human-readable message. 
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
Coding Style introduced by
This line is too long as per the coding-style (132/100).

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

Loading history...
72
    """
73 1
    pass
74
75
76 1
class B2RequestTimeoutError(Exception):
77
    """ The service timed out trying to read your request. """
78 1
    pass
79
80 1
class B2OutOfRangeError(Exception):
81
    """ The Range header in the request is outside the size of the file.. """
82 1
    pass
83
84
85 1
class B2TooManyRequestsError(Exception):
86
    """ B2 may limit API requests on a per-account basis. """
87 1
    pass
88
89
90 1
class B2InternalError(Exception):
91
    """ An unexpected error has occurred. """
92 1
    pass
93
94
95 1
class B2ServiceUnavailableError(Exception):
96
    """ The service is temporarily unavailable. The human-readable message identifies the nature of the issue, in general we recommend retrying with an exponential backoff between retries in response to this error. 
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
Coding Style introduced by
This line is too long as per the coding-style (214/100).

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

Loading history...
97
    """
98 1
    pass
99
100
101 1
class B2InvalidBucketName(Exception):
102
    """ Bucket name must be alphanumeric or '-' """
103 1
    pass
104
105
106 1
class B2InvalidBucketConfiguration(Exception):
107
    """ Value error in bucket configuration """
108 1
    pass
109
110 1
class B2AuthorizationError(Exception):
111
    """ An error with the authorization request """
112 1
    pass
113
114 1
class B2InvalidRequestType(Exception):
115
    """ Request type must be get or post """
116
    pass
117