# Path: monasca_api/v2/common/exceptions.py
# class HTTPUnprocessableEntityError(HTTPError):
#     def __init__(self, title, description, **kwargs):
#         HTTPError.__init__(self, '422 Unprocessable Entity', title, description, **kwargs)


from monasca_api.v2.common.exceptions import HTTPUnprocessableEntityError
import re
    if severity.upper() not in VALID_ALARM_DEFINITION_SEVERITIES:
        raise HTTPUnprocessableEntityError(
            "Invalid Severity",
            "Severity {} must be one of {}".format(severity.encode('utf8'),
                                                   VALID_ALARM_DEFINITION_SEVERITIES))


def validate_severity_query(severity_str):
    severities = severity_str.split('|')
    for severity in severities:
        validate_alarm_definition_severity(severity)


def validate_sort_by(sort_by_list, allowed_sort_by):
    for sort_by_field in sort_by_list:
        sort_by_values = sort_by_field.split()
        if len(sort_by_values) > 2:
            raise HTTPUnprocessableEntityError("Unprocessable Entity",
                                               "Invalid sort_by {}".format(sort_by_field))
        if sort_by_values[0] not in allowed_sort_by:
            raise HTTPUnprocessableEntityError("Unprocessable Entity",
                                               "sort_by field {} must be one of [{}]".format(
                                                   sort_by_values[0],
                                                   ','.join(list(allowed_sort_by))))
        if len(sort_by_values) > 1 and sort_by_values[1] not in ['asc', 'desc']:
            raise HTTPUnprocessableEntityError("Unprocessable Entity",
                                               "sort_by value {} must be 'asc' or 'desc'".format(
                                                   sort_by_values[1]))



# Path: monasca_api/v2/common/exceptions.py
# class HTTPUnprocessableEntityError(HTTPError):
#     def __init__(self, title, description, **kwargs):
#         HTTPError.__init__(self, '422 Unprocessable Entity', title, description, **kwargs)


# Path: monasca_api/v2/common/validation.py
from monasca_api.v2.common.exceptions import HTTPUnprocessableEntityError
import re

    if severity.upper() not in VALID_ALARM_DEFINITION_SEVERITIES:
        raise HTTPUnprocessableEntityError(
            "Invalid Severity",
            "Severity {} must be one of {}".format(severity.encode('utf8'),
                                                   VALID_ALARM_DEFINITION_SEVERITIES))


def validate_severity_query(severity_str):
    severities = severity_str.split('|')
    for severity in severities:
        validate_alarm_definition_severity(severity)


def validate_sort_by(sort_by_list, allowed_sort_by):
    for sort_by_field in sort_by_list:
        sort_by_values = sort_by_field.split()
        if len(sort_by_values) > 2:
            raise HTTPUnprocessableEntityError("Unprocessable Entity",
                                               "Invalid sort_by {}".format(sort_by_field))
        if sort_by_values[0] not in allowed_sort_by:
            raise HTTPUnprocessableEntityError("Unprocessable Entity",
                                               "sort_by field {} must be one of [{}]".format(
                                                   sort_by_values[0],
                                                   ','.join(list(allowed_sort_by))))
        if len(sort_by_values) > 1 and sort_by_values[1] not in ['asc', 'desc']:
            raise HTTPUnprocessableEntityError("Unprocessable Entity",
                                               "sort_by value {} must be 'asc' or 'desc'".format(
                                                   sort_by_values[1]))



def validate_email_address(email):