This repository was archived by the owner on Oct 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 524
Add some small improvements #536
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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. | ||
|
@@ -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, | ||
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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'): | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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: