<commit_before>#!/usr/bin/env python

import regex as re
from collections import OrderedDict

from colorama import Fore, Back, Style


_line_filters = OrderedDict()

def _register_filter(obj):
    _line_filters[obj.regex] = obj

class Filter(object):
    regex = None

    def __init__(self):
        assert self.regex is not None, (
                "'{}' filter not implemented".format(self.__name__))
        _register_filter(self)

    def filter(self, match):
        assert False, "'{}' filter not implemented".format(self.__name__)

def init_filters():
    for f in Filter.__subclasses__():
        f()

def _prefix(match):
    return Fore.LIGHTBLACK_EX + match.group('prefix') + Fore.RESET

class ByAt(Filter):
    regex = re.compile(r"^"
                       r"(?P<prefix>==\d+== +)"
                       r"(?P<byat>(?:by|at) 0x[A-F0-9]+: )"
                       r"(?P<func>.+?)"
                       r"(?: \((?P<loc>[^\)]+)\))?"
                       r"$")

    def filter(self, match):
        output = _prefix(match)
        output += Fore.YELLOW + match.group('byat')

        func = self.func_signature(match.group('func'))
        output += Fore.RESET + func

        if match.group('loc'):
            loc = match.group('loc')
            loc_m = re.match(r"^(?P<file>[^:]+):(?P<line>\d+)$", loc)
            if loc_m:
                loc = Fore.LIGHTWHITE_EX + loc_m.group('file')
                loc += Fore.LIGHTBLACK_EX + ":"
                loc += Fore.MAGENTA + loc_m.group('line')
            loc_m = re.match(r"^(?P<in>in\s+)"
                             r"(?P<lib>.*\.(?:a|so|dylib|dll)"
                                r"(?:(?:\.[0-9])+)?)$",
                             loc)
            if loc_m:
                loc = Fore.RESET + loc_m.group('in')
                loc += Fore.RED + loc_m.group('lib')
            output += Fore.LIGHTBLACK_EX + " ("
            output += Fore.RESET + loc
            output += Fore.LIGHTBLACK_EX + ")"
<commit_msg>fix 'in /lib/' highlighting to work with 2-digit version numbers<commit_after>#!/usr/bin/env python

import regex as re
from collections import OrderedDict

from colorama import Fore, Back, Style


_line_filters = OrderedDict()

def _register_filter(obj):
    _line_filters[obj.regex] = obj

class Filter(object):
    regex = None

    def __init__(self):
        assert self.regex is not None, (
                "'{}' filter not implemented".format(self.__name__))
        _register_filter(self)

    def filter(self, match):
        assert False, "'{}' filter not implemented".format(self.__name__)

def init_filters():
    for f in Filter.__subclasses__():
        f()

def _prefix(match):
    return Fore.LIGHTBLACK_EX + match.group('prefix') + Fore.RESET

class ByAt(Filter):
    regex = re.compile(r"^"
                       r"(?P<prefix>==\d+== +)"
                       r"(?P<byat>(?:by|at) 0x[A-F0-9]+: )"
                       r"(?P<func>.+?)"
                       r"(?: \((?P<loc>[^\)]+)\))?"
                       r"$")

    def filter(self, match):
        output = _prefix(match)
        output += Fore.YELLOW + match.group('byat')

        func = self.func_signature(match.group('func'))
        output += Fore.RESET + func

        if match.group('loc'):
            loc = match.group('loc')
            loc_m = re.match(r"^(?P<file>[^:]+):(?P<line>\d+)$", loc)
            if loc_m:
                loc = Fore.LIGHTWHITE_EX + loc_m.group('file')
                loc += Fore.LIGHTBLACK_EX + ":"
                loc += Fore.MAGENTA + loc_m.group('line')
            loc_m = re.match(r"^(?P<in>in\s+)"
                             r"(?P<lib>.*\.(?:a|so|dylib|dll)"
                                r"(?:(?:\.[0-9]+)+)?)$",
                             loc)
            if loc_m:
                loc = Fore.RESET + loc_m.group('in')
                loc += Fore.RED + loc_m.group('lib')
            output += Fore.LIGHTBLACK_EX + " ("
            output += Fore.RESET + loc
            output += Fore.LIGHTBLACK_EX + ")"

{'fraction_non_alphanumeric': 0.16848906560636182, 'fraction_numerical': 0.0027335984095427437, 'mean_word_length': 1.754962354551677, 'pattern_counts': {'":': 2, '<': 19, '<?xml version=': 0, '>': 19, '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': '341518', 'n_tokens_mistral': 1338, 'n_tokens_neox': 1272, 'n_words': 247}