Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def pudb_shell(_globals, _locals):
"""
This example shell runs a classic Python shell. It is based on
run_classic_shell in pudb.shell.
"""
# Many shells only let you pass in a single locals dictionary, rather than
# separate globals and locals dictionaries. In this case, you can use
# pudb.shell.SetPropagatingDict to automatically merge the two into a
# single dictionary. It does this in such a way that assignments propogate
# to _locals, so that when the debugger is at the module level, variables
# can be reassigned in the shell.
from pudb.shell import SetPropagatingDict
ns = SetPropagatingDict([_locals, _globals], _locals)
try:
import readline
import rlcompleter
HAVE_READLINE = True
except ImportError:
HAVE_READLINE = False
if HAVE_READLINE:
readline.set_completer(
rlcompleter.Completer(ns).complete)
readline.parse_and_bind("tab: complete")
readline.clear_history()
from code import InteractiveConsole
cons = InteractiveConsole(ns)
def cmdline_get_namespace():
curframe = self.debugger.curframe
from pudb.shell import SetPropagatingDict
return SetPropagatingDict(
[curframe.f_locals, curframe.f_globals],
curframe.f_locals)
def run_classic_shell(locals, globals, first_time):
if first_time:
banner = "Hit Ctrl-D to return to PuDB."
else:
banner = ""
ns = SetPropagatingDict([locals, globals], locals)
if HAVE_READLINE:
readline.set_completer(
rlcompleter.Completer(ns).complete)
from code import InteractiveConsole
cons = InteractiveConsole(ns)
cons.interact(banner)
def pudb_shell(_globals, _locals):
try:
tty_name = os.path.basename(os.ttyname(sys.stdout.fileno()))
except OSError:
tty_name = 'unknown'
# This makes it so that assignments in the shell act like globals
# assignments
ns = SetPropagatingDict([_locals, _globals], _locals)
return run_shell(ns, ns, quiet=True,
history_file='~/.mypython/history/pudb_%s_history' % tty_name,
in_out=emoji_pudb)
def run_bpython_shell(locals, globals, first_time):
ns = SetPropagatingDict([locals, globals], locals)
import bpython.cli
bpython.cli.main(locals_=ns)