mirror of
ssh://git.janware.com/srv/git/janware/proj/jw-python
synced 2026-01-15 09:53:32 +01:00
stree/serdes.py: Add support for kwarg "root_content"
parse() and read() up to present automatically set the root content of a StringTree object to "root". This can now be optionally defined by the "root_content" keyword argument. Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
parent
79ebb798c7
commit
020bb970bd
1 changed files with 4 additions and 4 deletions
|
|
@ -20,9 +20,9 @@ def _cleanup_line(line):
|
|||
return r[1:-1]
|
||||
return r
|
||||
|
||||
def parse(s, allow_full_lines=True): # export
|
||||
def parse(s, allow_full_lines=True, root_content='root'): # export
|
||||
slog(DEBUG, "parsing", s)
|
||||
root = StringTree('', content='root')
|
||||
root = StringTree('', content=root_content)
|
||||
sec = ''
|
||||
for line in s.splitlines():
|
||||
slog(DEBUG, "line=", line)
|
||||
|
|
@ -66,7 +66,7 @@ def parse(s, allow_full_lines=True): # export
|
|||
root.add(sec + '.' + cleanup_string(lhs), cleanup_string(rhs), split=split)
|
||||
return root
|
||||
|
||||
def read(path): # export
|
||||
def read(path, root_content='root'): # export
|
||||
with open(path, 'r') as infile:
|
||||
s = infile.read()
|
||||
return parse(s)
|
||||
return parse(s, root_content=root_content)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue