From 0820328718556e4143d85b7787ae14874da5e2ea Mon Sep 17 00:00:00 2001 From: William Pain Date: Tue, 8 Dec 2015 11:02:47 +0100 Subject: [PATCH] Use urlparse for parse netloc --- influxdb/client.py | 15 +++++---------- influxdb/tests/client_test.py | 3 +++ 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/influxdb/client.py b/influxdb/client.py index b9fcb0c3..683e0bcb 100644 --- a/influxdb/client.py +++ b/influxdb/client.py @@ -915,13 +915,8 @@ def parse_dsn(dsn): def _parse_netloc(netloc): - import re - parsed = re.findall(r'(\w*):(\w*)@([a-zA-Z0-9_\.]*):(\d*)', netloc) - if not parsed: - raise ValueError('Invalid netloc "{}".'.format(netloc)) - - info = parsed[0] - return {'username': info[0] or None, - 'password': info[1] or None, - 'host': info[2] or 'localhost', - 'port': info[3] or 8086} + info = urlparse("http://{}".format(netloc)) + return {'username': info.username or None, + 'password': info.password or None, + 'host': info.hostname or 'localhost', + 'port': info.port or 8086} diff --git a/influxdb/tests/client_test.py b/influxdb/tests/client_test.py index 24f5d0a4..dc4ab306 100644 --- a/influxdb/tests/client_test.py +++ b/influxdb/tests/client_test.py @@ -108,6 +108,9 @@ def test_scheme(self): self.assertEqual('https://host:8086', cli._baseurl) def test_dsn(self): + cli = InfluxDBClient.from_DSN('influxdb://192.168.0.1:1886') + self.assertEqual('http://192.168.0.1:1886', cli._baseurl) + cli = InfluxDBClient.from_DSN(self.dsn_string) self.assertEqual('http://my.host.fr:1886', cli._baseurl) self.assertEqual('uSr', cli._username) 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