mirror of
ssh://git.janware.com/srv/git/janware/proj/jw-python
synced 2026-01-15 09:53:32 +01:00
Attempt to support parsing full lines into StringTree
This commit tries to add support for the [section] first line second line syntax, i.e. non-assignments, without equal sign. Half-baked, but still better than before. Also support some more Python 3, i.e. dict.items() instead of iteritems() Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
parent
109179b55e
commit
1c0c5ab884
2 changed files with 16 additions and 12 deletions
|
|
@ -1,4 +1,4 @@
|
|||
from StringTree import *
|
||||
from jwutils.stree.StringTree import *
|
||||
from jwutils.log import *
|
||||
|
||||
def _cleanup_line(line):
|
||||
|
|
@ -20,7 +20,7 @@ def _cleanup_line(line):
|
|||
return r[1:-1]
|
||||
return r
|
||||
|
||||
def parse(s): # export
|
||||
def parse(s, allow_full_lines=True): # export
|
||||
slog(DEBUG, "parsing", s)
|
||||
root = StringTree('', content='root')
|
||||
sec = ''
|
||||
|
|
@ -57,9 +57,13 @@ def parse(s): # export
|
|||
continue
|
||||
rhs += c
|
||||
|
||||
split = True
|
||||
if rhs is None:
|
||||
raise Exception("failed to parse assignment", line)
|
||||
root.add(sec + '.' + cleanup_string(lhs), cleanup_string(rhs))
|
||||
if not allow_full_lines:
|
||||
raise Exception("failed to parse assignment", line)
|
||||
rhs = 'empty'
|
||||
split = False
|
||||
root.add(sec + '.' + cleanup_string(lhs), cleanup_string(rhs), split=split)
|
||||
return root
|
||||
|
||||
def read(path): # export
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue