Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ShExBy/shex_roo.../usr/lib64/python3....
File: pdb.py
#! /usr/libexec/platform-python
[0] Fix | Delete
[1] Fix | Delete
"""
[2] Fix | Delete
The Python Debugger Pdb
[3] Fix | Delete
=======================
[4] Fix | Delete
[5] Fix | Delete
To use the debugger in its simplest form:
[6] Fix | Delete
[7] Fix | Delete
>>> import pdb
[8] Fix | Delete
>>> pdb.run('<a statement>')
[9] Fix | Delete
[10] Fix | Delete
The debugger's prompt is '(Pdb) '. This will stop in the first
[11] Fix | Delete
function call in <a statement>.
[12] Fix | Delete
[13] Fix | Delete
Alternatively, if a statement terminated with an unhandled exception,
[14] Fix | Delete
you can use pdb's post-mortem facility to inspect the contents of the
[15] Fix | Delete
traceback:
[16] Fix | Delete
[17] Fix | Delete
>>> <a statement>
[18] Fix | Delete
<exception traceback>
[19] Fix | Delete
>>> import pdb
[20] Fix | Delete
>>> pdb.pm()
[21] Fix | Delete
[22] Fix | Delete
The commands recognized by the debugger are listed in the next
[23] Fix | Delete
section. Most can be abbreviated as indicated; e.g., h(elp) means
[24] Fix | Delete
that 'help' can be typed as 'h' or 'help' (but not as 'he' or 'hel',
[25] Fix | Delete
nor as 'H' or 'Help' or 'HELP'). Optional arguments are enclosed in
[26] Fix | Delete
square brackets. Alternatives in the command syntax are separated
[27] Fix | Delete
by a vertical bar (|).
[28] Fix | Delete
[29] Fix | Delete
A blank line repeats the previous command literally, except for
[30] Fix | Delete
'list', where it lists the next 11 lines.
[31] Fix | Delete
[32] Fix | Delete
Commands that the debugger doesn't recognize are assumed to be Python
[33] Fix | Delete
statements and are executed in the context of the program being
[34] Fix | Delete
debugged. Python statements can also be prefixed with an exclamation
[35] Fix | Delete
point ('!'). This is a powerful way to inspect the program being
[36] Fix | Delete
debugged; it is even possible to change variables or call functions.
[37] Fix | Delete
When an exception occurs in such a statement, the exception name is
[38] Fix | Delete
printed but the debugger's state is not changed.
[39] Fix | Delete
[40] Fix | Delete
The debugger supports aliases, which can save typing. And aliases can
[41] Fix | Delete
have parameters (see the alias help entry) which allows one a certain
[42] Fix | Delete
level of adaptability to the context under examination.
[43] Fix | Delete
[44] Fix | Delete
Multiple commands may be entered on a single line, separated by the
[45] Fix | Delete
pair ';;'. No intelligence is applied to separating the commands; the
[46] Fix | Delete
input is split at the first ';;', even if it is in the middle of a
[47] Fix | Delete
quoted string.
[48] Fix | Delete
[49] Fix | Delete
If a file ".pdbrc" exists in your home directory or in the current
[50] Fix | Delete
directory, it is read in and executed as if it had been typed at the
[51] Fix | Delete
debugger prompt. This is particularly useful for aliases. If both
[52] Fix | Delete
files exist, the one in the home directory is read first and aliases
[53] Fix | Delete
defined there can be overridden by the local file. This behavior can be
[54] Fix | Delete
disabled by passing the "readrc=False" argument to the Pdb constructor.
[55] Fix | Delete
[56] Fix | Delete
Aside from aliases, the debugger is not directly programmable; but it
[57] Fix | Delete
is implemented as a class from which you can derive your own debugger
[58] Fix | Delete
class, which you can make as fancy as you like.
[59] Fix | Delete
[60] Fix | Delete
[61] Fix | Delete
Debugger commands
[62] Fix | Delete
=================
[63] Fix | Delete
[64] Fix | Delete
"""
[65] Fix | Delete
# NOTE: the actual command documentation is collected from docstrings of the
[66] Fix | Delete
# commands and is appended to __doc__ after the class has been defined.
[67] Fix | Delete
[68] Fix | Delete
import os
[69] Fix | Delete
import re
[70] Fix | Delete
import sys
[71] Fix | Delete
import cmd
[72] Fix | Delete
import bdb
[73] Fix | Delete
import dis
[74] Fix | Delete
import code
[75] Fix | Delete
import glob
[76] Fix | Delete
import pprint
[77] Fix | Delete
import signal
[78] Fix | Delete
import inspect
[79] Fix | Delete
import traceback
[80] Fix | Delete
import linecache
[81] Fix | Delete
[82] Fix | Delete
[83] Fix | Delete
class Restart(Exception):
[84] Fix | Delete
"""Causes a debugger to be restarted for the debugged python program."""
[85] Fix | Delete
pass
[86] Fix | Delete
[87] Fix | Delete
__all__ = ["run", "pm", "Pdb", "runeval", "runctx", "runcall", "set_trace",
[88] Fix | Delete
"post_mortem", "help"]
[89] Fix | Delete
[90] Fix | Delete
def find_function(funcname, filename):
[91] Fix | Delete
cre = re.compile(r'def\s+%s\s*[(]' % re.escape(funcname))
[92] Fix | Delete
try:
[93] Fix | Delete
fp = open(filename)
[94] Fix | Delete
except OSError:
[95] Fix | Delete
return None
[96] Fix | Delete
# consumer of this info expects the first line to be 1
[97] Fix | Delete
with fp:
[98] Fix | Delete
for lineno, line in enumerate(fp, start=1):
[99] Fix | Delete
if cre.match(line):
[100] Fix | Delete
return funcname, filename, lineno
[101] Fix | Delete
return None
[102] Fix | Delete
[103] Fix | Delete
def getsourcelines(obj):
[104] Fix | Delete
lines, lineno = inspect.findsource(obj)
[105] Fix | Delete
if inspect.isframe(obj) and obj.f_globals is obj.f_locals:
[106] Fix | Delete
# must be a module frame: do not try to cut a block out of it
[107] Fix | Delete
return lines, 1
[108] Fix | Delete
elif inspect.ismodule(obj):
[109] Fix | Delete
return lines, 1
[110] Fix | Delete
return inspect.getblock(lines[lineno:]), lineno+1
[111] Fix | Delete
[112] Fix | Delete
def lasti2lineno(code, lasti):
[113] Fix | Delete
linestarts = list(dis.findlinestarts(code))
[114] Fix | Delete
linestarts.reverse()
[115] Fix | Delete
for i, lineno in linestarts:
[116] Fix | Delete
if lasti >= i:
[117] Fix | Delete
return lineno
[118] Fix | Delete
return 0
[119] Fix | Delete
[120] Fix | Delete
[121] Fix | Delete
class _rstr(str):
[122] Fix | Delete
"""String that doesn't quote its repr."""
[123] Fix | Delete
def __repr__(self):
[124] Fix | Delete
return self
[125] Fix | Delete
[126] Fix | Delete
[127] Fix | Delete
# Interaction prompt line will separate file and call info from code
[128] Fix | Delete
# text using value of line_prefix string. A newline and arrow may
[129] Fix | Delete
# be to your liking. You can set it once pdb is imported using the
[130] Fix | Delete
# command "pdb.line_prefix = '\n% '".
[131] Fix | Delete
# line_prefix = ': ' # Use this to get the old situation back
[132] Fix | Delete
line_prefix = '\n-> ' # Probably a better default
[133] Fix | Delete
[134] Fix | Delete
class Pdb(bdb.Bdb, cmd.Cmd):
[135] Fix | Delete
[136] Fix | Delete
_previous_sigint_handler = None
[137] Fix | Delete
[138] Fix | Delete
def __init__(self, completekey='tab', stdin=None, stdout=None, skip=None,
[139] Fix | Delete
nosigint=False, readrc=True):
[140] Fix | Delete
bdb.Bdb.__init__(self, skip=skip)
[141] Fix | Delete
cmd.Cmd.__init__(self, completekey, stdin, stdout)
[142] Fix | Delete
if stdout:
[143] Fix | Delete
self.use_rawinput = 0
[144] Fix | Delete
self.prompt = '(Pdb) '
[145] Fix | Delete
self.aliases = {}
[146] Fix | Delete
self.displaying = {}
[147] Fix | Delete
self.mainpyfile = ''
[148] Fix | Delete
self._wait_for_mainpyfile = False
[149] Fix | Delete
self.tb_lineno = {}
[150] Fix | Delete
# Try to load readline if it exists
[151] Fix | Delete
try:
[152] Fix | Delete
import readline
[153] Fix | Delete
# remove some common file name delimiters
[154] Fix | Delete
readline.set_completer_delims(' \t\n`@#$%^&*()=+[{]}\\|;:\'",<>?')
[155] Fix | Delete
except ImportError:
[156] Fix | Delete
pass
[157] Fix | Delete
self.allow_kbdint = False
[158] Fix | Delete
self.nosigint = nosigint
[159] Fix | Delete
[160] Fix | Delete
# Read $HOME/.pdbrc and ./.pdbrc
[161] Fix | Delete
self.rcLines = []
[162] Fix | Delete
if readrc:
[163] Fix | Delete
if 'HOME' in os.environ:
[164] Fix | Delete
envHome = os.environ['HOME']
[165] Fix | Delete
try:
[166] Fix | Delete
with open(os.path.join(envHome, ".pdbrc")) as rcFile:
[167] Fix | Delete
self.rcLines.extend(rcFile)
[168] Fix | Delete
except OSError:
[169] Fix | Delete
pass
[170] Fix | Delete
try:
[171] Fix | Delete
with open(".pdbrc") as rcFile:
[172] Fix | Delete
self.rcLines.extend(rcFile)
[173] Fix | Delete
except OSError:
[174] Fix | Delete
pass
[175] Fix | Delete
[176] Fix | Delete
self.commands = {} # associates a command list to breakpoint numbers
[177] Fix | Delete
self.commands_doprompt = {} # for each bp num, tells if the prompt
[178] Fix | Delete
# must be disp. after execing the cmd list
[179] Fix | Delete
self.commands_silent = {} # for each bp num, tells if the stack trace
[180] Fix | Delete
# must be disp. after execing the cmd list
[181] Fix | Delete
self.commands_defining = False # True while in the process of defining
[182] Fix | Delete
# a command list
[183] Fix | Delete
self.commands_bnum = None # The breakpoint number for which we are
[184] Fix | Delete
# defining a list
[185] Fix | Delete
[186] Fix | Delete
def sigint_handler(self, signum, frame):
[187] Fix | Delete
if self.allow_kbdint:
[188] Fix | Delete
raise KeyboardInterrupt
[189] Fix | Delete
self.message("\nProgram interrupted. (Use 'cont' to resume).")
[190] Fix | Delete
self.set_step()
[191] Fix | Delete
self.set_trace(frame)
[192] Fix | Delete
[193] Fix | Delete
def reset(self):
[194] Fix | Delete
bdb.Bdb.reset(self)
[195] Fix | Delete
self.forget()
[196] Fix | Delete
[197] Fix | Delete
def forget(self):
[198] Fix | Delete
self.lineno = None
[199] Fix | Delete
self.stack = []
[200] Fix | Delete
self.curindex = 0
[201] Fix | Delete
self.curframe = None
[202] Fix | Delete
self.tb_lineno.clear()
[203] Fix | Delete
[204] Fix | Delete
def setup(self, f, tb):
[205] Fix | Delete
self.forget()
[206] Fix | Delete
self.stack, self.curindex = self.get_stack(f, tb)
[207] Fix | Delete
while tb:
[208] Fix | Delete
# when setting up post-mortem debugging with a traceback, save all
[209] Fix | Delete
# the original line numbers to be displayed along the current line
[210] Fix | Delete
# numbers (which can be different, e.g. due to finally clauses)
[211] Fix | Delete
lineno = lasti2lineno(tb.tb_frame.f_code, tb.tb_lasti)
[212] Fix | Delete
self.tb_lineno[tb.tb_frame] = lineno
[213] Fix | Delete
tb = tb.tb_next
[214] Fix | Delete
self.curframe = self.stack[self.curindex][0]
[215] Fix | Delete
# The f_locals dictionary is updated from the actual frame
[216] Fix | Delete
# locals whenever the .f_locals accessor is called, so we
[217] Fix | Delete
# cache it here to ensure that modifications are not overwritten.
[218] Fix | Delete
self.curframe_locals = self.curframe.f_locals
[219] Fix | Delete
return self.execRcLines()
[220] Fix | Delete
[221] Fix | Delete
# Can be executed earlier than 'setup' if desired
[222] Fix | Delete
def execRcLines(self):
[223] Fix | Delete
if not self.rcLines:
[224] Fix | Delete
return
[225] Fix | Delete
# local copy because of recursion
[226] Fix | Delete
rcLines = self.rcLines
[227] Fix | Delete
rcLines.reverse()
[228] Fix | Delete
# execute every line only once
[229] Fix | Delete
self.rcLines = []
[230] Fix | Delete
while rcLines:
[231] Fix | Delete
line = rcLines.pop().strip()
[232] Fix | Delete
if line and line[0] != '#':
[233] Fix | Delete
if self.onecmd(line):
[234] Fix | Delete
# if onecmd returns True, the command wants to exit
[235] Fix | Delete
# from the interaction, save leftover rc lines
[236] Fix | Delete
# to execute before next interaction
[237] Fix | Delete
self.rcLines += reversed(rcLines)
[238] Fix | Delete
return True
[239] Fix | Delete
[240] Fix | Delete
# Override Bdb methods
[241] Fix | Delete
[242] Fix | Delete
def user_call(self, frame, argument_list):
[243] Fix | Delete
"""This method is called when there is the remote possibility
[244] Fix | Delete
that we ever need to stop in this function."""
[245] Fix | Delete
if self._wait_for_mainpyfile:
[246] Fix | Delete
return
[247] Fix | Delete
if self.stop_here(frame):
[248] Fix | Delete
self.message('--Call--')
[249] Fix | Delete
self.interaction(frame, None)
[250] Fix | Delete
[251] Fix | Delete
def user_line(self, frame):
[252] Fix | Delete
"""This function is called when we stop or break at this line."""
[253] Fix | Delete
if self._wait_for_mainpyfile:
[254] Fix | Delete
if (self.mainpyfile != self.canonic(frame.f_code.co_filename)
[255] Fix | Delete
or frame.f_lineno <= 0):
[256] Fix | Delete
return
[257] Fix | Delete
self._wait_for_mainpyfile = False
[258] Fix | Delete
if self.bp_commands(frame):
[259] Fix | Delete
self.interaction(frame, None)
[260] Fix | Delete
[261] Fix | Delete
def bp_commands(self, frame):
[262] Fix | Delete
"""Call every command that was set for the current active breakpoint
[263] Fix | Delete
(if there is one).
[264] Fix | Delete
[265] Fix | Delete
Returns True if the normal interaction function must be called,
[266] Fix | Delete
False otherwise."""
[267] Fix | Delete
# self.currentbp is set in bdb in Bdb.break_here if a breakpoint was hit
[268] Fix | Delete
if getattr(self, "currentbp", False) and \
[269] Fix | Delete
self.currentbp in self.commands:
[270] Fix | Delete
currentbp = self.currentbp
[271] Fix | Delete
self.currentbp = 0
[272] Fix | Delete
lastcmd_back = self.lastcmd
[273] Fix | Delete
self.setup(frame, None)
[274] Fix | Delete
for line in self.commands[currentbp]:
[275] Fix | Delete
self.onecmd(line)
[276] Fix | Delete
self.lastcmd = lastcmd_back
[277] Fix | Delete
if not self.commands_silent[currentbp]:
[278] Fix | Delete
self.print_stack_entry(self.stack[self.curindex])
[279] Fix | Delete
if self.commands_doprompt[currentbp]:
[280] Fix | Delete
self._cmdloop()
[281] Fix | Delete
self.forget()
[282] Fix | Delete
return
[283] Fix | Delete
return 1
[284] Fix | Delete
[285] Fix | Delete
def user_return(self, frame, return_value):
[286] Fix | Delete
"""This function is called when a return trap is set here."""
[287] Fix | Delete
if self._wait_for_mainpyfile:
[288] Fix | Delete
return
[289] Fix | Delete
frame.f_locals['__return__'] = return_value
[290] Fix | Delete
self.message('--Return--')
[291] Fix | Delete
self.interaction(frame, None)
[292] Fix | Delete
[293] Fix | Delete
def user_exception(self, frame, exc_info):
[294] Fix | Delete
"""This function is called if an exception occurs,
[295] Fix | Delete
but only if we are to stop at or just below this level."""
[296] Fix | Delete
if self._wait_for_mainpyfile:
[297] Fix | Delete
return
[298] Fix | Delete
exc_type, exc_value, exc_traceback = exc_info
[299] Fix | Delete
frame.f_locals['__exception__'] = exc_type, exc_value
[300] Fix | Delete
[301] Fix | Delete
# An 'Internal StopIteration' exception is an exception debug event
[302] Fix | Delete
# issued by the interpreter when handling a subgenerator run with
[303] Fix | Delete
# 'yield from' or a generator controlled by a for loop. No exception has
[304] Fix | Delete
# actually occurred in this case. The debugger uses this debug event to
[305] Fix | Delete
# stop when the debuggee is returning from such generators.
[306] Fix | Delete
prefix = 'Internal ' if (not exc_traceback
[307] Fix | Delete
and exc_type is StopIteration) else ''
[308] Fix | Delete
self.message('%s%s' % (prefix,
[309] Fix | Delete
traceback.format_exception_only(exc_type, exc_value)[-1].strip()))
[310] Fix | Delete
self.interaction(frame, exc_traceback)
[311] Fix | Delete
[312] Fix | Delete
# General interaction function
[313] Fix | Delete
def _cmdloop(self):
[314] Fix | Delete
while True:
[315] Fix | Delete
try:
[316] Fix | Delete
# keyboard interrupts allow for an easy way to cancel
[317] Fix | Delete
# the current command, so allow them during interactive input
[318] Fix | Delete
self.allow_kbdint = True
[319] Fix | Delete
self.cmdloop()
[320] Fix | Delete
self.allow_kbdint = False
[321] Fix | Delete
break
[322] Fix | Delete
except KeyboardInterrupt:
[323] Fix | Delete
self.message('--KeyboardInterrupt--')
[324] Fix | Delete
[325] Fix | Delete
# Called before loop, handles display expressions
[326] Fix | Delete
def preloop(self):
[327] Fix | Delete
displaying = self.displaying.get(self.curframe)
[328] Fix | Delete
if displaying:
[329] Fix | Delete
for expr, oldvalue in displaying.items():
[330] Fix | Delete
newvalue = self._getval_except(expr)
[331] Fix | Delete
# check for identity first; this prevents custom __eq__ to
[332] Fix | Delete
# be called at every loop, and also prevents instances whose
[333] Fix | Delete
# fields are changed to be displayed
[334] Fix | Delete
if newvalue is not oldvalue and newvalue != oldvalue:
[335] Fix | Delete
displaying[expr] = newvalue
[336] Fix | Delete
self.message('display %s: %r [old: %r]' %
[337] Fix | Delete
(expr, newvalue, oldvalue))
[338] Fix | Delete
[339] Fix | Delete
def interaction(self, frame, traceback):
[340] Fix | Delete
# Restore the previous signal handler at the Pdb prompt.
[341] Fix | Delete
if Pdb._previous_sigint_handler:
[342] Fix | Delete
signal.signal(signal.SIGINT, Pdb._previous_sigint_handler)
[343] Fix | Delete
Pdb._previous_sigint_handler = None
[344] Fix | Delete
if self.setup(frame, traceback):
[345] Fix | Delete
# no interaction desired at this time (happens if .pdbrc contains
[346] Fix | Delete
# a command like "continue")
[347] Fix | Delete
self.forget()
[348] Fix | Delete
return
[349] Fix | Delete
self.print_stack_entry(self.stack[self.curindex])
[350] Fix | Delete
self._cmdloop()
[351] Fix | Delete
self.forget()
[352] Fix | Delete
[353] Fix | Delete
def displayhook(self, obj):
[354] Fix | Delete
"""Custom displayhook for the exec in default(), which prevents
[355] Fix | Delete
assignment of the _ variable in the builtins.
[356] Fix | Delete
"""
[357] Fix | Delete
# reproduce the behavior of the standard displayhook, not printing None
[358] Fix | Delete
if obj is not None:
[359] Fix | Delete
self.message(repr(obj))
[360] Fix | Delete
[361] Fix | Delete
def default(self, line):
[362] Fix | Delete
if line[:1] == '!': line = line[1:]
[363] Fix | Delete
locals = self.curframe_locals
[364] Fix | Delete
globals = self.curframe.f_globals
[365] Fix | Delete
try:
[366] Fix | Delete
code = compile(line + '\n', '<stdin>', 'single')
[367] Fix | Delete
save_stdout = sys.stdout
[368] Fix | Delete
save_stdin = sys.stdin
[369] Fix | Delete
save_displayhook = sys.displayhook
[370] Fix | Delete
try:
[371] Fix | Delete
sys.stdin = self.stdin
[372] Fix | Delete
sys.stdout = self.stdout
[373] Fix | Delete
sys.displayhook = self.displayhook
[374] Fix | Delete
exec(code, globals, locals)
[375] Fix | Delete
finally:
[376] Fix | Delete
sys.stdout = save_stdout
[377] Fix | Delete
sys.stdin = save_stdin
[378] Fix | Delete
sys.displayhook = save_displayhook
[379] Fix | Delete
except:
[380] Fix | Delete
exc_info = sys.exc_info()[:2]
[381] Fix | Delete
self.error(traceback.format_exception_only(*exc_info)[-1].strip())
[382] Fix | Delete
[383] Fix | Delete
def precmd(self, line):
[384] Fix | Delete
"""Handle alias expansion and ';;' separator."""
[385] Fix | Delete
if not line.strip():
[386] Fix | Delete
return line
[387] Fix | Delete
args = line.split()
[388] Fix | Delete
while args[0] in self.aliases:
[389] Fix | Delete
line = self.aliases[args[0]]
[390] Fix | Delete
ii = 1
[391] Fix | Delete
for tmpArg in args[1:]:
[392] Fix | Delete
line = line.replace("%" + str(ii),
[393] Fix | Delete
tmpArg)
[394] Fix | Delete
ii += 1
[395] Fix | Delete
line = line.replace("%*", ' '.join(args[1:]))
[396] Fix | Delete
args = line.split()
[397] Fix | Delete
# split into ';;' separated commands
[398] Fix | Delete
# unless it's an alias command
[399] Fix | Delete
if args[0] != 'alias':
[400] Fix | Delete
marker = line.find(';;')
[401] Fix | Delete
if marker >= 0:
[402] Fix | Delete
# queue up everything after marker
[403] Fix | Delete
next = line[marker+2:].lstrip()
[404] Fix | Delete
self.cmdqueue.append(next)
[405] Fix | Delete
line = line[:marker].rstrip()
[406] Fix | Delete
return line
[407] Fix | Delete
[408] Fix | Delete
def onecmd(self, line):
[409] Fix | Delete
"""Interpret the argument as though it had been typed in response
[410] Fix | Delete
to the prompt.
[411] Fix | Delete
[412] Fix | Delete
Checks whether this line is typed at the normal prompt or in
[413] Fix | Delete
a breakpoint command list definition.
[414] Fix | Delete
"""
[415] Fix | Delete
if not self.commands_defining:
[416] Fix | Delete
return cmd.Cmd.onecmd(self, line)
[417] Fix | Delete
else:
[418] Fix | Delete
return self.handle_command_def(line)
[419] Fix | Delete
[420] Fix | Delete
def handle_command_def(self, line):
[421] Fix | Delete
"""Handles one command line during command list definition."""
[422] Fix | Delete
cmd, arg, line = self.parseline(line)
[423] Fix | Delete
if not cmd:
[424] Fix | Delete
return
[425] Fix | Delete
if cmd == 'silent':
[426] Fix | Delete
self.commands_silent[self.commands_bnum] = True
[427] Fix | Delete
return # continue to handle other cmd def in the cmd list
[428] Fix | Delete
elif cmd == 'end':
[429] Fix | Delete
self.cmdqueue = []
[430] Fix | Delete
return 1 # end of cmd list
[431] Fix | Delete
cmdlist = self.commands[self.commands_bnum]
[432] Fix | Delete
if arg:
[433] Fix | Delete
cmdlist.append(cmd+' '+arg)
[434] Fix | Delete
else:
[435] Fix | Delete
cmdlist.append(cmd)
[436] Fix | Delete
# Determine if we must stop
[437] Fix | Delete
try:
[438] Fix | Delete
func = getattr(self, 'do_' + cmd)
[439] Fix | Delete
except AttributeError:
[440] Fix | Delete
func = self.default
[441] Fix | Delete
# one of the resuming commands
[442] Fix | Delete
if func.__name__ in self.commands_resuming:
[443] Fix | Delete
self.commands_doprompt[self.commands_bnum] = False
[444] Fix | Delete
self.cmdqueue = []
[445] Fix | Delete
return 1
[446] Fix | Delete
return
[447] Fix | Delete
[448] Fix | Delete
# interface abstraction functions
[449] Fix | Delete
[450] Fix | Delete
def message(self, msg):
[451] Fix | Delete
print(msg, file=self.stdout)
[452] Fix | Delete
[453] Fix | Delete
def error(self, msg):
[454] Fix | Delete
print('***', msg, file=self.stdout)
[455] Fix | Delete
[456] Fix | Delete
# Generic completion functions. Individual complete_foo methods can be
[457] Fix | Delete
# assigned below to one of these functions.
[458] Fix | Delete
[459] Fix | Delete
def _complete_location(self, text, line, begidx, endidx):
[460] Fix | Delete
# Complete a file/module/function location for break/tbreak/clear.
[461] Fix | Delete
if line.strip().endswith((':', ',')):
[462] Fix | Delete
# Here comes a line number or a condition which we can't complete.
[463] Fix | Delete
return []
[464] Fix | Delete
# First, try to find matching functions (i.e. expressions).
[465] Fix | Delete
try:
[466] Fix | Delete
ret = self._complete_expression(text, line, begidx, endidx)
[467] Fix | Delete
except Exception:
[468] Fix | Delete
ret = []
[469] Fix | Delete
# Then, try to complete file names as well.
[470] Fix | Delete
globs = glob.glob(text + '*')
[471] Fix | Delete
for fn in globs:
[472] Fix | Delete
if os.path.isdir(fn):
[473] Fix | Delete
ret.append(fn + '/')
[474] Fix | Delete
elif os.path.isfile(fn) and fn.lower().endswith(('.py', '.pyw')):
[475] Fix | Delete
ret.append(fn + ':')
[476] Fix | Delete
return ret
[477] Fix | Delete
[478] Fix | Delete
def _complete_bpnumber(self, text, line, begidx, endidx):
[479] Fix | Delete
# Complete a breakpoint number. (This would be more helpful if we could
[480] Fix | Delete
# display additional info along with the completions, such as file/line
[481] Fix | Delete
# of the breakpoint.)
[482] Fix | Delete
return [str(i) for i, bp in enumerate(bdb.Breakpoint.bpbynumber)
[483] Fix | Delete
if bp is not None and str(i).startswith(text)]
[484] Fix | Delete
[485] Fix | Delete
def _complete_expression(self, text, line, begidx, endidx):
[486] Fix | Delete
# Complete an arbitrary expression.
[487] Fix | Delete
if not self.curframe:
[488] Fix | Delete
return []
[489] Fix | Delete
# Collect globals and locals. It is usually not really sensible to also
[490] Fix | Delete
# complete builtins, and they clutter the namespace quite heavily, so we
[491] Fix | Delete
# leave them out.
[492] Fix | Delete
ns = self.curframe.f_globals.copy()
[493] Fix | Delete
ns.update(self.curframe_locals)
[494] Fix | Delete
if '.' in text:
[495] Fix | Delete
# Walk an attribute chain up to the last part, similar to what
[496] Fix | Delete
# rlcompleter does. This will bail if any of the parts are not
[497] Fix | Delete
# simple attribute access, which is what we want.
[498] Fix | Delete
dotted = text.split('.')
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function