Skip to content

Commit 0988923

Browse files
committed
Merge pull request influxdata#84 from influxdb/fix_21_proposition
Fix 21 proposition
2 parents 6a4d2dd + ed12f40 commit 0988923

File tree

3 files changed

+33
-5
lines changed

3 files changed

+33
-5
lines changed

influxdb/chunked_json.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# -*- coding: utf-8 -*-
2+
3+
#
4+
# Author: Adrian Sampson <adrian@radbox.org>
5+
# Source: https://gist.github.com/sampsyo/920215
6+
#
7+
8+
import json
9+
10+
_decoder = json.JSONDecoder()
11+
12+
13+
def loads(s):
14+
"""A generator reading a sequence of JSON values from a string."""
15+
while s:
16+
s = s.strip()
17+
obj, pos = _decoder.raw_decode(s)
18+
if not pos:
19+
raise ValueError('no JSON object found at %i' % pos)
20+
yield obj
21+
s = s[pos:]

influxdb/client.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import socket
77
import requests
88

9+
from influxdb import chunked_json
10+
911
try:
1012
xrange
1113
except NameError:
@@ -322,7 +324,10 @@ def query(self, query, time_precision='s', chunked=False):
322324
expected_response_code=200
323325
)
324326

325-
return response.json()
327+
if chunked:
328+
return list(chunked_json.loads(response.content.decode()))
329+
else:
330+
return response.json()
326331

327332
# Creating and Dropping Databases
328333
#

tests/influxdb/client_test.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ def test_query(self):
242242

243243
def test_query_chunked(self):
244244
cli = InfluxDBClient(database='db')
245-
example_response = {
245+
example_object = {
246246
'points': [
247247
[1415206250119, 40001, 667],
248248
[1415206244555, 30001, 7],
@@ -257,17 +257,19 @@ def test_query_chunked(self):
257257
'val'
258258
]
259259
}
260+
example_response = \
261+
json.dumps(example_object) + json.dumps(example_object)
260262

261263
with requests_mock.Mocker() as m:
262264
m.register_uri(
263265
requests_mock.GET,
264266
"http://localhost:8086/db/db/series",
265-
text=json.dumps(example_response)
267+
text=example_response
266268
)
267269

268-
self.assertDictEqual(
270+
self.assertListEqual(
269271
cli.query('select * from foo', chunked=True),
270-
example_response
272+
[example_object, example_object]
271273
)
272274

273275
@raises(Exception)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy