Some style clean up.
Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/309e7743 Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/309e7743 Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/309e7743 Branch: refs/heads/trunk Commit: 309e7743c9d817456587985f2f9c51b7a461063c Parents: 5733de3 Author: Tomaz Muraus <[email protected]> Authored: Sun Jan 10 16:34:46 2016 +0100 Committer: Tomaz Muraus <[email protected]> Committed: Sun Jan 10 16:34:46 2016 +0100 ---------------------------------------------------------------------- libcloud/utils/misc.py | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/libcloud/blob/309e7743/libcloud/utils/misc.py ---------------------------------------------------------------------- diff --git a/libcloud/utils/misc.py b/libcloud/utils/misc.py index 1902d23..0162511 100644 --- a/libcloud/utils/misc.py +++ b/libcloud/utils/misc.py @@ -12,36 +12,19 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -from functools import wraps import os import sys import binascii -from libcloud.utils.py3 import httplib - import socket -from datetime import datetime, timedelta import time import ssl +from datetime import datetime, timedelta +from functools import wraps +from libcloud.utils.py3 import httplib from libcloud.common.exceptions import RateLimitReachedError - -TRANSIENT_SSL_ERROR = 'The read operation timed out' - - -class TransientSSLError(ssl.SSLError): - """Represent transient SSL errors, e.g. timeouts""" - pass - - -DEFAULT_TIMEOUT = 30 -DEFAULT_DELAY = 1 -DEFAULT_BACKOFF = 1 -RETRY_EXCEPTIONS = (RateLimitReachedError, socket.error, socket.gaierror, - httplib.NotConnected, httplib.ImproperConnectionState, - TransientSSLError) - __all__ = [ 'find', 'get_driver', @@ -58,6 +41,23 @@ __all__ = [ 'ReprMixin' ] +# Error message which indicates a transient SSL error upon which request +# can be retried +TRANSIENT_SSL_ERROR = 'The read operation timed out' + + +class TransientSSLError(ssl.SSLError): + """Represent transient SSL errors, e.g. timeouts""" + pass + + +DEFAULT_TIMEOUT = 30 +DEFAULT_DELAY = 1 +DEFAULT_BACKOFF = 1 +RETRY_EXCEPTIONS = (RateLimitReachedError, socket.error, socket.gaierror, + httplib.NotConnected, httplib.ImproperConnectionState, + TransientSSLError) + def find(l, predicate): results = [x for x in l if predicate(x)] @@ -309,8 +309,8 @@ class ReprMixin(object): return str(self.__repr__()) -def retry(retry_exceptions=None, retry_delay=None, timeout=None, - backoff=None): +def retry(retry_exceptions=RETRY_EXCEPTIONS, retry_delay=DEFAULT_DELAY, + timeout=DEFAULT_TIMEOUT, backoff=DEFAULT_BACKOFF): """ Retry decorator that helps to handle common transient exceptions.
