<commit_before>"""Copyright (c) 2010-2012 <NAME>

Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

errorreporting.py

Patch the `traceback' module to print "self" with each stack frame.
"""
import collections
import sys
import traceback
import platform
from datetime import datetime
import os
import json
import httplib
import zlib
import directories
import mcplatform
import release
import logging
log = logging.getLogger(__name__)

def extract_tb(tb, limit=None):
    """Return list of up to limit pre-processed entries from traceback.

    This is useful for alternate formatting of stack traces.  If
    'limit' is omitted or None, all entries are extracted.  A
    pre-processed stack trace entry is a quadruple (filename, line
    number, function name, text) representing the information that is
    usually printed for a stack trace.  The text is a string with
    leading and trailing whitespace stripped; if the source is not
    available it is None.
    """
    if limit is None:
        if hasattr(sys, 'tracebacklimit'):
            limit = sys.tracebacklimit
    list = []
    n = 0
    while tb is not None and (limit is None or n < limit):
        f = tb.tb_frame
        lineno = tb.tb_lineno
        co = f.f_code
        filename = co.co_filename
        name = co.co_name
        self = f.f_locals.get('self')
        try:
            selfstr = self and "(self is a {0})".format(self.__class__.__name__) or " "
        except:
            selfstr = " "
        traceback.linecache.checkcache(filename)
        line = traceback.linecache.getline(filename, lineno, f.f_globals)
        if line:
            line = line.strip()
        else:
            line = None
        list.append((filename, lineno, name, line, selfstr))
        tb = tb.tb_next
        n = n + 1
    return list


def format_list(extracted_list):
    """Format a list of traceback entry tuples for printing.

    Given a list of tuples as returned by extract_tb() or
    extract_stack(), return a list of strings ready for printing.
    Each string in the resulting list corresponds to the item with the
    same index in the argument list.  Each string ends in a newline;
    the strings may contain internal newlines as well, for those items
    whose source text line is not None.
    """
    list = []
    for filename, lineno, name, line, selfstr in reversed(extracted_list):
        item = '  File "%s", line %d, in %s %s\n' % (filename, lineno, name, selfstr[:60])
        if line:
            item = item + '    %s\n' % line.strip()
        list.append(item)
    return list

traceback.extract_tb = extract_tb
traceback.format_list = format_list

EXCEPTIONAL_API_KEY = "37eaf2a19432e268829ef4fa35921ad399bbda80"

def sanitize(s):
    parentDir = mcplatform.parentDir
    minecraftDir = mcplatform.minecraftDir
    home = os.path.expanduser("~")

    s = s.replace(parentDir, "[MCEdit folder]")
    s = s.replace(repr(parentDir)[1:-1], "[MCEdit folder]")
    s = s.replace(minecraftDir, "[Minecraft folder]")
    s = s.replace(repr(minecraftDir)[1:-1], "[Minecraft folder]")
    s = s.replace(home, "[User home folder]")
    s = s.replace(repr(home)[1:-1], "[User home folder]")
    return s

def get_backtrace():
    tb = sys.exc_traceback
    backtrace = []
    for filename, lineno, name, line, selfstr in extract_tb(tb):
        backtrace.append({
            "file":os.path.normpath(filename).replace(directories.dataDir, ""),<commit_msg>Debug: Reverse error traceback and put the last callee first, similar to Java and Obj-C tracebacks.<commit_after>"""Copyright (c) 2010-2012 <NAME>

Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

errorreporting.py

Patch the `traceback' module to print "self" with each stack frame.
"""
import collections
import sys
import traceback
import platform
from datetime import datetime
import os
import json
import httplib
import zlib
import directories
import mcplatform
import release
import logging
log = logging.getLogger(__name__)

def extract_tb(tb, limit=None):
    """Return list of up to limit pre-processed entries from traceback.

    This is useful for alternate formatting of stack traces.  If
    'limit' is omitted or None, all entries are extracted.  A
    pre-processed stack trace entry is a quadruple (filename, line
    number, function name, text) representing the information that is
    usually printed for a stack trace.  The text is a string with
    leading and trailing whitespace stripped; if the source is not
    available it is None.
    """
    if limit is None:
        if hasattr(sys, 'tracebacklimit'):
            limit = sys.tracebacklimit
    list = []
    n = 0
    while tb is not None and (limit is None or n < limit):
        f = tb.tb_frame
        lineno = tb.tb_lineno
        co = f.f_code
        filename = co.co_filename
        name = co.co_name
        self = f.f_locals.get('self')
        try:
            selfstr = self and "(self is a {0})".format(self.__class__.__name__) or " "
        except:
            selfstr = " "
        traceback.linecache.checkcache(filename)
        line = traceback.linecache.getline(filename, lineno, f.f_globals)
        if line:
            line = line.strip()
        else:
            line = None
        list.append((filename, lineno, name, line, selfstr))
        tb = tb.tb_next
        n = n + 1
    return list


def format_list(extracted_list):
    """Format a list of traceback entry tuples for printing.

    Given a list of tuples as returned by extract_tb() or
    extract_stack(), return a list of strings ready for printing.
    Each string in the resulting list corresponds to the item with the
    same index in the argument list.  Each string ends in a newline;
    the strings may contain internal newlines as well, for those items
    whose source text line is not None.
    """
    list = []
    for filename, lineno, name, line, selfstr in reversed(extracted_list):
        item = '  File "%s", line %d, in %s %s\n' % (filename, lineno, name, selfstr[:60])
        if line:
            item = item + '    %s\n' % line.strip()
        list.append(item)
    return list

traceback.extract_tb = extract_tb
traceback.format_list = format_list

EXCEPTIONAL_API_KEY = "37eaf2a19432e268829ef4fa35921ad399bbda80"

def sanitize(s):
    parentDir = mcplatform.parentDir
    minecraftDir = mcplatform.minecraftDir
    home = os.path.expanduser("~")

    s = s.replace(parentDir, "[MCEdit folder]")
    s = s.replace(repr(parentDir)[1:-1], "[MCEdit folder]")
    s = s.replace(minecraftDir, "[Minecraft folder]")
    s = s.replace(repr(minecraftDir)[1:-1], "[Minecraft folder]")
    s = s.replace(home, "[User home folder]")
    s = s.replace(repr(home)[1:-1], "[User home folder]")
    return s

def get_backtrace():
    tb = sys.exc_traceback
    backtrace = []
    for filename, lineno, name, line, selfstr in reversed(extract_tb(tb)):
        backtrace.append({
            "file":os.path.normpath(filename).replace(directories.dataDir, ""),
{'fraction_non_alphanumeric': 0.08409859835669406, 'fraction_numerical': 0.010633156114064766, 'mean_word_length': 3.117910447761194, 'pattern_counts': {'":': 2, '<': 7, '<?xml version=': 0, '>': 5, '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': '1256002', 'n_tokens_mistral': 2488, 'n_tokens_neox': 2361, 'n_words': 943}