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

Add some small improvements #536

Merged
merged 3 commits into from
Nov 14, 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
8 changes: 4 additions & 4 deletions influxdb/_dataframe_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.')
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this was ever raised, the formatting would end up looking weird:

>>> raise TypeError('this is a long error message \
...                 that gets split over lines, but look \
...                 at all those spaces!')
Traceback (most recent call last):
  File "<stdin>", line 3, in <module>
TypeError: this is a long error message                 that gets split over lines, but look                 at all those spaces!


# Make sure tags and tag columns are correctly typed
tag_columns = tag_columns if tag_columns is not None else []
Expand Down Expand Up @@ -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)
Expand Down
36 changes: 11 additions & 25 deletions influxdb/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,21 @@
from __future__ import print_function
from __future__ import unicode_literals

from sys import version_info
import time
import random

import json
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.
Expand Down Expand Up @@ -239,7 +230,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,
Expand All @@ -254,25 +244,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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

linters like this approach a little better, and it also gives more digestible tracebacks IMO:

>>> e = None
>>> try:
...     raise ValueError('this is a raised value error')
... except ValueError as _e:
...     e = _e
... 
>>> raise(e)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 2, in <module>
ValueError: this is a raised value error
>>> try:
...     raise ValueError('this is a raised value error')
... except ValueError:
...     raise
... 
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
ValueError: this is a raised value error

This seems to be the original intent.

# 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'):
Expand Down
13 changes: 2 additions & 11 deletions influxdb/influxdb08/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()


Expand Down