Config¶
High-level wrapper exposing query access over a parsed configuration.
Config ¶
Config(nodes: list[ConfigNode])
Bases: _Queryable
A parsed configuration: its ordered top-level lines and their subtrees.
Returned by parse. A configuration owns the
top-level lines (those at column 0). find searches the whole tree,
while find_child and has_child consider only top-level
lines.
Create a configuration from its ordered top-level nodes.
Source code in networkconfparse/config.py
walk ¶
walk() -> Iterator[ConfigNode]
Yield every descendant node, depth-first (pre-order).
The object itself is not yielded; iteration descends into the immediate child nodes in configuration order.
Source code in networkconfparse/node.py
find ¶
find(
pattern: str | Pattern[str] | None = None,
*,
where: Predicate | None = None,
) -> list[ConfigNode]
Return all descendant nodes matching pattern and/or where.
Searches the entire subtree, not just immediate children.
Source code in networkconfparse/node.py
find_one ¶
find_one(
pattern: str | Pattern[str] | None = None,
*,
where: Predicate | None = None,
) -> ConfigNode | None
Return the first descendant matching pattern/where, or None.
Searches the whole subtree in pre-order.
Source code in networkconfparse/node.py
find_child ¶
find_child(
pattern: str | Pattern[str] | None = None,
*,
where: Predicate | None = None,
) -> ConfigNode | None
Return the first immediate child matching pattern/where.
Only immediate children are considered, in configuration order; returns
None if none match.
Source code in networkconfparse/node.py
has_child ¶
Return whether any immediate child matches pattern/where.
Source code in networkconfparse/node.py
find_with_child ¶
Return nodes matching pattern that have child as direct children.
child is one regex or an iterable of them; every pattern must match
some direct child (logical AND). Implemented with find and a
where predicate.
Source code in networkconfparse/node.py
find_with_descendant ¶
find_with_descendant(
pattern: str | Pattern[str] | None, descendant: Patterns
) -> list[ConfigNode]
Return nodes matching pattern with descendant anywhere below.
descendant is one regex or an iterable of them; every pattern must
match some descendant at any depth (logical AND). Implemented with
find and a where predicate.
Source code in networkconfparse/node.py
find_with_parent ¶
Return nodes matching pattern whose direct parent matches parent.
parent is one regex or an iterable of them; every pattern must match
the single parent line (logical AND). Implemented with find and
a where predicate.
Source code in networkconfparse/node.py
find_with_ancestor ¶
find_with_ancestor(
pattern: str | Pattern[str] | None,
ancestor: Patterns,
*,
adjacent: bool = False,
) -> list[ConfigNode]
Return nodes matching pattern with ancestor above them.
ancestor is one regex or an iterable of them, all required (AND).
With adjacent=False (the default) each pattern must match some
ancestor, in any order. With adjacent=True the patterns must form a
consecutive chain matched nearest-first: the first against the direct
parent, the next against its parent, and so on. Implemented with
find and a where predicate.
Source code in networkconfparse/node.py
find_without_child ¶
Return nodes matching pattern that lack every child pattern.
The negative counterpart of find_with_child. child is one regex
or an iterable of them; a node matches when none of them match any
direct child (the "none present" / NOR rule). For [a, b] a node
qualifies only if it has no direct child matching a and none
matching b - so a node carrying just one of them is excluded.
Implemented with find and a where predicate.
Source code in networkconfparse/node.py
find_without_descendant ¶
find_without_descendant(
pattern: str | Pattern[str] | None, descendant: Patterns
) -> list[ConfigNode]
Return nodes matching pattern with none of descendant below.
The negative counterpart of find_with_descendant. descendant is
one regex or an iterable of them; a node matches when none of them
match any descendant at any depth (the "none present" / NOR rule). For
[a, b] a node carrying just one of the two below it is excluded.
Implemented with find and a where predicate.
Source code in networkconfparse/node.py
find_without_parent ¶
Return nodes matching pattern whose parent matches no parent.
The negative counterpart of find_with_parent. parent is one regex
or an iterable of them; a node matches when its direct parent matches
none of them (the "none present" / NOR rule). A top-level node has
no parent, so it can never sit beneath a matching one and always
qualifies. For [a, b] a node whose parent matches just one of the
two is excluded. Implemented with find and a where predicate.
Source code in networkconfparse/node.py
find_without_ancestor ¶
Return nodes matching pattern with none of ancestor above.
The negative counterpart of find_with_ancestor. ancestor is one
regex or an iterable of them; a node matches when none of them
match any ancestor at any depth (the "none present" / NOR rule). A
top-level node has no ancestors and always qualifies. For [a, b] a
node with just one of the two anywhere above it is excluded.
Unlike find_with_ancestor, this takes no adjacent flag: negating
an adjacent-chain match is rarely meaningful, so the only negative
offered is "none of these appear anywhere in the ancestry." Implemented
with find and a where predicate.