From d60e3df062b659275c899dabd1cf6652d76c6720 Mon Sep 17 00:00:00 2001 From: baftek Date: Sat, 19 Aug 2017 19:15:12 +0200 Subject: [PATCH 1/5] data arg in write() can be single string data argument in write() was expected to be list of strings, now it can be single string as well --- influxdb/client.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/influxdb/client.py b/influxdb/client.py index f8cea2ac..ceb0645f 100644 --- a/influxdb/client.py +++ b/influxdb/client.py @@ -270,7 +270,7 @@ def write(self, data, params=None, expected_response_code=204, :param data: the data to be written :type data: (if protocol is 'json') dict - (if protocol is 'line') sequence of line protocol strings + (if protocol is 'line') sequence of line protocol strings or single string :param params: additional parameters for the request, defaults to None :type params: dict :param expected_response_code: the expected response code of the write @@ -284,7 +284,7 @@ def write(self, data, params=None, expected_response_code=204, headers = self._headers headers['Content-type'] = 'application/octet-stream' - if params: + if params and 'precision' in params: precision = params.get('precision') else: precision = None @@ -292,7 +292,10 @@ def write(self, data, params=None, expected_response_code=204, if protocol == 'json': data = make_lines(data, precision).encode('utf-8') elif protocol == 'line': - data = ('\n'.join(data) + '\n').encode('utf-8') + if type(data) == list: + data = ('\n'.join(data) + '\n').encode('utf-8') + elif type(data) == str: + data = data.encode('utf-8') self.request( url="write", From 775880abb1b4d8cf153edd6710eeb2902254671f Mon Sep 17 00:00:00 2001 From: baftek Date: Sat, 19 Aug 2017 19:46:25 +0200 Subject: [PATCH 2/5] Fix linter error --- influxdb/client.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/influxdb/client.py b/influxdb/client.py index ceb0645f..495f184c 100644 --- a/influxdb/client.py +++ b/influxdb/client.py @@ -270,7 +270,8 @@ def write(self, data, params=None, expected_response_code=204, :param data: the data to be written :type data: (if protocol is 'json') dict - (if protocol is 'line') sequence of line protocol strings or single string + (if protocol is 'line') sequence of line protocol strings + or single string :param params: additional parameters for the request, defaults to None :type params: dict :param expected_response_code: the expected response code of the write From 2a0729783f53f5cb02067631d69fd3259587786b Mon Sep 17 00:00:00 2001 From: baftek Date: Sun, 20 Aug 2017 13:00:24 +0200 Subject: [PATCH 3/5] Trailing whitespace removed --- influxdb/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/influxdb/client.py b/influxdb/client.py index 495f184c..9af56fe3 100644 --- a/influxdb/client.py +++ b/influxdb/client.py @@ -270,7 +270,7 @@ def write(self, data, params=None, expected_response_code=204, :param data: the data to be written :type data: (if protocol is 'json') dict - (if protocol is 'line') sequence of line protocol strings + (if protocol is 'line') sequence of line protocol strings or single string :param params: additional parameters for the request, defaults to None :type params: dict From a0f92b33d02bf32bd6378afd94ceff96b179bc33 Mon Sep 17 00:00:00 2001 From: baftek Date: Mon, 21 Aug 2017 17:09:36 +0200 Subject: [PATCH 4/5] Transformed to isinstance instead of using type() --- influxdb/client.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/influxdb/client.py b/influxdb/client.py index 9af56fe3..03ad2d1a 100644 --- a/influxdb/client.py +++ b/influxdb/client.py @@ -285,7 +285,7 @@ def write(self, data, params=None, expected_response_code=204, headers = self._headers headers['Content-type'] = 'application/octet-stream' - if params and 'precision' in params: + if params: precision = params.get('precision') else: precision = None @@ -293,10 +293,9 @@ def write(self, data, params=None, expected_response_code=204, if protocol == 'json': data = make_lines(data, precision).encode('utf-8') elif protocol == 'line': - if type(data) == list: - data = ('\n'.join(data) + '\n').encode('utf-8') - elif type(data) == str: - data = data.encode('utf-8') + if isinstance(data, str): + data = list(data) + data = ('\n'.join(data) + '\n').encode('utf-8') self.request( url="write", From 3b2a79b9170e27d7e7ae6e110e205cb785131411 Mon Sep 17 00:00:00 2001 From: baftek Date: Mon, 21 Aug 2017 17:57:57 +0200 Subject: [PATCH 5/5] Change list(str) to [str] --- influxdb/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/influxdb/client.py b/influxdb/client.py index 03ad2d1a..7930679c 100644 --- a/influxdb/client.py +++ b/influxdb/client.py @@ -294,7 +294,7 @@ def write(self, data, params=None, expected_response_code=204, data = make_lines(data, precision).encode('utf-8') elif protocol == 'line': if isinstance(data, str): - data = list(data) + data = [data] data = ('\n'.join(data) + '\n').encode('utf-8') self.request( 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