Debian Codegraph @

influxdb/chunked_json.py

raw
1 # -*- coding: utf-8 -*-
2 """Module to generate chunked JSON replies."""
3
4 #
5 # Author: Adrian Sampson <[email protected]>
6 # Source: https://gist.github.com/sampsyo/920215
7 #
8
9 from __future__ import absolute_import
10 from __future__ import division
11 from __future__ import print_function
12 from __future__ import unicode_literals
13
14 import json
15
16
17 def loads(s):
18 """Generate a sequence of JSON values from a string."""
19 _decoder = json.JSONDecoder()
20
21 while s:
22 s = s.strip()
23 obj, pos = _decoder.raw_decode(s)
24 if not pos:
25 raise ValueError('no JSON object found at %i' % pos)
26 yield obj
27 s = s[pos:]