MCPcopy Index your code
hub / github.com/prometheus/client_python / _next_term

Function _next_term

prometheus_client/parser.py:106–137  ·  view source on GitHub ↗

Extract the next comma-separated label term from the text. The results are stripped terms for the label name, label value, and then the remainder of the string including the final , or }. Raises ValueError if the term is empty and we're in openmetrics mode.

(text: str, openmetrics: bool)

Source from the content-addressed store, hash-verified

104
105
106def _next_term(text: str, openmetrics: bool) -> Tuple[str, str, str]:
107 """Extract the next comma-separated label term from the text. The results
108 are stripped terms for the label name, label value, and then the remainder
109 of the string including the final , or }.
110
111 Raises ValueError if the term is empty and we're in openmetrics mode.
112 """
113
114 # There may be a leading comma, which is fine here.
115 if text[0] == ',':
116 text = text[1:]
117 if not text:
118 return "", "", ""
119 if text[0] == ',':
120 raise ValueError("multiple commas")
121
122 splitpos = _next_unquoted_char(text, '=,}')
123 if splitpos >= 0 and text[splitpos] == "=":
124 labelname = text[:splitpos]
125 text = text[splitpos + 1:]
126 splitpos = _next_unquoted_char(text, ',}')
127 else:
128 labelname = "__name__"
129
130 if splitpos == -1:
131 splitpos = len(text)
132 term = text[:splitpos]
133 if not term and openmetrics:
134 raise ValueError("empty term:", term)
135
136 rest = text[splitpos:]
137 return labelname, term.strip(), rest.strip()
138
139
140def _next_unquoted_char(text: str, chs: Optional[str], startidx: int = 0) -> int:

Callers 1

parse_labelsFunction · 0.85

Calls 1

_next_unquoted_charFunction · 0.85

Tested by

no test coverage detected