Completed
Push — master ( 5cbcf8...d3d059 )
by Matthias
01:08
created

multiple_replacer()   A

Complexity

Conditions 4

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

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