@@ -37,24 +37,40 @@ 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
- sub_labels = labels_string .split ("," )
50
65
try :
51
66
# Process one label at a time
52
- for label in sub_labels :
67
+ for label in labels_string . split ( "," ) :
53
68
label_name , label_value = label .split ("=" )
54
69
55
70
normalized_value = label_value .strip ()
56
71
# remove SINGLE leading and trailing double quotes
57
- normalized_value = normalized_value .removeprefix ('"' ).removesuffix ('"' )
72
+ normalized_value = _removeprefix (normalized_value , '"' )
73
+ normalized_value = _removesuffix (normalized_value , '"' )
58
74
59
75
if "\\ " in normalized_value :
60
76
normalized_value = _replace_escaping (normalized_value )
0 commit comments