Use httplib constants for http status codes

The httplib (py2) and http.client (py3) have nice constants for all
the standard HTTP status codes. This patch changes the exception
module to make use of those.

Change-Id: I67d3717dca5aecf3c8b36f5b69f1ca659c0b08b1
This commit is contained in:
Eric Brown 2016-09-29 16:41:45 -07:00
parent 9bb57c1eb7
commit a899334d2a

View File

@ -15,6 +15,7 @@
from oslo_log import log
from oslo_utils import encodeutils
import six
from six.moves import http_client
import keystone.conf
from keystone.i18n import _, _LW
@ -84,8 +85,8 @@ class ValidationError(Error):
" The server could not comply with the request"
" since it is either malformed or otherwise"
" incorrect. The client is assumed to be in error.")
code = 400
title = 'Bad Request'
code = int(http_client.BAD_REQUEST)
title = http_client.responses[http_client.BAD_REQUEST]
class URLValidationError(ValidationError):
@ -129,8 +130,8 @@ class ValidationTimeStampError(Error):
" The server could not comply with the request"
" since it is either malformed or otherwise"
" incorrect. The client is assumed to be in error.")
code = 400
title = 'Bad Request'
code = int(http_client.BAD_REQUEST)
title = http_client.responses[http_client.BAD_REQUEST]
class InvalidOperatorError(ValidationError):
@ -144,8 +145,8 @@ class ValidationExpirationError(Error):
" The server could not comply with the request"
" since it is either malformed or otherwise"
" incorrect. The client is assumed to be in error.")
code = 400
title = 'Bad Request'
code = int(http_client.BAD_REQUEST)
title = http_client.responses[http_client.BAD_REQUEST]
class StringLengthExceeded(ValidationError):
@ -160,15 +161,15 @@ class ValidationSizeError(Error):
" could not comply with the request because"
" the attribute size is invalid (too large)."
" The client is assumed to be in error.")
code = 400
title = 'Bad Request'
code = int(http_client.BAD_REQUEST)
title = http_client.responses[http_client.BAD_REQUEST]
class CircularRegionHierarchyError(Error):
message_format = _("The specified parent region %(parent_region_id)s "
"would create a circular region hierarchy.")
code = 400
title = 'Bad Request'
code = int(http_client.BAD_REQUEST)
title = http_client.responses[http_client.BAD_REQUEST]
class ForbiddenNotSecurity(Error):
@ -179,8 +180,8 @@ class ForbiddenNotSecurity(Error):
"""
code = 403
title = 'Forbidden'
code = int(http_client.FORBIDDEN)
title = http_client.responses[http_client.FORBIDDEN]
class PasswordVerificationError(ForbiddenNotSecurity):
@ -249,8 +250,8 @@ class SecurityError(Error):
class Unauthorized(SecurityError):
message_format = _("The request you have made requires authentication.")
code = 401
title = 'Unauthorized'
code = int(http_client.UNAUTHORIZED)
title = http_client.responses[http_client.UNAUTHORIZED]
class InsufficientAuthMethods(Error):
@ -302,8 +303,8 @@ class AdditionalAuthRequired(AuthPluginException):
class Forbidden(SecurityError):
message_format = _("You are not authorized to perform the"
" requested action.")
code = 403
title = 'Forbidden'
code = int(http_client.FORBIDDEN)
title = http_client.responses[http_client.FORBIDDEN]
class ForbiddenAction(Forbidden):
@ -330,8 +331,8 @@ class InvalidDomainConfig(Forbidden):
class NotFound(Error):
message_format = _("Could not find: %(target)s.")
code = 404
title = 'Not Found'
code = int(http_client.NOT_FOUND)
title = http_client.responses[http_client.NOT_FOUND]
class EndpointNotFound(NotFound):
@ -460,8 +461,8 @@ class ConfigRegistrationNotFound(Exception):
class Conflict(Error):
message_format = _("Conflict occurred attempting to store %(type)s -"
" %(details)s.")
code = 409
title = 'Conflict'
code = int(http_client.CONFLICT)
title = http_client.responses[http_client.CONFLICT]
class UnexpectedError(SecurityError):
@ -483,8 +484,8 @@ class UnexpectedError(SecurityError):
return super(UnexpectedError, self)._build_message(
message or self.debug_message_format, **kwargs)
code = 500
title = 'Internal Server Error'
code = int(http_client.INTERNAL_SERVER_ERROR)
title = http_client.responses[http_client.INTERNAL_SERVER_ERROR]
class TrustConsumeMaximumAttempt(UnexpectedError):
@ -528,15 +529,15 @@ class AssignmentTypeCalculationError(UnexpectedError):
class NotImplemented(Error):
message_format = _("The action you have requested has not"
" been implemented.")
code = 501
title = 'Not Implemented'
code = int(http_client.NOT_IMPLEMENTED)
title = http_client.responses[http_client.NOT_IMPLEMENTED]
class Gone(Error):
message_format = _("The service you have requested is no"
" longer available on this server.")
code = 410
title = 'Gone'
code = int(http_client.GONE)
title = http_client.responses[http_client.GONE]
class ConfigFileNotFound(UnexpectedError):