MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / _Parser

Class _Parser

scripts/test-impact/profile_text_parser.py:98–203  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

96
97
98class _Parser:
99 __slots__ = ("data", "limits", "gate", "position", "names", "values")
100
101 def __init__(self, data, limits, gate):
102 self.data = data
103 self.limits = limits
104 self.gate = gate
105 self.position = 0
106 self.names = 0
107 self.values = 0
108
109 def line(self):
110 start = self.position
111 while self.position < len(self.data):
112 self.gate.step()
113 value = self.data[self.position]
114 self.position += 1
115 if value == 0 or value == 13:
116 raise MalformedProfileError("NUL and CR are unsupported")
117 if value == 10:
118 return start, self.position - 1
119 raise MalformedProfileError("unterminated or missing line")
120
121 def marker(self, expected):
122 start, end = self.line()
123 if end - start != len(expected):
124 raise MalformedProfileError("unexpected record marker")
125 for index, value in enumerate(expected):
126 self.gate.step()
127 if self.data[start + index] != value:
128 raise MalformedProfileError("unexpected record marker")
129
130 def uint64(self):
131 start, end = self.line()
132 length = end - start
133 if length == 0 or length > 20:
134 raise MalformedProfileError("invalid unsigned decimal")
135 if length > 1 and self.data[start] == 48:
136 raise MalformedProfileError("noncanonical unsigned decimal")
137 value = 0
138 for index in range(start, end):
139 self.gate.step()
140 digit = self.data[index] - 48
141 if digit < 0 or digit > 9:
142 raise MalformedProfileError("invalid unsigned decimal")
143 if value > (_UINT64_MAX - digit) // 10:
144 raise MalformedProfileError("unsigned decimal overflow")
145 value = value * 10 + digit
146 return value
147
148 def name_values(self, start, end):
149 for index in range(start, end):
150 self.gate.step()
151 yield self.data[index]
152
153 def counter_values(self, count):
154 for _ in range(count):
155 self.gate.step()

Callers 1

parse_profile_textFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected