<commit_before>from __pyjamas__ import JS

# a dictionary of module override names (platform-specific)
overrides = None # to be updated by app, on compile

# the remote path for loading modules
loadpath = None

stacktrace = None

appname = None

def setloadpath(lp):
    global loadpath
    loadpath = lp

def setappname(an):
    global appname
    appname = an

def getloadpath():
    return loadpath

def addoverride(module_name, path):
    overrides[module_name] = path

def exc_info():
    le = JS('$pyjs.__last_exception__')
    if not le:
        return (None, None, None)
    if not hasattr(le.error, '__class__'):
        cls = None
    else:
        cls = le.error.__class__
    tb = JS('$pyjs.__last_exception_stack__')
    if tb:
        start = tb.start
        while tb and start > 0:
            tb = tb.tb_next
            start -= 1
    return (cls, le.error, tb)

def exc_clear():
    JS('$pyjs.__last_exception_stack__ = $pyjs.__last_exception__ = null;')

# save_exception_stack is totally javascript, to prevent trackstack pollution
JS("""@{{!sys}}.save_exception_stack = function (start) {
    if (typeof start == 'undefined') {
      start = 0;
    }
    var save_stack = null;
    var top = null;
    if ($pyjs.__active_exception_stack__) {
        $pyjs.__active_exception_stack__.start = start;
        return $pyjs.__active_exception_stack__;
    }
    for (var needle=0; needle < $pyjs.trackstack.length; needle++) {
        var t = new Object();
        for (var p in $pyjs.trackstack[needle]) {
            t[p] = $pyjs.trackstack[needle][p];
        }
        if (typeof $pyjs.loaded_modules[t.module].__track_lines__ != 'undefined') {
          var f_globals = $p['dict']();
          for (var name in $pyjs.loaded_modules[t.module]) {
            f_globals.__setitem__(name, $pyjs.loaded_modules[t.module][name]);
          }
          t.tb_frame = {f_globals: f_globals};
        }
        if (save_stack == null) {
          save_stack = top = t;
        } else {
          top.tb_next = t;
        }
        top = t;
    }
    top.tb_next = null;
    save_stack.start = start;
    $pyjs.__active_exception_stack__ = save_stack;
    return $pyjs.__active_exception_stack__;
};""")

def trackstacklist(stack=None, limit=None):
    if stack is None:
        stack = JS('$pyjs.__active_exception_stack__')
    if not stack:
        return ''
    stackstrings = []
    msg = ''
    if limit is None:
        limit = -1
    while stack and limit:
        JS("@{{msg}} = $pyjs.loaded_modules[@{{stack}}.module]['__track_lines__'][@{{stack}}['lineno']];")
        if msg:
            stackstrings.append(msg + '\n')
        else:
            stackstrings.append('%s.py, line %d\n' % (stack.module, stack.lineno))
        stack = stack.tb_next
        limit -= 1
    return stackstrings

def trackstackstr(stack=None, limit=None):
    stackstrings = trackstacklist(stack, limit=limit)
    return ''.join(stackstrings)

def _get_traceback_list(err, tb=None, limit=None):
    msg = [str(err) + '\n', 'Traceback:\n']
    try:
        msg.extend(trackstacklist(tb, limit=limit))
    except:<commit_msg>Fix for issue #550 : broken debug flag<commit_after>from __pyjamas__ import JS

# a dictionary of module override names (platform-specific)
overrides = None # to be updated by app, on compile

# the remote path for loading modules
loadpath = None

stacktrace = None

appname = None

def setloadpath(lp):
    global loadpath
    loadpath = lp

def setappname(an):
    global appname
    appname = an

def getloadpath():
    return loadpath

def addoverride(module_name, path):
    overrides[module_name] = path

def exc_info():
    le = JS('$pyjs.__last_exception__')
    if not le:
        return (None, None, None)
    if not hasattr(le.error, '__class__'):
        cls = None
    else:
        cls = le.error.__class__
    tb = JS('$pyjs.__last_exception_stack__')
    if tb:
        start = tb.start
        while tb and start > 0:
            tb = tb.tb_next
            start -= 1
    return (cls, le.error, tb)

def exc_clear():
    JS('$pyjs.__last_exception_stack__ = $pyjs.__last_exception__ = null;')

# save_exception_stack is totally javascript, to prevent trackstack pollution
JS("""@{{!sys}}._exception_from_trackstack = function (trackstack, start) {
    if (typeof start == 'undefined') {
      start = 0;
    }
    var exception_stack = null;
    var top = null;
    for (var needle=0; needle < $pyjs.trackstack.length; needle++) {
        var t = new Object();
        for (var p in $pyjs.trackstack[needle]) {
            t[p] = $pyjs.trackstack[needle][p];
        }
        if (typeof $pyjs.loaded_modules[t.module].__track_lines__ != 'undefined') {
          var f_globals = $p['dict']();
          for (var name in $pyjs.loaded_modules[t.module]) {
            f_globals.__setitem__(name, $pyjs.loaded_modules[t.module][name]);
          }
          t.tb_frame = {f_globals: f_globals};
        }
        if (exception_stack == null) {
            exception_stack = top = t;
        } else {
          top.tb_next = t;
        }
        top = t;
    }
    top.tb_next = null;
    exception_stack.start = start;
    return exception_stack;
};""")

JS("""@{{!sys}}.save_exception_stack = function (start) {
    if ($pyjs.__active_exception_stack__) {
        $pyjs.__active_exception_stack__.start = start;
        return $pyjs.__active_exception_stack__;
    }
    $pyjs.__active_exception_stack__ = @{{!sys}}._exception_from_trackstack($pyjs.trackstack, start);
    return $pyjs.__active_exception_stack__;
};""")

def trackstacklist(stack=None, limit=None):
    if stack is None:
        stack = JS('$pyjs.__active_exception_stack__')
    else:
        import pyjslib
        if pyjslib.isArray(stack):
            stack = _exception_from_trackstack(stack)
    if stack is None:
        return ''
    stackstrings = []
    msg = ''
    if limit is None:
        limit = -1
    while stack and limit:
        JS("@{{msg}} = $pyjs.loaded_modules[@{{stack}}.module]['__track_lines__'][@{{stack}}['lineno']];")
        JS("if (typeof @{{msg}} == 'undefined') @{{msg}} = null;")
        if msg:
            stackstrings.append(msg + '\n')
        else:
            stackstrings.append('%s.py, line %d\n' % (stack.module, stack.lineno))
        stack = stack.tb_next
        limit -= 1
    return stackstrings

def trackstackstr(stack=None, limit=None):
    stackstrings = trackstacklist(stack, limit=limit)
    return ''.join(stackstrings)

def _get_traceback_list(err, tb=None, limit=None):
    msg = [str(err) + '\n', 'Traceback:\n']
    try:
        msg.extend(trackstacklist(tb, limit=limit))
    except:
{'fraction_non_alphanumeric': 0.12945421741091565, 'fraction_numerical': 0.0022552999548940008, 'mean_word_length': 2.638949671772429, 'pattern_counts': {'":': 0, '<': 5, '<?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': '5183223', 'n_tokens_mistral': 2168, 'n_tokens_neox': 2156, 'n_words': 510}