libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject [3/7] libcloud git commit: Be consistent with the exception class names - add "Error" suffix to all the exception classes.
Date Sun, 19 Jul 2015 10:06:32 GMT
Be consistent with the exception class names - add "Error" suffix to all the
exception classes.


Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/6ffffa33
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/6ffffa33
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/6ffffa33

Branch: refs/heads/trunk
Commit: 6ffffa338bb624f2e8d3f79a5c38d960667af1c1
Parents: 6cabe9c
Author: Tomaz Muraus <tomaz@tomaz.me>
Authored: Sun Jul 19 17:29:19 2015 +0800
Committer: Tomaz Muraus <tomaz@tomaz.me>
Committed: Sun Jul 19 17:31:20 2015 +0800

----------------------------------------------------------------------
 libcloud/common/exceptions.py             | 22 ++++++++++++++--------
 libcloud/test/compute/test_retry_limit.py |  9 +++++----
 libcloud/utils/misc.py                    |  6 +++---
 3 files changed, 22 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/6ffffa33/libcloud/common/exceptions.py
----------------------------------------------------------------------
diff --git a/libcloud/common/exceptions.py b/libcloud/common/exceptions.py
index 6768945..518d5c1 100644
--- a/libcloud/common/exceptions.py
+++ b/libcloud/common/exceptions.py
@@ -13,27 +13,33 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+__all__ = [
+    'BaseHTTPError',
+    'RateLimitReachedError',
 
-class BaseHTTPException(Exception):
+    'exception_from_message'
+]
+
+
+class BaseHTTPError(Exception):
 
     """
-    The base exception class for all exception raises.
+    The base exception class for all HTTP related eceptions.
     """
 
     def __init__(self, code, message, headers=None):
-
-        self.message = message
         self.code = code
+        self.message = message
         self.headers = headers
         # preserve old exception behavior for tests that
         # look for e.args[0]
-        super(BaseHTTPException, self).__init__(message)
+        super(BaseHTTPError, self).__init__(message)
 
     def __str__(self):
         return self.message
 
 
-class RateLimit(BaseHTTPException):
+class RateLimitReachedError(BaseHTTPError):
     """
     HTTP 429 - Rate limit: you've sent too many requests for this time period.
     """
@@ -47,7 +53,7 @@ class RateLimit(BaseHTTPException):
             self.retry_after = 0
 
 
-_error_classes = [RateLimit]
+_error_classes = [RateLimitReachedError]
 _code_map = dict((c.code, c) for c in _error_classes)
 
 
@@ -68,5 +74,5 @@ def exception_from_message(code, message, headers=None):
     if headers and 'retry_after' in headers:
         kwargs['retry_after'] = headers['retry_after']
 
-    cls = _code_map.get(code, BaseHTTPException)
+    cls = _code_map.get(code, BaseHTTPError)
     return cls(**kwargs)

http://git-wip-us.apache.org/repos/asf/libcloud/blob/6ffffa33/libcloud/test/compute/test_retry_limit.py
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/test_retry_limit.py b/libcloud/test/compute/test_retry_limit.py
index d285c80..72e3710 100644
--- a/libcloud/test/compute/test_retry_limit.py
+++ b/libcloud/test/compute/test_retry_limit.py
@@ -12,15 +12,16 @@
 # 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.
+
 import socket
 import tempfile
-from libcloud.utils.py3 import httplib
 
 from mock import Mock, patch, MagicMock
 
+from libcloud.utils.py3 import httplib
 from libcloud.common.base import Connection
 from libcloud.common.base import Response
-from libcloud.common.exceptions import RateLimit
+from libcloud.common.exceptions import RateLimitReachedError
 from libcloud.test import unittest
 
 CONFLICT_RESPONSE_STATUS = [
@@ -30,7 +31,7 @@ CONFLICT_RESPONSE_STATUS = [
 SIMPLE_RESPONSE_STATUS = ('HTTP/1.1', 429, 'CONFLICT')
 
 
-class RateLimitTestCase(unittest.TestCase):
+class FailedRequestRetryTestCase(unittest.TestCase):
 
     def _raise_socket_error(self):
         raise socket.gaierror('')
@@ -66,7 +67,7 @@ class RateLimitTestCase(unittest.TestCase):
                         mock_obj = httplib.HTTPResponse(sock)
                         mock_obj.begin()
                         Response(mock_obj, con)
-        except RateLimit:
+        except RateLimitReachedError:
             pass
         except Exception:
             self.fail('Failed to raise Rate Limit exception')

http://git-wip-us.apache.org/repos/asf/libcloud/blob/6ffffa33/libcloud/utils/misc.py
----------------------------------------------------------------------
diff --git a/libcloud/utils/misc.py b/libcloud/utils/misc.py
index b8b70f3..970feaa 100644
--- a/libcloud/utils/misc.py
+++ b/libcloud/utils/misc.py
@@ -23,12 +23,12 @@ import socket
 from datetime import datetime, timedelta
 import time
 
-from libcloud.common.exceptions import RateLimit
+from libcloud.common.exceptions import RateLimitReachedError
 
 DEFAULT_TIMEOUT = 30
 DEFAULT_SLEEP = 1
 DEFAULT_BACKCOFF = 1
-EXCEPTION_TYPES = (RateLimit, socket.error, socket.gaierror,
+EXCEPTION_TYPES = (RateLimitReachedError, socket.error, socket.gaierror,
                    httplib.NotConnected, httplib.ImproperConnectionState)
 
 __all__ = [
@@ -326,7 +326,7 @@ def retry(retry_exceptions=EXCEPTION_TYPES, retry_delay=None,
                 except retry_exceptions:
                     e = sys.exc_info()[1]
 
-                    if isinstance(e, RateLimit):
+                    if isinstance(e, RateLimitReachedError):
                         time.sleep(e.retry_after)
                         end = datetime.now() + timedelta(
                             seconds=e.retry_after + timeout)


Mime
View raw message