From e66a8b29fa0c176ff6e3c11505ddfd2def22282b Mon Sep 17 00:00:00 2001 From: root Date: Thu, 27 Feb 2020 22:44:49 +0100 Subject: [PATCH 1/4] implement gzip compression --- influxdb/client.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/influxdb/client.py b/influxdb/client.py index 5e39f490..49ab5d9e 100644 --- a/influxdb/client.py +++ b/influxdb/client.py @@ -18,6 +18,7 @@ import requests.exceptions from six.moves import xrange from six.moves.urllib.parse import urlparse +import gzip from influxdb.line_protocol import make_lines, quote_ident, quote_literal from influxdb.resultset import ResultSet @@ -89,6 +90,7 @@ def __init__(self, pool_size=10, path='', cert=None, + compression=False ): """Construct a new InfluxDBClient object.""" self.__host = host @@ -98,6 +100,10 @@ def __init__(self, self._database = database self._timeout = timeout self._retries = retries + if compression == True: + self._compression = 9 + else: + self._compression = compression self._verify_ssl = verify_ssl @@ -354,6 +360,10 @@ def write(self, data, params=None, expected_response_code=204, data = [data] data = ('\n'.join(data) + '\n').encode('utf-8') + if self._compression != False: + data = gzip.compress(data, self._compression) + headers['Content-Encoding'] = 'gzip' + self.request( url="write", method='POST', From 253cb4b55235dd44c1542e65baba3b1c460835f0 Mon Sep 17 00:00:00 2001 From: root Date: Sun, 1 Mar 2020 11:06:49 +0100 Subject: [PATCH 2/4] assert that compression parameter is within limits --- influxdb/client.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/influxdb/client.py b/influxdb/client.py index 49ab5d9e..bacd16ff 100644 --- a/influxdb/client.py +++ b/influxdb/client.py @@ -105,6 +105,8 @@ def __init__(self, else: self._compression = compression + assert self._compression == False or (self._compression >= 0 and self._compression <= 9) + self._verify_ssl = verify_ssl self.__use_udp = use_udp From cfbaa445e19fc52ec149b4bd875739b296d0b679 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 10 Mar 2020 21:40:23 +0100 Subject: [PATCH 3/4] make flake8 happy --- influxdb/client.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/influxdb/client.py b/influxdb/client.py index bacd16ff..d0a74d9d 100644 --- a/influxdb/client.py +++ b/influxdb/client.py @@ -100,12 +100,13 @@ def __init__(self, self._database = database self._timeout = timeout self._retries = retries - if compression == True: + if compression is True: self._compression = 9 else: self._compression = compression - assert self._compression == False or (self._compression >= 0 and self._compression <= 9) + assert self._compression is False or \ + (self._compression >= 0 and self._compression <= 9) self._verify_ssl = verify_ssl @@ -362,7 +363,7 @@ def write(self, data, params=None, expected_response_code=204, data = [data] data = ('\n'.join(data) + '\n').encode('utf-8') - if self._compression != False: + if self._compression is not False: data = gzip.compress(data, self._compression) headers['Content-Encoding'] = 'gzip' From 4974434ca9bb8cad71980d768b16c598bc706f78 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 10 Mar 2020 22:01:20 +0100 Subject: [PATCH 4/4] flake8: fix indent --- influxdb/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/influxdb/client.py b/influxdb/client.py index d0a74d9d..3ebf7ab0 100644 --- a/influxdb/client.py +++ b/influxdb/client.py @@ -106,7 +106,7 @@ def __init__(self, self._compression = compression assert self._compression is False or \ - (self._compression >= 0 and self._compression <= 9) + (self._compression >= 0 and self._compression <= 9) self._verify_ssl = verify_ssl