def init():
stdout.write("\033[95m----------------------------------------------------------------\n")
if os.getenv('PYSESSION_SAVE_OFF'):
PySession.off()
stdout.write(BANNER_OFF)
elif os.getenv('PYSESSION_SAVE_LOCALLY'):
PySession.local()
stdout.write(BANNER_LOCAL)
else:
stdout.write(BANNER_GIST)
if os.getenv('PYSESSION_SAVE_OFF'):
stdout.write(BANNER_ENABLE)
else:
stdout.write(BANNER_DISABLE)
stdout.write(BANNER_SWITCH)
stdout.write("----------------------------------------------------------------\033[0m\n")
PySession.load_history_urls()
try:
from IPython import get_ipython
PySession.ipython_history = get_ipython().pt_cli.application.buffer.history
PySession.is_ipython = True
except (ImportError, AttributeError):
pass
if PySession.is_ipython:
PySession.start_index = len(PySession.ipython_history)
def custom_hook(shell, etype, evalue, traceback, tb_offset=None):
PySession.wrong_code_lines.append(
len(PySession.ipython_history) - 1)
shell.showtraceback((etype, evalue, traceback),
tb_offset=tb_offset)
get_ipython().set_custom_exc((Exception,), custom_hook)
else:
readline.add_history('') # A hack for a strange bug in 3 < Py <3.5.2
PySession.start_index = readline.get_current_history_length() + 1
default_hook = sys.excepthook
def custom_hook(etype, evalue, traceback):
PySession.wrong_code_lines.append(
readline.get_current_history_length())
default_hook(etype, evalue, traceback)
sys.excepthook = custom_hook
评论列表
文章目录