<commit_before>"""
Color Scheme Tweaker (for sublime text).

Licensed under MIT
Copyright (c) 2013 - 2015 <NAME> <<EMAIL>>
"""
from __future__ import absolute_import
from .rgba import RGBA
from . import x11colors
import re

FILTER_MATCH = re.compile(
    r'''(?x)
    ^(?:
        (brightness|saturation|hue|colorize|glow)\((-?[\d]+|[\d]*\.[\d]+)\)|
        (sepia|grayscale|invert)
    )
    (?:@(fg|bg))?$
    '''
)


class ColorSchemeTweaker(object):
    """Tweak the color scheme with the provided filter(s)."""

    def _apply_filter(self, color, f_name, value=None):
        """Apply the filter."""

        if isinstance(color, RGBA):
            if value is None:
                color.__getattribute__(f_name)()
            else:
                color.__getattribute__(f_name)(value)

    def _filter_colors(self, *args, **kwargs):
        """Filter the colors."""

        global_settings = kwargs.get("global_settings", False)
        dual_colors = False
        if len(args) == 1:
            fg = args[0]
            bg = None
        elif len(args) == 2:
            fg = args[0]
            bg = args[1]
            if not global_settings:
                dual_colors = True
        else:
            return None, None

        try:
            assert(fg is not None)
            rgba_fg = RGBA(fg)
        except Exception:
            rgba_fg = fg
        try:
            assert(bg is not None)
            rgba_bg = RGBA(bg)
        except Exception:
            rgba_bg = bg

        for f in self.filters:
            name = f[0]
            value = f[1]
            context = f[2]
            if name in ("grayscale", "sepia", "invert"):
                if context != "bg":
                    self._apply_filter(rgba_fg, name)
                if context != "fg":
                    self._apply_filter(rgba_bg, name)
            elif name in ["saturation", "brightness", "hue", "colorize"]:
                if context != "bg":
                    self._apply_filter(rgba_fg, name, value)
                if context != "fg":
                    self._apply_filter(rgba_bg, name, value)
            elif name == "glow" and dual_colors and isinstance(rgba_fg, RGBA) and (bg is None or bg.strip() == ""):
                rgba = RGBA(rgba_fg.get_rgba())
                rgba.apply_alpha(self.bground if self.bground != "" else "#FFFFFF")
                bg = rgba.get_rgb() + ("%02X" % int((255.0 * value)))
                try:
                    rgba_bg = RGBA(bg)
                except Exception:
                    rgba_bg = bg
        return (
            rgba_fg.get_rgba() if isinstance(rgba_fg, RGBA) else rgba_fg,
            rgba_bg.get_rgba() if isinstance(rgba_bg, RGBA) else rgba_bg
        )

    def tweak(self, tmtheme, filters):
        """Tweak the theme with the provided filters."""

        self.filters = []
        for f in filters.split(";"):
            m = FILTER_MATCH.match(f)
            if m:
                if m.group(1):
                    self.filters.append([m.group(1), float(m.group(2)), m.group(4) if m.group(4) else "all"])
                else:
                    self.filters.append([m.group(3), 0.0, m.group(4) if m.group(4) else "all"])

        if len(self.filters):
            general_settings_read = False
            for settings in tmtheme["settings"]:
                if not general_settings_read:
                    for k, v in settings["settings"].items():
                        if k in ("background", "gutter", "lineHighlight", "selection"):
                            _, v = self._filter_colors(None, self.process_color(v), global_settings=True)
                        else:
                            v, _ = self._filter_colors(self.process_color(v), global_settings=True)
                        settings["settings"][k] = v
                    general_settings_read = True<commit_msg>Skip popupCss and phantomCss<commit_after>"""
Color Scheme Tweaker (for sublime text).

Licensed under MIT
Copyright (c) 2013 - 2015 <NAME> <<EMAIL>>
"""
from __future__ import absolute_import
from .rgba import RGBA
from . import x11colors
import re

FILTER_MATCH = re.compile(
    r'''(?x)
    ^(?:
        (brightness|saturation|hue|colorize|glow)\((-?[\d]+|[\d]*\.[\d]+)\)|
        (sepia|grayscale|invert)
    )
    (?:@(fg|bg))?$
    '''
)


class ColorSchemeTweaker(object):
    """Tweak the color scheme with the provided filter(s)."""

    def _apply_filter(self, color, f_name, value=None):
        """Apply the filter."""

        if isinstance(color, RGBA):
            if value is None:
                color.__getattribute__(f_name)()
            else:
                color.__getattribute__(f_name)(value)

    def _filter_colors(self, *args, **kwargs):
        """Filter the colors."""

        global_settings = kwargs.get("global_settings", False)
        dual_colors = False
        if len(args) == 1:
            fg = args[0]
            bg = None
        elif len(args) == 2:
            fg = args[0]
            bg = args[1]
            if not global_settings:
                dual_colors = True
        else:
            return None, None

        try:
            assert(fg is not None)
            rgba_fg = RGBA(fg)
        except Exception:
            rgba_fg = fg
        try:
            assert(bg is not None)
            rgba_bg = RGBA(bg)
        except Exception:
            rgba_bg = bg

        for f in self.filters:
            name = f[0]
            value = f[1]
            context = f[2]
            if name in ("grayscale", "sepia", "invert"):
                if context != "bg":
                    self._apply_filter(rgba_fg, name)
                if context != "fg":
                    self._apply_filter(rgba_bg, name)
            elif name in ["saturation", "brightness", "hue", "colorize"]:
                if context != "bg":
                    self._apply_filter(rgba_fg, name, value)
                if context != "fg":
                    self._apply_filter(rgba_bg, name, value)
            elif name == "glow" and dual_colors and isinstance(rgba_fg, RGBA) and (bg is None or bg.strip() == ""):
                rgba = RGBA(rgba_fg.get_rgba())
                rgba.apply_alpha(self.bground if self.bground != "" else "#FFFFFF")
                bg = rgba.get_rgb() + ("%02X" % int((255.0 * value)))
                try:
                    rgba_bg = RGBA(bg)
                except Exception:
                    rgba_bg = bg
        return (
            rgba_fg.get_rgba() if isinstance(rgba_fg, RGBA) else rgba_fg,
            rgba_bg.get_rgba() if isinstance(rgba_bg, RGBA) else rgba_bg
        )

    def tweak(self, tmtheme, filters):
        """Tweak the theme with the provided filters."""

        self.filters = []
        for f in filters.split(";"):
            m = FILTER_MATCH.match(f)
            if m:
                if m.group(1):
                    self.filters.append([m.group(1), float(m.group(2)), m.group(4) if m.group(4) else "all"])
                else:
                    self.filters.append([m.group(3), 0.0, m.group(4) if m.group(4) else "all"])

        if len(self.filters):
            general_settings_read = False
            for settings in tmtheme["settings"]:
                if not general_settings_read:
                    for k, v in settings["settings"].items():
                        if not k.endswith('Css'):
                            if k in ("background", "gutter", "lineHighlight", "selection"):
                                _, v = self._filter_colors(None, self.process_color(v), global_settings=True)
                            else:
                                v, _ = self._filter_colors(self.process_color(v), global_settings=True)
                        settings["settings"][k] = v
                    general_settings_read = True
{'fraction_non_alphanumeric': 0.12303363601483566, 'fraction_numerical': 0.008696764292108965, 'mean_word_length': 1.587690271343481, 'pattern_counts': {'":': 8, '<': 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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '745569', 'n_tokens_mistral': 2451, 'n_tokens_neox': 2267, 'n_words': 571}