Skip to content
This repository was archived by the owner on Oct 29, 2024. It is now read-only.

Fix 21 proposition #84

Merged
merged 2 commits into from
Nov 11, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions influxdb/chunked_json.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-

#
# Author: Adrian Sampson <adrian@radbox.org>
# Source: https://gist.github.com/sampsyo/920215
#

import json

_decoder = json.JSONDecoder()


def loads(s):
"""A generator reading a sequence of JSON values from a string."""
while s:
s = s.strip()
obj, pos = _decoder.raw_decode(s)
if not pos:
raise ValueError('no JSON object found at %i' % pos)
yield obj
s = s[pos:]
7 changes: 6 additions & 1 deletion influxdb/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import socket
import requests

from influxdb import chunked_json

try:
xrange
except NameError:
Expand Down Expand Up @@ -322,7 +324,10 @@ def query(self, query, time_precision='s', chunked=False):
expected_response_code=200
)

return response.json()
if chunked:
return list(chunked_json.loads(response.content.decode()))
else:
return response.json()

# Creating and Dropping Databases
#
Expand Down
10 changes: 6 additions & 4 deletions tests/influxdb/client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ def test_query(self):

def test_query_chunked(self):
cli = InfluxDBClient(database='db')
example_response = {
example_object = {
'points': [
[1415206250119, 40001, 667],
[1415206244555, 30001, 7],
Expand All @@ -257,17 +257,19 @@ def test_query_chunked(self):
'val'
]
}
example_response = \
json.dumps(example_object) + json.dumps(example_object)

with requests_mock.Mocker() as m:
m.register_uri(
requests_mock.GET,
"http://localhost:8086/db/db/series",
text=json.dumps(example_response)
text=example_response
)

self.assertDictEqual(
self.assertListEqual(
cli.query('select * from foo', chunked=True),
example_response
[example_object, example_object]
)

@raises(Exception)
Expand Down
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