Skip to content

Commit

Permalink
fix #7; handle multiline keys
Browse files Browse the repository at this point in the history
  • Loading branch information
rossengeorgiev committed Mar 26, 2016
1 parent 8e50d5a commit 88ec1ab
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions tests/test_vdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ def test_parse_exceptions(self):
# invalid syntax
'"asd" "123"\n"zxc" "333"\n"',
'asd 123\nzxc 333\n"',
'"asd\n\n\n\n\nzxc',

# one too many closing parenthasis
'"asd"\n{\n"zxc" "123"\n}\n}\n}\n}\n',
Expand Down
11 changes: 9 additions & 2 deletions vdf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,11 @@ def parse(fp, mapper=dict):
match = re_keyvalue.match(line)

if not match:
raise SyntaxError("vdf.parse: invalid syntax (line %d)" % (idx + 1))
try:
line += next(fp)
except StopIteration:
raise SyntaxError("vdf.parse: unexpected EOF (open key quote?)")
continue

key = match.group('key') if match.group('qkey') is None else match.group('qkey')
val = match.group('val') if match.group('qval') is None else match.group('qval')
Expand All @@ -100,7 +104,10 @@ def parse(fp, mapper=dict):
# if the value is line consume one more line and try to match again,
# until we get the KeyValue pair
if match.group('vq_end') is None and match.group('qval') is not None:
line += next(fp)
try:
line += next(fp)
except StopIteration:
raise SyntaxError("vdf.parse: unexpected EOF (open value quote?)")
continue

stack[-1][key] = val
Expand Down

0 comments on commit 88ec1ab

Please sign in to comment.