diff --git a/troveclient/openstack/common/apiclient/exceptions.py b/troveclient/openstack/common/apiclient/exceptions.py index b03def77..fec8ade1 100644 --- a/troveclient/openstack/common/apiclient/exceptions.py +++ b/troveclient/openstack/common/apiclient/exceptions.py @@ -22,8 +22,11 @@ Exception definitions. """ +import inspect import sys +import six + class ClientException(Exception): """The base exception class for all exceptions this library raises. @@ -387,20 +390,12 @@ class HttpVersionNotSupported(HttpServerError): message = "HTTP Version Not Supported" -# In Python 2.4 Exception is old-style and thus doesn't have a __subclasses__() -# so we can do this: -# _code_map = dict((c.http_status, c) -# for c in HttpError.__subclasses__()) -_code_map = {} -for obj in sys.modules[__name__].__dict__.values(): - if isinstance(obj, type): - try: - http_status = obj.http_status - except AttributeError: - pass - else: - if http_status: - _code_map[http_status] = obj +# _code_map contains all the classes that have http_status attribute. +_code_map = dict( + (getattr(obj, 'http_status', None), obj) + for name, obj in six.iteritems(vars(sys.modules[__name__])) + if inspect.isclass(obj) and getattr(obj, 'http_status', False) +) def from_response(response, method, url):