StringTree fix: Comments were not ignored in quotes

Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
Jan Lindemann 2017-11-05 16:35:41 +01:00
commit 7007c894b8
2 changed files with 8 additions and 8 deletions

View file

@ -26,7 +26,7 @@ def cleanup_string(s):
return s return s
s = s.strip() s = s.strip()
if is_quoted(s): if is_quoted(s):
return s[1:-1] return s[1:-1].replace('\\' + s[0], s[0])
return s return s
class StringTree: # export class StringTree: # export
@ -52,18 +52,18 @@ class StringTree: # export
logcontent = "not-yet" logcontent = "not-yet"
if hasattr(self, "content"): if hasattr(self, "content"):
logcontent = self.content logcontent = self.content
slog(DEBUG, "+ setting", content, "at path \"" + str(path_) + "\" to", logcontent) slog(DEBUG, "+ setting >" + str(content) + "< at path \"" + str(path_) + "\" to", logcontent)
if content is not None:
content = cleanup_string(content)
if path_ is None: if path_ is None:
self.content = content self.content = cleanup_string(content)
slog(DEBUG, " -- content = >" + str(content) + "<, self.content = >" + str(self.content) + "<")
return self return self
path = cleanup_string(path_) path = cleanup_string(path_)
components = path.split('.') components = path.split('.')
l = len(components) l = len(components)
if len(path) == 0 or l == 0: if len(path) == 0 or l == 0:
assert self.content is None assert self.content is None
self.content = content self.content = cleanup_string(content)
slog(DEBUG, " -- content = >" + str(content) + "<, self.content = >" + str(self.content) + "<")
#self.children[content] = StringTree(None, content) #self.children[content] = StringTree(None, content)
return self return self
@ -142,7 +142,7 @@ class StringTree: # export
def value(self): def value(self):
if len(self.children) == 0: if len(self.children) == 0:
return None return None
return next(reversed(self.children)) return self.children[next(reversed(self.children))].content
def dump(self, prio, caller=None, *args): def dump(self, prio, caller=None, *args):
if caller is None: if caller is None:

View file

@ -11,7 +11,7 @@ def _cleanup_line(line):
else: else:
if c in [ '"', "'" ]: if c in [ '"', "'" ]:
in_quote = c in_quote = c
elif c == '#': elif in_quote is None and c == '#':
return r.strip() return r.strip()
r += c r += c
return r return r