From ea4df384a4f78584883594c2f1efa5b315f75a1e Mon Sep 17 00:00:00 2001 From: Jason Swails Date: Thu, 9 Nov 2017 13:39:45 -0500 Subject: [PATCH 1/2] Add some small improvements - six is already listed as a requirement, so use six.moves instead of defining builtins based on checking sys.version_info - Fix formatting of several exceptions. --- influxdb/_dataframe_client.py | 8 ++++---- influxdb/client.py | 37 +++++++++++------------------------ influxdb/influxdb08/client.py | 13 ++---------- 3 files changed, 17 insertions(+), 41 deletions(-) diff --git a/influxdb/_dataframe_client.py b/influxdb/_dataframe_client.py index 31a78672..6a66558b 100644 --- a/influxdb/_dataframe_client.py +++ b/influxdb/_dataframe_client.py @@ -222,8 +222,8 @@ def _convert_dataframe_to_json(dataframe, .format(type(dataframe))) if not (isinstance(dataframe.index, pd.PeriodIndex) or isinstance(dataframe.index, pd.DatetimeIndex)): - raise TypeError('Must be DataFrame with DatetimeIndex or \ - PeriodIndex.') + raise TypeError('Must be DataFrame with DatetimeIndex or ' + 'PeriodIndex.') # Make sure tags and tag columns are correctly typed tag_columns = tag_columns if tag_columns is not None else [] @@ -279,8 +279,8 @@ def _convert_dataframe_to_lines(self, .format(type(dataframe))) if not (isinstance(dataframe.index, pd.PeriodIndex) or isinstance(dataframe.index, pd.DatetimeIndex)): - raise TypeError('Must be DataFrame with DatetimeIndex or \ - PeriodIndex.') + raise TypeError('Must be DataFrame with DatetimeIndex or ' + 'PeriodIndex.') # Create a Series of columns for easier indexing column_series = pd.Series(dataframe.columns) diff --git a/influxdb/client.py b/influxdb/client.py index 4721fa3f..ded0e11a 100644 --- a/influxdb/client.py +++ b/influxdb/client.py @@ -6,7 +6,6 @@ from __future__ import print_function from __future__ import unicode_literals -from sys import version_info import time import random @@ -14,23 +13,14 @@ import socket import requests import requests.exceptions +from six.moves import xrange +from six.moves.urllib.parse import urlparse from influxdb.line_protocol import make_lines, quote_ident, quote_literal from influxdb.resultset import ResultSet from .exceptions import InfluxDBClientError from .exceptions import InfluxDBServerError -try: - xrange -except NameError: - xrange = range - -if version_info[0] == 3: - from urllib.parse import urlparse -else: - from urlparse import urlparse - - class InfluxDBClient(object): """InfluxDBClient primary client object to connect InfluxDB. @@ -239,7 +229,6 @@ def request(self, url, method='GET', params=None, data=None, _try = 0 while retry: try: - _error = False response = self._session.request( method=method, url=url, @@ -254,25 +243,21 @@ def request(self, url, method='GET', params=None, data=None, break except (requests.exceptions.ConnectionError, requests.exceptions.HTTPError, - requests.exceptions.Timeout) as _e: - _error = _e + requests.exceptions.Timeout): _try += 1 if self._retries != 0: retry = _try < self._retries if method == "POST": time.sleep((2 ** _try) * random.random() / 100.0) - if _error: - raise(_error) + if not retry: + raise + # if there's not an error, there must have been a successful response + if 500 <= response.status_code < 600: + raise InfluxDBServerError(response.content) + elif response.status_code == expected_response_code: + return response else: - # if there's not an error, there must have been a successful - # response - if 500 <= response.status_code < 600: - raise InfluxDBServerError(response.content) - elif response.status_code == expected_response_code: - return response - else: - raise InfluxDBClientError(response.content, - response.status_code) + raise InfluxDBClientError(response.content, response.status_code) def write(self, data, params=None, expected_response_code=204, protocol='json'): diff --git a/influxdb/influxdb08/client.py b/influxdb/influxdb08/client.py index 9954133e..41600404 100644 --- a/influxdb/influxdb08/client.py +++ b/influxdb/influxdb08/client.py @@ -2,25 +2,16 @@ """Python client for InfluxDB v0.8.""" import warnings -from sys import version_info import json import socket import requests import requests.exceptions +from six.moves import xrange +from six.moves.urllib.parse import urlparse from influxdb import chunked_json -try: - xrange -except NameError: - xrange = range - -if version_info[0] == 3: - from urllib.parse import urlparse -else: - from urlparse import urlparse - session = requests.Session() From d5234c5a14cd4ebd49055362a0a8dbaa640b63c2 Mon Sep 17 00:00:00 2001 From: Jason Swails Date: Thu, 9 Nov 2017 13:56:03 -0500 Subject: [PATCH 2/2] Add a blank line to appease flake8 --- influxdb/client.py | 1 + 1 file changed, 1 insertion(+) diff --git a/influxdb/client.py b/influxdb/client.py index ded0e11a..608e8dbc 100644 --- a/influxdb/client.py +++ b/influxdb/client.py @@ -21,6 +21,7 @@ from .exceptions import InfluxDBClientError from .exceptions import InfluxDBServerError + class InfluxDBClient(object): """InfluxDBClient primary client object to connect InfluxDB. 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