<commit_before><commit_msg>trace frame<commit_after>from __future__ import unicode_literals
from __future__ import print_function

import os
from . import syntax

class Frame(object):
    def __init__(self,
                 code,
                 location,
                 lineno,
                 path=None,
                 obj=None,
                 cols=None,
                 one_line=False,
                 code_start=1,
                 libid=None,
                 format="xml",
                 raw_location=None):
        self.code = code
        self._location = location
        self.lineno = lineno
        self.obj = obj
        self.cols = cols
        self.one_line = one_line
        self.code_start = code_start
        self.format = format
        self.libid = libid
        self._raw_location = raw_location

    def __repr__(self):
        return "<frame '{}'>".format(self.location)

    @property
    def location(self):
        location = self._location
        homedir = os.environ.get('HOME', None)
        if homedir and location.startswith(homedir + '/'):
            location = '~/' + location[len(homedir) + 1:]
        if self.obj:
            return 'File "{}", line {}, in {}'.format(location, self.lineno, self.obj)
        else:
            if self.cols:
                return 'File "{}", line {}, col {}'.format(location, self.lineno, self.cols[0])
            else:
                return 'File "{}"'.format(location)

    @property
    def raw_location(self):
        return self._raw_location or self._location

    @property
    def snippet(self):
        try:
            if not self.code:
                return ''
            if self.one_line:
                return self.code
            lineno = max(0, self.lineno - 5)

            return syntax.highlight(self.format,
                                    self.code,
                                    lineno,
                                    lineno + 10,
                                    highlight_lines=[self.lineno],
                                    highlight_range=[self.lineno, self.cols[0], self.cols[1]] if self.cols else None)
        except Exception as e:
            raise
            from traceback import print_exc
            print_exc(e)
{'fraction_non_alphanumeric': 0.09424778761061947, 'fraction_numerical': 0.003982300884955752, 'mean_word_length': 1.347871235721703, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 1}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 5, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4581549', 'n_tokens_mistral': 612, 'n_tokens_neox': 583, 'n_words': 139}