replacement_function()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
c 0
b 0
f 0
dl 0
loc 1
rs 10
1
import re
2
3
4
def multiple_replacer(*key_values):
5
    replace_dict = dict(key_values)
6
7
    def replacement_function(match): return replace_dict[match.group(0)]
8
    pattern = re.compile("|".join([re.escape(k) for k, v in key_values]), re.M)
9
    return lambda string: pattern.sub(replacement_function, string)
10
11
12
def multiple_replace(string, *key_values):
13
    return multiple_replacer(*key_values)(string)
14
15
16
def influxdb_tag_escaper():
17
    return multiple_replacer(('\\', '\\\\'), (' ', '\\ '), (',', '\\,'), ('=', '\\='))
18