mirror of
ssh://git.janware.com/srv/git/janware/proj/jw-python
synced 2026-01-15 09:53:32 +01:00
StringTree.value(): Add optional path argument
As opposed to the C++ variant, StringTree.value() doesn't take a path argument, but only returns the value of the node it's called on. Change this. Returns None if the path is not found. Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
parent
ee3d49a23c
commit
85672d6cf3
1 changed files with 7 additions and 2 deletions
|
|
@ -115,7 +115,7 @@ class StringTree: # export
|
|||
r = self.get(path)
|
||||
if r is None:
|
||||
raise KeyError(path)
|
||||
return r.value()
|
||||
return r.value() # type: ignore
|
||||
|
||||
def __setitem__(self, key, value):
|
||||
return self.__set(key, value)
|
||||
|
|
@ -170,7 +170,12 @@ class StringTree: # export
|
|||
relpath = '.'.join(components[1:])
|
||||
return self.children[name].get(relpath)
|
||||
|
||||
def value(self) -> str:
|
||||
def value(self, path = None) -> Optional[str]:
|
||||
if path:
|
||||
child = self.get(path)
|
||||
if child is None:
|
||||
return None
|
||||
return child.value()
|
||||
if len(self.children) == 0:
|
||||
raise Exception('tried to get value from leave "{}"'.format(self.content))
|
||||
return self.children[next(reversed(self.children))].content # type: ignore
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue