Skip to content

Commit

Permalink
raise error if there is extra content beyond top data
Browse files Browse the repository at this point in the history
  • Loading branch information
Ken Kundert authored and Ken Kundert committed May 19, 2024
1 parent cef03b6 commit 3fd8abb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
16 changes: 8 additions & 8 deletions nestedtext/nestedtext.py
Original file line number Diff line number Diff line change
Expand Up @@ -911,9 +911,8 @@ def __init__(self, lines, top, source, on_dup, keymap, normalize_key, dialect):
self.values, self.keymap = None, None
else:
self.values, self.keymap = self._read_value(0, ())
return

if top in ["dict", dict]:
elif top in ["dict", dict]:
if next_is in ["dict item", "key item", "inline dict"]:
self.values, self.keymap = self._read_value(0, ())
elif next_is is None:
Expand All @@ -923,9 +922,8 @@ def __init__(self, lines, top, source, on_dup, keymap, normalize_key, dialect):
"content must start with key or brace ({{).",
lines.get_next()
)
return

if top in ["list", list]:
elif top in ["list", list]:
if next_is in ["list item", "inline list"]:
self.values, self.keymap = self._read_value(0, ())
elif next_is is None:
Expand All @@ -935,9 +933,8 @@ def __init__(self, lines, top, source, on_dup, keymap, normalize_key, dialect):
"content must start with dash (-) or bracket ([).",
lines.get_next(),
)
return

if top in ["str", str]:
elif top in ["str", str]:
if next_is == "string item":
self.values, self.keymap = self._read_value(0, ())
elif next_is is None:
Expand All @@ -947,9 +944,12 @@ def __init__(self, lines, top, source, on_dup, keymap, normalize_key, dialect):
"content must start with greater-than sign (>).",
lines.get_next(),
)
return

raise NotImplementedError(top)
else:
raise NotImplementedError(top)

if lines.type_of_next():
report('extra content', lines.get_next())

# get_decoded() {{{3
def get_decoded(self):
Expand Down
2 changes: 1 addition & 1 deletion tests/official_tests

0 comments on commit 3fd8abb

Please sign in to comment.