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:
Kui Shi
2013-10-21 16:58:14 +08:00
parent 502f7113a8
commit b46248c98f

View File

@@ -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):