<commit_before># exceptions.py - serialization exceptions
#
# Copyright 2011 <NAME> <<EMAIL>>.
# Copyright 2012, 2013, 2014, 2015, 2016 <NAME>
#           <<EMAIL>> and contributors.
#
# This file is part of Flask-Restless.
#
# Flask-Restless is distributed under both the GNU Affero General Public
# License version 3 and under the 3-clause BSD license. For more
# information, see LICENSE.AGPL and LICENSE.BSD.
"""Exceptions that arise from serialization or deserialization."""


class SerializationException(Exception):
    """Raised when there is a problem serializing an instance of a
    SQLAlchemy model to a dictionary representation.

    `instance` is the (problematic) instance on which
    :meth:`Serializer.__call__` was invoked.

    `message` is an optional string describing the problem in more
    detail.

    `resource` is an optional partially-constructed serialized
    representation of ``instance``.

    Each of these keyword arguments is stored in a corresponding
    instance attribute so client code can access them.

    """

    def __init__(self, instance, message=None, resource=None, *args, **kw):
        super(SerializationException, self).__init__(*args, **kw)
        self.resource = resource
        self.message = message
        self.instance = instance


class MultipleExceptions(Exception):
    """Raised when there are multiple problems in serialization or
    deserialization.

    `exceptions` is a non-empty sequence of other exceptions that have
    been raised in the code.

    You may wish to raise this exception when implementing the
    :meth:`.Serializer.serialize_many` method, for example, if there are
    multiple exceptions

    """

    def __init__(self, exceptions, *args, **kw):
        super(MultipleExceptions, self).__init__(*args, **kw)

        #: Sequence of other exceptions that have been raised in the code.
        self.exceptions = exceptions


class DeserializationException(Exception):
    """Raised when there is a problem deserializing a Python dictionary to an
    instance of a SQLAlchemy model.

    `status` is an integer representing the HTTP status code that
    corresponds to this error. If not specified, it is set to 400,
    representing :http:status:`400`.

    `detail` is a string describing the problem in more detail. If
    provided, this will be incorporated in the return value of
    :meth:`.message`.

    Each of the keyword arguments `status` and `detail` are assigned
    directly to instance-level attributes :attr:`status` and
    :attr:`detail`.

    """

    def __init__(self, status=400, detail=None, *args, **kw):
        super(DeserializationException, self).__init__(*args, **kw)

        #: A string describing the problem in more detail.
        self.detail = detail

        #: The HTTP status code corresponding to this error.
        self.status = status

    def message(self):
        """Returns a more detailed description of the problem as a
        string.

        """
        base = 'Failed to deserialize object'
        if self.detail is not None:
            return '{0}: {1}'.format(base, self.detail)<commit_msg>Corrects HTTP status code role in docstring.<commit_after># exceptions.py - serialization exceptions
#
# Copyright 2011 <NAME> <<EMAIL>>.
# Copyright 2012, 2013, 2014, 2015, 2016 <NAME>
#           <<EMAIL>> and contributors.
#
# This file is part of Flask-Restless.
#
# Flask-Restless is distributed under both the GNU Affero General Public
# License version 3 and under the 3-clause BSD license. For more
# information, see LICENSE.AGPL and LICENSE.BSD.
"""Exceptions that arise from serialization or deserialization."""


class SerializationException(Exception):
    """Raised when there is a problem serializing an instance of a
    SQLAlchemy model to a dictionary representation.

    `instance` is the (problematic) instance on which
    :meth:`Serializer.__call__` was invoked.

    `message` is an optional string describing the problem in more
    detail.

    `resource` is an optional partially-constructed serialized
    representation of ``instance``.

    Each of these keyword arguments is stored in a corresponding
    instance attribute so client code can access them.

    """

    def __init__(self, instance, message=None, resource=None, *args, **kw):
        super(SerializationException, self).__init__(*args, **kw)
        self.resource = resource
        self.message = message
        self.instance = instance


class MultipleExceptions(Exception):
    """Raised when there are multiple problems in serialization or
    deserialization.

    `exceptions` is a non-empty sequence of other exceptions that have
    been raised in the code.

    You may wish to raise this exception when implementing the
    :meth:`.Serializer.serialize_many` method, for example, if there are
    multiple exceptions

    """

    def __init__(self, exceptions, *args, **kw):
        super(MultipleExceptions, self).__init__(*args, **kw)

        #: Sequence of other exceptions that have been raised in the code.
        self.exceptions = exceptions


class DeserializationException(Exception):
    """Raised when there is a problem deserializing a Python dictionary to an
    instance of a SQLAlchemy model.

    `status` is an integer representing the HTTP status code that
    corresponds to this error. If not specified, it is set to 400,
    representing :http:statuscode:`400`.

    `detail` is a string describing the problem in more detail. If
    provided, this will be incorporated in the return value of
    :meth:`.message`.

    Each of the keyword arguments `status` and `detail` are assigned
    directly to instance-level attributes :attr:`status` and
    :attr:`detail`.

    """

    def __init__(self, status=400, detail=None, *args, **kw):
        super(DeserializationException, self).__init__(*args, **kw)

        #: A string describing the problem in more detail.
        self.detail = detail

        #: The HTTP status code corresponding to this error.
        self.status = status

    def message(self):
        """Returns a more detailed description of the problem as a
        string.

        """
        base = 'Failed to deserialize object'
        if self.detail is not None:
            return '{0}: {1}'.format(base, self.detail)
{'fraction_non_alphanumeric': 0.08284492317440202, 'fraction_numerical': 0.011721843814351339, 'mean_word_length': 3.2319034852546915, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, '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': '7475596', 'n_tokens_mistral': 1709, 'n_tokens_neox': 1574, 'n_words': 695}