From 1a523a486be3f76b721a947169576070df9ab4d0 Mon Sep 17 00:00:00 2001 From: aviau Date: Wed, 5 Nov 2014 20:56:14 -0500 Subject: [PATCH 1/2] fixed #21 --- influxdb/chunked_json.py | 21 +++++++++++++++++++++ influxdb/client.py | 8 +++++++- tests/influxdb/client_test.py | 9 +++++---- 3 files changed, 33 insertions(+), 5 deletions(-) create mode 100644 influxdb/chunked_json.py diff --git a/influxdb/chunked_json.py b/influxdb/chunked_json.py new file mode 100644 index 00000000..50d304f1 --- /dev/null +++ b/influxdb/chunked_json.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- + +# +# Author: Adrian Sampson +# 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:] diff --git a/influxdb/client.py b/influxdb/client.py index dfae9613..1df036c9 100644 --- a/influxdb/client.py +++ b/influxdb/client.py @@ -6,6 +6,8 @@ import socket import requests +from influxdb import chunked_json + try: xrange except NameError: @@ -322,7 +324,11 @@ 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)) + else: + return response.json() + # Creating and Dropping Databases # diff --git a/tests/influxdb/client_test.py b/tests/influxdb/client_test.py index 101d4145..c3bb435c 100644 --- a/tests/influxdb/client_test.py +++ b/tests/influxdb/client_test.py @@ -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], @@ -257,17 +257,18 @@ 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) From ed12f4045c7b7a97a48e30953eb1da851432ef69 Mon Sep 17 00:00:00 2001 From: aviau Date: Wed, 5 Nov 2014 21:11:19 -0500 Subject: [PATCH 2/2] fixed flake8 + python3 --- influxdb/client.py | 3 +-- tests/influxdb/client_test.py | 3 ++- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/influxdb/client.py b/influxdb/client.py index 1df036c9..9aaab7c3 100644 --- a/influxdb/client.py +++ b/influxdb/client.py @@ -325,11 +325,10 @@ def query(self, query, time_precision='s', chunked=False): ) if chunked: - return list(chunked_json.loads(response.content)) + return list(chunked_json.loads(response.content.decode())) else: return response.json() - # Creating and Dropping Databases # # ### create a database diff --git a/tests/influxdb/client_test.py b/tests/influxdb/client_test.py index c3bb435c..e6079212 100644 --- a/tests/influxdb/client_test.py +++ b/tests/influxdb/client_test.py @@ -257,7 +257,8 @@ def test_query_chunked(self): 'val' ] } - example_response = json.dumps(example_object) + json.dumps(example_object) + example_response = \ + json.dumps(example_object) + json.dumps(example_object) with requests_mock.Mocker() as m: m.register_uri( 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