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

move use_udp and udp_port private #477

Merged
merged 1 commit into from
Aug 15, 2017
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
18 changes: 13 additions & 5 deletions influxdb/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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"
)
Expand All @@ -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(
Expand Down Expand Up @@ -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."""
Expand Down
10 changes: 5 additions & 5 deletions influxdb/influxdb08/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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"
)
Expand All @@ -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(
Expand Down Expand Up @@ -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))
4 changes: 2 additions & 2 deletions influxdb/tests/client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions influxdb/tests/influxdb08/client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down