<commit_before>"""
Mark log entries as important.
"""

from .colorizer import ColorizableMixin


class Mark(ColorizableMixin):
    """
    Wraps any object an mark it for colored output.
    """
    def __init__(self, obj, color_tag):
        """
        Mark `obj`.

        :param obj: The object to mark for colored output.
        :param color_tag: The color tag to use for coloring.
        """
        if isinstance(obj, Mark):
            if isinstance(color_tag, basestring):
                color_tag = [color_tag]

            if isinstance(obj.color_tag, basestring):
                color_tag.append(obj.color_tag)
            else:
                color_tag.extend(obj.color_tag)

            obj = obj.obj

        super(Mark, self).__init__(color_tag=color_tag)
        self.obj = obj

    def __str__(self):
        return str(self.obj)

    def __unicode__(self):
        return unicode(self.obj)<commit_msg>Added helper functions in mark.py<commit_after>"""
Mark log entries as important.
"""

from .colorizer import ColorizableMixin


class Mark(ColorizableMixin):
    """
    Wraps any object an mark it for colored output.
    """
    def __init__(self, obj, color_tag):
        """
        Mark `obj`.

        :param obj: The object to mark for colored output.
        :param color_tag: The color tag to use for coloring.
        """
        if isinstance(obj, Mark):
            if isinstance(color_tag, basestring):
                color_tag = [color_tag]

            if isinstance(obj.color_tag, basestring):
                color_tag.append(obj.color_tag)
            else:
                color_tag.extend(obj.color_tag)

            obj = obj.obj

        super(Mark, self).__init__(color_tag=color_tag)
        self.obj = obj

    def __str__(self):
        return str(self.obj)

    def __unicode__(self):
        return unicode(self.obj)


def success(obj):
    """
    A convenience helper method that marks an object with the `'success'` color
    tag.

    :param obj: The object the mark.
    :returns: A :class:`Mark<chromalog.mark.Mark>` instance.

    >>> success(42).color_tag
    'success'
    """
    return Mark(obj, color_tag='success')


def error(obj):
    """
    A convenience helper method that marks an object with the `'error'` color
    tag.

    :param obj: The object the mark.
    :returns: A :class:`Mark<chromalog.mark.Mark>` instance.

    >>> error(42).color_tag
    'error'
    """
    return Mark(obj, color_tag='error')


def success_if(obj, condition):
    """
    A convenience helper method that marks an object with the `'success'` color
    tag if `condition` is truthy, and with the `'error'` color tag otherwise.

    :param obj: The object the mark.
    :param condition: The condition to verify.
    :returns: A :class:`Mark<chromalog.mark.Mark>` instance.

    >>> success_if(42, True).color_tag
    'success'

    >>> success_if(42, False).color_tag
    'error'
    """
    return Mark(obj, color_tag='success' if condition else 'error')
{'fraction_non_alphanumeric': 0.10893390900033212, 'fraction_numerical': 0.002656924609764198, 'mean_word_length': 2.36536312849162, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 18, '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': '461179', 'n_tokens_mistral': 925, 'n_tokens_neox': 880, 'n_words': 265}