diff options
author | Bob Ippolito <bob@redivi.com> | 2012-07-27 21:53:42 -0700 |
---|---|---|
committer | Bob Ippolito <bob@redivi.com> | 2012-07-27 21:53:42 -0700 |
commit | 5178cb760e35a8a921fd509f7d5da383d122d54e (patch) | |
tree | c5ec429f622256ecd5b3df2860e2e9c9efa9b516 | |
parent | 16b63cdb118138f8639b6f005d92f2136c815a1e (diff) | |
parent | 0fb0aeabc0af49bb127deb11ecddf66fa7a3d58c (diff) | |
download | simplejson-5178cb760e35a8a921fd509f7d5da383d122d54e.tar.gz |
Merge pull request #38 from japeq/master
Bug fixes related to raw_decode()
-rw-r--r-- | simplejson/decoder.py | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/simplejson/decoder.py b/simplejson/decoder.py index 714a733..1c1526c 100644 --- a/simplejson/decoder.py +++ b/simplejson/decoder.py @@ -403,23 +403,25 @@ class JSONDecoder(object): 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() if end != len(s): raise JSONDecodeError("Extra data", s, end, len(s)) 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`` beginning with a JSON document) and return a 2-tuple of the Python representation and the index in ``s`` where the document ended. + Optionally, ``idx`` can be used to specify an offset in ``s`` where + the JSON document begins. This can be used to decode a JSON document from a string that may have extraneous data at the end. """ try: - obj, end = self.scan_once(s, idx) + obj, end = self.scan_once(s, idx=_w(s, idx).end()) except StopIteration: raise JSONDecodeError("No JSON object could be decoded", s, idx) return obj, end |