Skip to content
Snippets Groups Projects
Commit 1e23b865bb74 authored by Janne Kulmala's avatar Janne Kulmala
Browse files

raw_decode(): Skip whitespace before the object

parent a0a453784523
Branches
No related tags found
No related merge requests found
...@@ -403,9 +403,9 @@ ...@@ -403,9 +403,9 @@
instance containing a JSON document) instance containing a JSON document)
""" """
obj, end = self.raw_decode(s, idx=_w(s, 0).end()) obj, end = self.raw_decode(s)
end = _w(s, end).end() end = _w(s, end).end()
if end != len(s): if end != len(s):
raise JSONDecodeError("Extra data", s, end, len(s)) raise JSONDecodeError("Extra data", s, end, len(s))
return obj return obj
...@@ -407,9 +407,9 @@ ...@@ -407,9 +407,9 @@
end = _w(s, end).end() end = _w(s, end).end()
if end != len(s): if end != len(s):
raise JSONDecodeError("Extra data", s, end, len(s)) raise JSONDecodeError("Extra data", s, end, len(s))
return obj return obj
def raw_decode(self, s, idx=0): def raw_decode(self, s, idx=0, _w=WHITESPACE.match):
"""Decode a JSON document from ``s`` (a ``str`` or ``unicode`` """Decode a JSON document from ``s`` (a ``str`` or ``unicode``
beginning with a JSON document) and return a 2-tuple of the Python beginning with a JSON document) and return a 2-tuple of the Python
representation and the index in ``s`` where the document ended. representation and the index in ``s`` where the document ended.
...@@ -421,7 +421,7 @@ ...@@ -421,7 +421,7 @@
""" """
try: try:
obj, end = self.scan_once(s, idx) obj, end = self.scan_once(s, idx=_w(s, idx).end())
except StopIteration: except StopIteration:
raise JSONDecodeError("No JSON object could be decoded", s, idx) raise JSONDecodeError("No JSON object could be decoded", s, idx)
return obj, end return obj, end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment