Passed
Pull Request — master (#2)
by Yang
02:09
created

Python.LORIS.helper.check_json()   A

Complexity

Conditions 3

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 13
rs 10
c 0
b 0
f 0
cc 3
nop 1
1
import sys
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
import json
3
import logging
4
5
6
logging.basicConfig(stream=sys.stdout, level=logging.INFO)
7
#logger = logging.getLogger('LORISQuery')
8
9
10
def number_extraction(string):
11
    """
12
    Return
13
    :param string:
14
    :return: a LIST of strings of number!
15
    """
16
    import re
17
    return re.findall(r'\d+', string)
18
19
if __name__ == '__main__':
20
    print(number_extraction("T4"))
21
22
23
def is_response_success(status_code, expected_code):
24
    """
25
    A simple function to determine the success of the status code
26
    :param status_code:
27
    :return: boolean value
28
    """
29
    if status_code == expected_code:
0 ignored issues
show
Unused Code introduced by
The if statement can be replaced with 'return bool(test)'
Loading history...
unused-code introduced by
Unnecessary "else" after "return"
Loading history...
30
        return True
31
    else:
32
        return False
33
34
35
def check_json(data):
36
    """
37
    Check if the data input is JSON format compatible.
38
    :param data:
39
    :return:
40
    """
41
    try:
42
        JSON = json.loads(data)
0 ignored issues
show
Coding Style Naming introduced by
The name JSON 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...
43
        return True, JSON
44
    except ValueError:
45
        return False, None
46
    except Exception as e:
0 ignored issues
show
Best Practice introduced by
Catching very general exceptions such as Exception is usually not recommended.

Generally, you would want to handle very specific errors in the exception handler. This ensure that you do not hide other types of errors which should be fixed.

So, unless you specifically plan to handle any error, consider adding a more specific exception.

Loading history...
Coding Style Naming introduced by
The name e 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...
Unused Code introduced by
The variable e seems to be unused.
Loading history...
47
        return False, None
48