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

Function key_value_rule

tools/python-3.11.9-amd64/Lib/tomllib/_parser.py:323–354  ·  view source on GitHub ↗
(
    src: str, pos: Pos, out: Output, header: Key, parse_float: ParseFloat
)

Source from the content-addressed store, hash-verified

321
322
323def key_value_rule(
324 src: str, pos: Pos, out: Output, header: Key, parse_float: ParseFloat
325) -> Pos:
326 pos, key, value = parse_key_value_pair(src, pos, parse_float)
327 key_parent, key_stem = key[:-1], key[-1]
328 abs_key_parent = header + key_parent
329
330 relative_path_cont_keys = (header + key[:i] for i in range(1, len(key)))
331 for cont_key in relative_path_cont_keys:
332 # Check that dotted key syntax does not redefine an existing table
333 if out.flags.is_(cont_key, Flags.EXPLICIT_NEST):
334 raise suffixed_err(src, pos, f"Cannot redefine namespace {cont_key}")
335 # Containers in the relative path can't be opened with the table syntax or
336 # dotted key/value syntax in following table sections.
337 out.flags.add_pending(cont_key, Flags.EXPLICIT_NEST)
338
339 if out.flags.is_(abs_key_parent, Flags.FROZEN):
340 raise suffixed_err(
341 src, pos, f"Cannot mutate immutable namespace {abs_key_parent}"
342 )
343
344 try:
345 nest = out.data.get_or_create_nest(abs_key_parent)
346 except KeyError:
347 raise suffixed_err(src, pos, "Cannot overwrite a value") from None
348 if key_stem in nest:
349 raise suffixed_err(src, pos, "Cannot overwrite a value")
350 # Mark inline table and array namespaces recursively immutable
351 if isinstance(value, (dict, list)):
352 out.flags.set(header + key, Flags.FROZEN, recursive=True)
353 nest[key_stem] = value
354 return pos
355
356
357def parse_key_value_pair(

Callers 1

loadsFunction · 0.70

Calls 6

parse_key_value_pairFunction · 0.70
suffixed_errFunction · 0.70
is_Method · 0.45
add_pendingMethod · 0.45
get_or_create_nestMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected