benedict.core.standardize   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 13
dl 0
loc 20
rs 10
c 0
b 0
f 0

2 Functions

Rating   Name   Duplication   Size   Complexity  
A _standardize_item() 0 6 2
A standardize() 0 2 1
1
import re
2
3
from slugify import slugify
4
5
from benedict.core.rename import rename
6
from benedict.core.traverse import traverse
7
from benedict.utils import type_util
8
9
10
def _standardize_item(d, key, value):
11
    if type_util.is_string(key):
12
        # https://stackoverflow.com/a/12867228/2096218
13
        norm_key = re.sub(r"((?<=[a-z0-9])[A-Z]|(?!^)[A-Z](?=[a-z]))", r"_\1", key)
14
        norm_key = slugify(norm_key, separator="_")
15
        rename(d, key, norm_key)
16
17
18
def standardize(d):
19
    traverse(d, _standardize_item)
20