Skip to content

Commit 0820328

Browse files
committed
Use urlparse for parse netloc
1 parent 4fd815c commit 0820328

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

influxdb/client.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -915,13 +915,8 @@ def parse_dsn(dsn):
915915

916916

917917
def _parse_netloc(netloc):
918-
import re
919-
parsed = re.findall(r'(\w*):(\w*)@([a-zA-Z0-9_\.]*):(\d*)', netloc)
920-
if not parsed:
921-
raise ValueError('Invalid netloc "{}".'.format(netloc))
922-
923-
info = parsed[0]
924-
return {'username': info[0] or None,
925-
'password': info[1] or None,
926-
'host': info[2] or 'localhost',
927-
'port': info[3] or 8086}
918+
info = urlparse("http://{}".format(netloc))
919+
return {'username': info.username or None,
920+
'password': info.password or None,
921+
'host': info.hostname or 'localhost',
922+
'port': info.port or 8086}

influxdb/tests/client_test.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ def test_scheme(self):
108108
self.assertEqual('https://host:8086', cli._baseurl)
109109

110110
def test_dsn(self):
111+
cli = InfluxDBClient.from_DSN('influxdb://192.168.0.1:1886')
112+
self.assertEqual('http://192.168.0.1:1886', cli._baseurl)
113+
111114
cli = InfluxDBClient.from_DSN(self.dsn_string)
112115
self.assertEqual('http://my.host.fr:1886', cli._baseurl)
113116
self.assertEqual('uSr', cli._username)

0 commit comments

Comments
 (0)