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

Function _parse_timestamp

prometheus_client/openmetrics/parser.py:81–100  ·  view source on GitHub ↗
(timestamp)

Source from the content-addressed store, hash-verified

79
80
81def _parse_timestamp(timestamp):
82 timestamp = ''.join(timestamp)
83 if not timestamp:
84 return None
85 if timestamp != timestamp.strip() or '_' in timestamp:
86 raise ValueError(f"Invalid timestamp: {timestamp!r}")
87 try:
88 # Simple int.
89 return Timestamp(int(timestamp), 0)
90 except ValueError:
91 try:
92 # aaaa.bbbb. Nanosecond resolution supported.
93 parts = timestamp.split('.', 1)
94 return Timestamp(int(parts[0]), int(parts[1][:9].ljust(9, "0")))
95 except ValueError:
96 # Float.
97 ts = float(timestamp)
98 if math.isnan(ts) or math.isinf(ts):
99 raise ValueError(f"Invalid timestamp: {timestamp!r}")
100 return ts
101
102
103def _is_character_escaped(s, charpos):

Callers 1

_parse_remaining_textFunction · 0.85

Calls 2

TimestampClass · 0.85
joinMethod · 0.80

Tested by

no test coverage detected