Add __all__ entry, fix Python 2.5 compatibiility issue.
Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/6cabe9cc Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/6cabe9cc Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/6cabe9cc Branch: refs/heads/trunk Commit: 6cabe9cce4fe4f1a3273bfb0ba77f085586ebd96 Parents: fe81fef Author: Tomaz Muraus <[email protected]> Authored: Sun Jul 19 17:22:35 2015 +0800 Committer: Tomaz Muraus <[email protected]> Committed: Sun Jul 19 17:22:35 2015 +0800 ---------------------------------------------------------------------- libcloud/utils/misc.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/libcloud/blob/6cabe9cc/libcloud/utils/misc.py ---------------------------------------------------------------------- diff --git a/libcloud/utils/misc.py b/libcloud/utils/misc.py index 6389827..b8b70f3 100644 --- a/libcloud/utils/misc.py +++ b/libcloud/utils/misc.py @@ -42,6 +42,7 @@ __all__ = [ 'reverse_dict', 'lowercase_keys', 'get_secure_random_string', + 'retry', 'ReprMixin' ] @@ -301,11 +302,11 @@ def retry(retry_exceptions=EXCEPTION_TYPES, retry_delay=None, timeout=None, backoff=None): """ Retry method that helps to handle common exception. - :param func: the function to execute. - :param timeout: maximum time to wait. + + :param retry_exceptions: types of exceptions to retry on. :param retry_delay: retry delay between the attempts. + :param timeout: maximum time to wait. :param backoff: multiplier added to delay between attempts. - :param retry_exceptions: types of exceptions to retry on. :Example: @@ -322,17 +323,19 @@ def retry(retry_exceptions=EXCEPTION_TYPES, retry_delay=None, try: result = func(*args, **kwargs) return result - except retry_exceptions as exc: - if isinstance(exc, RateLimit): - time.sleep(exc.retry_after) + except retry_exceptions: + e = sys.exc_info()[1] + + if isinstance(e, RateLimit): + time.sleep(e.retry_after) end = datetime.now() + timedelta( - seconds=exc.retry_after + timeout) + seconds=e.retry_after + timeout) else: - exc_info = sys.exc_info() + exc_info = e time.sleep(delay) delay *= backoff if exc_info: - raise exc_info[1] + raise exc_info return func(*args, **kwargs) return retry_loop return deco_retry
