From 3f54847176533156da2ac26a88183c5a16e9d24a Mon Sep 17 00:00:00 2001 From: Sebastian Borza Date: Fri, 7 Jul 2017 08:00:16 -0500 Subject: [PATCH] move use_udp and udp_port private --- influxdb/client.py | 18 +++++++++++++----- influxdb/influxdb08/client.py | 10 +++++----- influxdb/tests/client_test.py | 4 ++-- influxdb/tests/influxdb08/client_test.py | 4 ++-- 4 files changed, 22 insertions(+), 14 deletions(-) diff --git a/influxdb/client.py b/influxdb/client.py index 14bf3f72..f8cea2ac 100644 --- a/influxdb/client.py +++ b/influxdb/client.py @@ -91,8 +91,8 @@ def __init__(self, self._verify_ssl = verify_ssl - self.use_udp = use_udp - self.udp_port = udp_port + self.__use_udp = use_udp + self.__udp_port = udp_port self._session = requests.Session() if use_udp: self.udp_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) @@ -129,6 +129,14 @@ def _host(self): def _port(self): return self.__port + @property + def _udp_port(self): + return self.__udp_port + + @property + def _use_udp(self): + return self.__use_udp + @classmethod def from_dsn(cls, dsn, **kwargs): r"""Generate an instance of InfluxDBClient from given data source name. @@ -467,7 +475,7 @@ def _write_points(self, "Invalid time precision is given. " "(use 'n', 'u', 'ms', 's', 'm' or 'h')") - if self.use_udp and time_precision and time_precision != 's': + if self._use_udp and time_precision and time_precision != 's': raise ValueError( "InfluxDB only supports seconds precision for udp writes" ) @@ -492,7 +500,7 @@ def _write_points(self, if retention_policy is not None: params['rp'] = retention_policy - if self.use_udp: + if self._use_udp: self.send_packet(data, protocol=protocol) else: self.write( @@ -821,7 +829,7 @@ def send_packet(self, packet, protocol='json'): data = make_lines(packet).encode('utf-8') elif protocol == 'line': data = ('\n'.join(packet) + '\n').encode('utf-8') - self.udp_socket.sendto(data, (self._host, self.udp_port)) + self.udp_socket.sendto(data, (self._host, self._udp_port)) def close(self): """Close http session.""" diff --git a/influxdb/influxdb08/client.py b/influxdb/influxdb08/client.py index 59a01f54..9954133e 100644 --- a/influxdb/influxdb08/client.py +++ b/influxdb/influxdb08/client.py @@ -92,8 +92,8 @@ def __init__(self, self._verify_ssl = verify_ssl - self.use_udp = use_udp - self.udp_port = udp_port + self._use_udp = use_udp + self._udp_port = udp_port if use_udp: self.udp_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) @@ -344,7 +344,7 @@ def _write_points(self, data, time_precision): raise Exception( "Invalid time precision is given. (use 's', 'm', 'ms' or 'u')") - if self.use_udp and time_precision != 's': + if self._use_udp and time_precision != 's': raise Exception( "InfluxDB only supports seconds precision for udp writes" ) @@ -355,7 +355,7 @@ def _write_points(self, data, time_precision): 'time_precision': time_precision } - if self.use_udp: + if self._use_udp: self.send_packet(data) else: self.request( @@ -849,4 +849,4 @@ def send_packet(self, packet): """Send a UDP packet along the wire.""" data = json.dumps(packet) byte = data.encode('utf-8') - self.udp_socket.sendto(byte, (self._host, self.udp_port)) + self.udp_socket.sendto(byte, (self._host, self._udp_port)) diff --git a/influxdb/tests/client_test.py b/influxdb/tests/client_test.py index 8def6629..8768d170 100644 --- a/influxdb/tests/client_test.py +++ b/influxdb/tests/client_test.py @@ -119,10 +119,10 @@ def test_dsn(self): self.assertEqual('uSr', cli._username) self.assertEqual('pWd', cli._password) self.assertEqual('db', cli._database) - self.assertFalse(cli.use_udp) + self.assertFalse(cli._use_udp) cli = InfluxDBClient.from_dsn('udp+' + self.dsn_string) - self.assertTrue(cli.use_udp) + self.assertTrue(cli._use_udp) cli = InfluxDBClient.from_dsn('https+' + self.dsn_string) self.assertEqual('https://my.host.fr:1886', cli._baseurl) diff --git a/influxdb/tests/influxdb08/client_test.py b/influxdb/tests/influxdb08/client_test.py index 4a789fb5..39ab52d6 100644 --- a/influxdb/tests/influxdb08/client_test.py +++ b/influxdb/tests/influxdb08/client_test.py @@ -113,10 +113,10 @@ def test_dsn(self): self.assertEqual('uSr', cli._username) self.assertEqual('pWd', cli._password) self.assertEqual('db', cli._database) - self.assertFalse(cli.use_udp) + self.assertFalse(cli._use_udp) cli = InfluxDBClient.from_dsn('udp+' + self.dsn_string) - self.assertTrue(cli.use_udp) + self.assertTrue(cli._use_udp) cli = InfluxDBClient.from_dsn('https+' + self.dsn_string) self.assertEqual('https://host:1886', cli._baseurl)