@@ -37,24 +37,40 @@ def _replace_escaping(s: str) -> str:
3737 return ESCAPING_RE .sub (replace_escape_sequence , s )
3838
3939
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+
4054def _parse_labels (labels_string : str ) -> Dict [str , str ]:
4155 labels : Dict [str , str ] = {}
4256 # Return if we don't have valid labels
4357 if "=" not in labels_string :
4458 return labels
4559
4660 # 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 , ',' )
4864
49- sub_labels = labels_string .split ("," )
5065 try :
5166 # Process one label at a time
52- for label in sub_labels :
67+ for label in labels_string . split ( "," ) :
5368 label_name , label_value = label .split ("=" )
5469
5570 normalized_value = label_value .strip ()
5671 # 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 , '"' )
5874
5975 if "\\ " in normalized_value :
6076 normalized_value = _replace_escaping (normalized_value )
0 commit comments