Commit 70e71f71 authored by Luke Dashjr's avatar Luke Dashjr

interactivemode: Fix variable access in Python 3.3 with a "smarter" algorithm...

interactivemode: Fix variable access in Python 3.3 with a "smarter" algorithm to find the right context
parent 9294ed0e
......@@ -20,10 +20,23 @@ def exit():
def _RunCLI():
import code, sys, threading
namespace = {}
try:
raise None
except:
namespace = sys.exc_info()[2].tb_frame.f_back.f_back.f_globals
# The goal here is to find the context that imported us
try:
frame = sys.exc_info()[2].tb_frame
while frame.f_code.co_filename[0] != '<':
frame = frame.f_back
while frame.f_code.co_filename[0] == '<':
frame = frame.f_back
namespace.update(frame.f_globals)
namespace.update(frame.f_locals)
except:
print("InteractiveMode: Error setting up initial namespace")
finally:
frame = None
namespace.setdefault('exit', exit)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment