Update RapydScript

This commit is contained in:
Kovid Goyal 2016-04-14 11:42:18 +05:30
parent 220064441c
commit 36ea076b8b
3 changed files with 52 additions and 0 deletions

Binary file not shown.

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,51 @@
# vim:fileencoding=utf-8
# License: BSD Copyright: 2016, Kovid Goyal <kovid at kovidgoyal.net>
# globals: ρσ_str, ρσ_last_exception
def _get_internal_traceback(err):
if isinstance(err, Exception) and err.stack:
lines = ρσ_str.splitlines(err.stack)
for i, line in enumerate(lines):
line = ρσ_str.strip(line)
# These two conditions work on desktop Chrome and Firefox to identify the correct
# line in the traceback.
if line.startsWith('at new ' + err.name) or line.startsWith(err.name + '@'):
return err.__repr__() + '\n' + lines.slice(i+1).join('\n')
return err and err.stack
def format_exception(exc, limit):
if not isinstance(exc, Error):
if exc and exc.toString:
return [exc.toString()]
return []
tb = _get_internal_traceback(exc)
if tb:
lines = ρσ_str.splitlines(tb)
e = lines[0]
lines = [l for l in lines[1:]]
if limit:
lines = lines[:limit+1] if limit > 0 else lines[limit:]
lines.reverse()
lines.push(e)
lines.insert(0, 'Traceback (most recent call last):')
return [l+'\n' for l in lines]
return [exc.toString()]
def format_exc(limit):
return format_exception(ρσ_last_exception, limit).join('')
def print_exc(limit):
print(format_exc(limit))
def format_stack(limit):
stack = Error().stack
if not stack:
return []
lines = str.splitlines(stack)[2:]
lines.reverse()
if limit:
lines = lines[:limit+1] if limit > 0 else lines[limit:]
return [l + '\n' for l in lines]
def print_stack(limit):
print(format_stack(limit).join(''))