MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / NestedDict

Class NestedDict

tools/python-3.11.9-amd64/Lib/tomllib/_parser.py:193–224  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

191
192
193class NestedDict:
194 def __init__(self) -> None:
195 # The parsed content of the TOML document
196 self.dict: dict[str, Any] = {}
197
198 def get_or_create_nest(
199 self,
200 key: Key,
201 *,
202 access_lists: bool = True,
203 ) -> dict:
204 cont: Any = self.dict
205 for k in key:
206 if k not in cont:
207 cont[k] = {}
208 cont = cont[k]
209 if access_lists and isinstance(cont, list):
210 cont = cont[-1]
211 if not isinstance(cont, dict):
212 raise KeyError("There is no nest behind this key")
213 return cont
214
215 def append_nest_to_list(self, key: Key) -> None:
216 cont = self.get_or_create_nest(key[:-1])
217 last_key = key[-1]
218 if last_key in cont:
219 list_ = cont[last_key]
220 if not isinstance(list_, list):
221 raise KeyError("An object other than list found behind this key")
222 list_.append({})
223 else:
224 cont[last_key] = [{}]
225
226
227class Output(NamedTuple):

Callers 2

loadsFunction · 0.70
parse_inline_tableFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected