stree.StringTree.__set(): path_ -> path

Some methods take a "path_" argument, which is not nice for callers.
Rename it to "path" and fix the fallout in the method bodies.

Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
Jan Lindemann 2026-07-02 11:04:51 +02:00 • committed by janware DevOps
commit b4041018d2
Signed by: DevOps
SSH key fingerprint: SHA256:cZiw7ExG5q3KAVm7Jse3rGITowu0VjgUgNMPbifmY8g

View file

@ -75,11 +75,11 @@ class StringTree: # export
else:
self.children[name].__adopt_children(c)
def __set(self, path_, content, split = True):
def __set(self, path: str, content: str, split = True):
slog(
DEBUG,
('At "{}": '.format(str(self.content)) if hasattr(self, "content") else "")
+ f'Setting "{path_}" -> "{content}"'
+ f'Setting "{path}" -> "{content}"'
)
# Not sure what the idea behind this was. It often goes off, and all
@ -92,7 +92,7 @@ class StringTree: # export
type(content).__name__
)
)
if path_ is None:
if path is None:
if isinstance(content, str):
self.content = cleanup_string(content)
elif isinstance(content, StringTree):
@ -109,10 +109,10 @@ class StringTree: # export
str(self.content) + "<"
)
return self
path = cleanup_string(path_)
components = path.split('.') if split else [path]
_path = cleanup_string(path)
components = _path.split('.') if split else [_path]
length = len(components)
if len(path) == 0 or length == 0:
if len(_path) == 0 or length == 0:
#assert self.content is None or (
# isinstance(content, StringTree) and content.content == self.content
@ -133,7 +133,7 @@ class StringTree: # export
#self.children[content] = StringTree(None, content)
return self
#assert self.content is not None, f'Tried to set empty content to "{path_}"'
#assert self.content is not None, f'Tried to set empty content to "{path}"'
nibble = components[0]
rest = '.'.join(components[1:])
@ -206,18 +206,18 @@ class StringTree: # export
slog(DEBUG, f'-- At "{self.content}": Adding "{path}" -> "{content}"')
return self.__set(path, content, split)
def get(self, path_: str) -> Optional[StringTree]:
slog(DEBUG, 'looking for "{}" in "{}"'.format(path_, self.content))
assert not isinstance(path_, int)
path = cleanup_string(path_)
if len(path) == 0:
def get(self, path: str) -> Optional[StringTree]:
slog(DEBUG, 'looking for "{}" in "{}"'.format(path, self.content))
assert not isinstance(path, int)
_path = cleanup_string(path)
if len(_path) == 0:
slog(DEBUG, "returning myself")
return self
if is_quoted(path_):
if path not in self.children.keys():
if is_quoted(path):
if _path not in self.children.keys():
return None
return self.children[path]
components = path.split('.')
return self.children[_path]
components = _path.split('.')
if len(components) == 0:
return self
name = cleanup_string(components[0])
@ -228,8 +228,8 @@ class StringTree: # export
for child in self.children:
slog(DEBUG, "child = ", child)
return None
relpath = '.'.join(components[1:])
return self.children[name].get(relpath)
rel_path = '.'.join(components[1:])
return self.children[name].get(rel_path)
def value(self, path = None, default = None) -> Optional[str]:
if path: