@@ -37,14 +37,30 @@ def _replace_escaping(s: str) -> str:
37
37
return ESCAPING_RE .sub (replace_escape_sequence , s )
38
38
39
39
40
+ # for python < 3.9 compatibility
41
+ def _removeprefix (data : str , prefix : str ) -> str :
42
+ if data .startswith (prefix ):
43
+ return data [len (prefix ):]
44
+ return data
45
+
46
+
47
+ # for python < 3.9 compatibility
48
+ def _removesuffix (data : str , suffix : str ) -> str :
49
+ if data .endswith (suffix ):
50
+ return data [:- len (suffix )]
51
+ return data
52
+
53
+
40
54
def _parse_labels (labels_string : str ) -> Dict [str , str ]:
41
55
labels : Dict [str , str ] = {}
42
56
# Return if we don't have valid labels
43
57
if "=" not in labels_string :
44
58
return labels
45
59
46
60
# remove SINGLE leading and trailing commas
47
- labels_string = labels_string .strip ().removeprefix (',' ).removesuffix (',' )
61
+ labels_string = labels_string .strip ()
62
+ labels_string = _removeprefix (labels_string , ',' )
63
+ labels_string = _removesuffix (labels_string , ',' )
48
64
49
65
sub_labels = labels_string .split ("," )
50
66
try :
@@ -54,7 +70,8 @@ def _parse_labels(labels_string: str) -> Dict[str, str]:
54
70
55
71
normalized_value = label_value .strip ()
56
72
# remove SINGLE leading and trailing double quotes
57
- normalized_value = normalized_value .removeprefix ('"' ).removesuffix ('"' )
73
+ normalized_value = _removeprefix (normalized_value , '"' )
74
+ normalized_value = _removesuffix (normalized_value , '"' )
58
75
59
76
if "\\ " in normalized_value :
60
77
normalized_value = _replace_escaping (normalized_value )
0 commit comments