tests.utils   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 23
rs 10
c 0
b 0
f 0
wmc 3

1 Function

Rating   Name   Duplication   Size   Complexity  
A load() 0 15 3
1
import json
2
from typing import Union
3
4
import flask
5
import log
6
7
8
def load(response: flask.Response) -> (int, Union[dict, str]):
9
    """Convert a response's binary data (JSON) to a dictionary."""
10
    text = response.data.decode('utf-8')
11
12
    if text:
13
        try:
14
            data = json.loads(text)
15
        except json.decoder.JSONDecodeError:
16
            data = text
17
    else:
18
        data = None
19
20
    log.debug("Response: %r", data)
21
22
    return response.status_code, data
23