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