Sync up exceptions.py from oslo
oslo change: I169b13546bcd0d87353dbca5a9b64229b704fe66 Define _code_map in an expression. Partial implements: blueprint py33-support Change-Id: I4b9f5bc083ebe62739a33674d26728d4a8f1a2d6
This commit is contained in:
@@ -22,8 +22,11 @@
|
|||||||
Exception definitions.
|
Exception definitions.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import inspect
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
import six
|
||||||
|
|
||||||
|
|
||||||
class ClientException(Exception):
|
class ClientException(Exception):
|
||||||
"""The base exception class for all exceptions this library raises.
|
"""The base exception class for all exceptions this library raises.
|
||||||
@@ -387,20 +390,12 @@ class HttpVersionNotSupported(HttpServerError):
|
|||||||
message = "HTTP Version Not Supported"
|
message = "HTTP Version Not Supported"
|
||||||
|
|
||||||
|
|
||||||
# In Python 2.4 Exception is old-style and thus doesn't have a __subclasses__()
|
# _code_map contains all the classes that have http_status attribute.
|
||||||
# so we can do this:
|
_code_map = dict(
|
||||||
# _code_map = dict((c.http_status, c)
|
(getattr(obj, 'http_status', None), obj)
|
||||||
# for c in HttpError.__subclasses__())
|
for name, obj in six.iteritems(vars(sys.modules[__name__]))
|
||||||
_code_map = {}
|
if inspect.isclass(obj) and getattr(obj, 'http_status', False)
|
||||||
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
|
|
||||||
|
|
||||||
|
|
||||||
def from_response(response, method, url):
|
def from_response(response, method, url):
|
||||||
|
Reference in New Issue
Block a user