<commit_before># encoding: utf-8

"""
.. codeauthor:: <NAME> <<EMAIL>>
"""

from __future__ import absolute_import, unicode_literals

import enum


@enum.unique
class ErrorReason(enum.Enum):
    NULL_NAME = "NULL_NAME"
    INVALID_CHARACTER = "INVALID_CHARACTER"
    INVALID_LENGTH = "INVALID_LENGTH"
    RESERVED_NAME = "RESERVED_NAME"


class ValidationError(ValueError):
    """
    Base exception class that indicates invalid name errors.
    """

    @property
    def platform(self):
        return self.__platform

    @property
    def reason(self):
        return self.__reason

    @property
    def description(self):
        return self.__description

    @property
    def reusable_name(self):
        return self.__reusable_name

    def __init__(self, *args, **kwargs):
        self.__platform = kwargs.pop("platform", None)
        self.__reason = kwargs.pop("reason", None)
        self.__description = kwargs.pop("description", None)
        self.__reusable_name = kwargs.pop("reusable_name", None)

        super(ValidationError, self).__init__(*args, **kwargs)


class NullNameError(ValidationError):
    """
    Exception raised when a name is empty.
    """

    def __init__(self, *args, **kwargs):
        kwargs["reason"] = ErrorReason.NULL_NAME

        super(NullNameError, self).__init__(args, **kwargs)


class InvalidCharError(ValidationError):
    """
    Exception raised when includes invalid character(s) within a string.
    """

    def __init__(self, *args, **kwargs):
        kwargs["reason"] = ErrorReason.INVALID_CHARACTER

        super(InvalidCharError, self).__init__(args, **kwargs)


class InvalidLengthError(ValidationError):
    """
    Exception raised when a string too long/short.
    """

    def __init__(self, *args, **kwargs):
        kwargs["reason"] = ErrorReason.INVALID_LENGTH

        super(InvalidLengthError, self).__init__(args, **kwargs)


class ReservedNameError(ValidationError):
    """
    Exception raised when a string matched a reserved name.
    """

    def __init__(self, *args, **kwargs):
        kwargs["reason"] = ErrorReason.RESERVED_NAME

        super(ReservedNameError, self).__init__(args, **kwargs)


class ValidReservedNameError(ReservedNameError):
    """
    Exception raised when a string matched a reserved name.
    However, it can be used as a name.
    """

    def __init__(self, *args, **kwargs):
        kwargs["reusable_name"] = True

        super(ValidReservedNameError, self).__init__(args, **kwargs)


class InvalidReservedNameError(ReservedNameError):
    """
    Exception raised when a string matched a reserved name.
    Moreover, the reserved name is invalid as a name.
    """

    def __init__(self, *args, **kwargs):
        kwargs["reusable_name"] = False

        super(InvalidReservedNameError, self).__init__(args, **kwargs)
<commit_msg>Add __str__/__repr__ to exception classes<commit_after># encoding: utf-8

"""
.. codeauthor:: <NAME> <<EMAIL>>
"""

from __future__ import absolute_import, unicode_literals

import enum


@enum.unique
class ErrorReason(enum.Enum):
    NULL_NAME = "NULL_NAME"
    INVALID_CHARACTER = "INVALID_CHARACTER"
    INVALID_LENGTH = "INVALID_LENGTH"
    RESERVED_NAME = "RESERVED_NAME"


class ValidationError(ValueError):
    """
    Base exception class that indicates invalid name errors.
    """

    @property
    def platform(self):
        return self.__platform

    @property
    def reason(self):
        return self.__reason

    @property
    def description(self):
        return self.__description

    @property
    def reusable_name(self):
        return self.__reusable_name

    def __init__(self, *args, **kwargs):
        self.__platform = kwargs.pop("platform", None)
        self.__reason = kwargs.pop("reason", None)
        self.__description = kwargs.pop("description", None)
        self.__reusable_name = kwargs.pop("reusable_name", None)

        super(ValidationError, self).__init__(*args[0], **kwargs)

    def __str__(self, *args, **kwargs):
        item_list = [Exception.__str__(self, *args, **kwargs)]

        if self.reason:
            item_list.append("reason={}".format(self.reason))
        if self.description:
            item_list.append("description={}".format(self.description))
        if self.reusable_name:
            item_list.append("reusable_name={}".format(self.reusable_name))

        return ", ".join(item_list).strip()

    def __repr__(self, *args, **kwargs):
        return self.__str__(*args, **kwargs)


class NullNameError(ValidationError):
    """
    Exception raised when a name is empty.
    """

    def __init__(self, *args, **kwargs):
        kwargs["reason"] = ErrorReason.NULL_NAME

        super(NullNameError, self).__init__(args, **kwargs)


class InvalidCharError(ValidationError):
    """
    Exception raised when includes invalid character(s) within a string.
    """

    def __init__(self, *args, **kwargs):
        kwargs["reason"] = ErrorReason.INVALID_CHARACTER

        super(InvalidCharError, self).__init__(args, **kwargs)


class InvalidLengthError(ValidationError):
    """
    Exception raised when a string too long/short.
    """

    def __init__(self, *args, **kwargs):
        kwargs["reason"] = ErrorReason.INVALID_LENGTH

        super(InvalidLengthError, self).__init__(args, **kwargs)


class ReservedNameError(ValidationError):
    """
    Exception raised when a string matched a reserved name.
    """

    def __init__(self, *args, **kwargs):
        kwargs["reason"] = ErrorReason.RESERVED_NAME

        super(ReservedNameError, self).__init__(args, **kwargs)


class ValidReservedNameError(ReservedNameError):
    """
    Exception raised when a string matched a reserved name.
    However, it can be used as a name.
    """

    def __init__(self, *args, **kwargs):
        kwargs["reusable_name"] = True

        super(ValidReservedNameError, self).__init__(args, **kwargs)


class InvalidReservedNameError(ReservedNameError):
    """
    Exception raised when a string matched a reserved name.
    Moreover, the reserved name is invalid as a name.
    """

    def __init__(self, *args, **kwargs):
        kwargs["reusable_name"] = False

        super(InvalidReservedNameError, self).__init__(args, **kwargs)

{'fraction_non_alphanumeric': 0.11764705882352941, 'fraction_numerical': 0.00047953964194373403, 'mean_word_length': 3.339112343966713, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1267043', 'n_tokens_mistral': 1829, 'n_tokens_neox': 1757, 'n_words': 442}