<commit_before>"""
RGBA.

Licensed under MIT
Copyright (c) 2012 - 2015 <NAME> <<EMAIL>>
"""
import re
from colorsys import rgb_to_hls, hls_to_rgb, rgb_to_hsv, hsv_to_rgb
import decimal

RGB_CHANNEL_SCALE = 1.0 / 255.0
HUE_SCALE = 1.0 / 360.0


def clamp(value, mn, mx):
    """Clamp the value to the the given minimum and maximum."""

    return max(min(value, mx), mn)


def round_int(dec):
    """Round float to nearest int using expected rounding."""

    return int(decimal.Decimal(dec).quantize(decimal.Decimal('0'), decimal.ROUND_HALF_UP))


class RGBA(object):
    """RGBA object for converting between color formats or applying filters to the color."""

    r = None
    g = None
    b = None
    a = None
    color_pattern = re.compile(r"^#(?:([A-Fa-f\d]{6})([A-Fa-f\d]{2})?|([A-Fa-f\d]{3}))")

    def __init__(self, s=None):
        """Initialize."""

        if s is None:
            s = "#000000FF"
        self.r, self.g, self.b, self.a = self._split_channels(s)

    def _split_channels(self, s):
        """Split the color into color channels: red, green, blue, alpha."""

        def alpha_channel(alpha):
            """Get alpha channel."""
            return int(alpha, 16) if alpha else 0xFF

        m = self.color_pattern.match(s)
        assert(m is not None)
        if m.group(1):
            return int(s[1:3], 16), int(s[3:5], 16), int(s[5:7], 16), alpha_channel(m.group(2))
        else:
            return int(s[1] * 2, 16), int(s[2] * 2, 16), int(s[3] * 2, 16), 0xFF

    def get_rgba(self):
        """Get the RGB color with the alpha channel."""

        return "#%02X%02X%02X%02X" % (self.r, self.g, self.b, self.a)

    def get_rgb(self):
        """Get the RGB valuie."""

        return "#%02X%02X%02X" % (self.r, self.g, self.b)

    def apply_alpha(self, background="#000000FF"):
        """
        Apply the given transparency with the given background.

        This gives a color that represents what the eye sees with
        the transparent color against the given background.
        """

        def tx_alpha(cf, af, cb, ab):
            """Translate the color channel with the alpha channel and background channel color."""

            return round_int(
                abs(
                    cf * (af * RGB_CHANNEL_SCALE) + cb * (ab * RGB_CHANNEL_SCALE) * (1 - (af * RGB_CHANNEL_SCALE))
                )
            ) & 0xFF

        if self.a < 0xFF:
            r, g, b, a = self._split_channels(background)

            self.r = tx_alpha(self.r, self.a, r, a)
            self.g = tx_alpha(self.g, self.a, g, a)
            self.b = tx_alpha(self.b, self.a, b, a)

        return self.get_rgb()

    def get_luminance(self):
        """Get percieved luminance."""

        return clamp(round_int(0.299 * self.r + 0.587 * self.g + 0.114 * self.b), 0, 255)

    def get_true_luminance(self):
        """"Get true liminance."""

        l = self.tohls()[1]
        return clamp(round_int(l * 255.0), 0, 255)

    def alpha(self, factor):
        """Adjust alpha."""

        self.a = round_int(clamp(self.a + (255.0 * factor) - 255.0, 0.0, 255.0))

    def red(self, factor):
        """Adjust red."""

        self.r = round_int(clamp(self.r + (255.0 * factor) - 255.0, 0.0, 255.0))

    def green(self, factor):
        """Adjust green."""

        self.g = round_int(clamp(self.g + (255.0 * factor) - 255.0, 0.0, 255.0))

    def blue(self, factor):
        """Adjust blue."""

        self.b = round_int(clamp(self.b + (255.0 * factor) - 255.0, 0.0, 255.0))

    def luminance(self, factor):
        """True luminance."""

        h, l, s = self.tohls()<commit_msg>Lint fixes<commit_after>"""
RGBA.

Licensed under MIT
Copyright (c) 2012 - 2016 <NAME> <<EMAIL>>
"""
import re
from colorsys import rgb_to_hls, hls_to_rgb, rgb_to_hsv, hsv_to_rgb
import decimal

RGB_CHANNEL_SCALE = 1.0 / 255.0
HUE_SCALE = 1.0 / 360.0


def clamp(value, mn, mx):
    """Clamp the value to the the given minimum and maximum."""

    return max(min(value, mx), mn)


def round_int(dec):
    """Round float to nearest int using expected rounding."""

    return int(decimal.Decimal(dec).quantize(decimal.Decimal('0'), decimal.ROUND_HALF_UP))


class RGBA(object):
    """RGBA object for converting between color formats or applying filters to the color."""

    r = None
    g = None
    b = None
    a = None
    color_pattern = re.compile(r"^#(?:([A-Fa-f\d]{6})([A-Fa-f\d]{2})?|([A-Fa-f\d]{3}))")

    def __init__(self, s=None):
        """Initialize."""

        if s is None:
            s = "#000000FF"
        self.r, self.g, self.b, self.a = self._split_channels(s)

    def _split_channels(self, s):
        """Split the color into color channels: red, green, blue, alpha."""

        def alpha_channel(alpha):
            """Get alpha channel."""
            return int(alpha, 16) if alpha else 0xFF

        m = self.color_pattern.match(s)
        assert(m is not None)
        if m.group(1):
            return int(s[1:3], 16), int(s[3:5], 16), int(s[5:7], 16), alpha_channel(m.group(2))
        else:
            return int(s[1] * 2, 16), int(s[2] * 2, 16), int(s[3] * 2, 16), 0xFF

    def get_rgba(self):
        """Get the RGB color with the alpha channel."""

        return "#%02X%02X%02X%02X" % (self.r, self.g, self.b, self.a)

    def get_rgb(self):
        """Get the RGB valuie."""

        return "#%02X%02X%02X" % (self.r, self.g, self.b)

    def apply_alpha(self, background="#000000FF"):
        """
        Apply the given transparency with the given background.

        This gives a color that represents what the eye sees with
        the transparent color against the given background.
        """

        def tx_alpha(cf, af, cb, ab):
            """Translate the color channel with the alpha channel and background channel color."""

            return round_int(
                abs(
                    cf * (af * RGB_CHANNEL_SCALE) + cb * (ab * RGB_CHANNEL_SCALE) * (1 - (af * RGB_CHANNEL_SCALE))
                )
            ) & 0xFF

        if self.a < 0xFF:
            r, g, b, a = self._split_channels(background)

            self.r = tx_alpha(self.r, self.a, r, a)
            self.g = tx_alpha(self.g, self.a, g, a)
            self.b = tx_alpha(self.b, self.a, b, a)

        return self.get_rgb()

    def get_luminance(self):
        """Get percieved luminance."""

        return clamp(round_int(0.299 * self.r + 0.587 * self.g + 0.114 * self.b), 0, 255)

    def get_true_luminance(self):
        """Get true liminance."""

        l = self.tohls()[1]
        return clamp(round_int(l * 255.0), 0, 255)

    def alpha(self, factor):
        """Adjust alpha."""

        self.a = round_int(clamp(self.a + (255.0 * factor) - 255.0, 0.0, 255.0))

    def red(self, factor):
        """Adjust red."""

        self.r = round_int(clamp(self.r + (255.0 * factor) - 255.0, 0.0, 255.0))

    def green(self, factor):
        """Adjust green."""

        self.g = round_int(clamp(self.g + (255.0 * factor) - 255.0, 0.0, 255.0))

    def blue(self, factor):
        """Adjust blue."""

        self.b = round_int(clamp(self.b + (255.0 * factor) - 255.0, 0.0, 255.0))

    def luminance(self, factor):
        """Get true luminance."""

        h, l, s = self.tohls()
{'fraction_non_alphanumeric': 0.1569141595362959, 'fraction_numerical': 0.04526635385040022, 'mean_word_length': 2.2166000887705284, 'pattern_counts': {'":': 0, '<': 11, '<?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': '3565829', 'n_tokens_mistral': 2812, 'n_tokens_neox': 2474, 'n_words': 693}