Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/AnonR/anonr.TX.../opt/imh-pyth.../lib/python3....
File: bdb.py
"""Debugger basics"""
[0] Fix | Delete
[1] Fix | Delete
import fnmatch
[2] Fix | Delete
import sys
[3] Fix | Delete
import os
[4] Fix | Delete
from inspect import CO_GENERATOR, CO_COROUTINE, CO_ASYNC_GENERATOR
[5] Fix | Delete
[6] Fix | Delete
__all__ = ["BdbQuit", "Bdb", "Breakpoint"]
[7] Fix | Delete
[8] Fix | Delete
GENERATOR_AND_COROUTINE_FLAGS = CO_GENERATOR | CO_COROUTINE | CO_ASYNC_GENERATOR
[9] Fix | Delete
[10] Fix | Delete
[11] Fix | Delete
class BdbQuit(Exception):
[12] Fix | Delete
"""Exception to give up completely."""
[13] Fix | Delete
[14] Fix | Delete
[15] Fix | Delete
class Bdb:
[16] Fix | Delete
"""Generic Python debugger base class.
[17] Fix | Delete
[18] Fix | Delete
This class takes care of details of the trace facility;
[19] Fix | Delete
a derived class should implement user interaction.
[20] Fix | Delete
The standard debugger class (pdb.Pdb) is an example.
[21] Fix | Delete
[22] Fix | Delete
The optional skip argument must be an iterable of glob-style
[23] Fix | Delete
module name patterns. The debugger will not step into frames
[24] Fix | Delete
that originate in a module that matches one of these patterns.
[25] Fix | Delete
Whether a frame is considered to originate in a certain module
[26] Fix | Delete
is determined by the __name__ in the frame globals.
[27] Fix | Delete
"""
[28] Fix | Delete
[29] Fix | Delete
def __init__(self, skip=None):
[30] Fix | Delete
self.skip = set(skip) if skip else None
[31] Fix | Delete
self.breaks = {}
[32] Fix | Delete
self.fncache = {}
[33] Fix | Delete
self.frame_returning = None
[34] Fix | Delete
[35] Fix | Delete
def canonic(self, filename):
[36] Fix | Delete
"""Return canonical form of filename.
[37] Fix | Delete
[38] Fix | Delete
For real filenames, the canonical form is a case-normalized (on
[39] Fix | Delete
case insensitive filesystems) absolute path. 'Filenames' with
[40] Fix | Delete
angle brackets, such as "<stdin>", generated in interactive
[41] Fix | Delete
mode, are returned unchanged.
[42] Fix | Delete
"""
[43] Fix | Delete
if filename == "<" + filename[1:-1] + ">":
[44] Fix | Delete
return filename
[45] Fix | Delete
canonic = self.fncache.get(filename)
[46] Fix | Delete
if not canonic:
[47] Fix | Delete
canonic = os.path.abspath(filename)
[48] Fix | Delete
canonic = os.path.normcase(canonic)
[49] Fix | Delete
self.fncache[filename] = canonic
[50] Fix | Delete
return canonic
[51] Fix | Delete
[52] Fix | Delete
def reset(self):
[53] Fix | Delete
"""Set values of attributes as ready to start debugging."""
[54] Fix | Delete
import linecache
[55] Fix | Delete
linecache.checkcache()
[56] Fix | Delete
self.botframe = None
[57] Fix | Delete
self._set_stopinfo(None, None)
[58] Fix | Delete
[59] Fix | Delete
def trace_dispatch(self, frame, event, arg):
[60] Fix | Delete
"""Dispatch a trace function for debugged frames based on the event.
[61] Fix | Delete
[62] Fix | Delete
This function is installed as the trace function for debugged
[63] Fix | Delete
frames. Its return value is the new trace function, which is
[64] Fix | Delete
usually itself. The default implementation decides how to
[65] Fix | Delete
dispatch a frame, depending on the type of event (passed in as a
[66] Fix | Delete
string) that is about to be executed.
[67] Fix | Delete
[68] Fix | Delete
The event can be one of the following:
[69] Fix | Delete
line: A new line of code is going to be executed.
[70] Fix | Delete
call: A function is about to be called or another code block
[71] Fix | Delete
is entered.
[72] Fix | Delete
return: A function or other code block is about to return.
[73] Fix | Delete
exception: An exception has occurred.
[74] Fix | Delete
c_call: A C function is about to be called.
[75] Fix | Delete
c_return: A C function has returned.
[76] Fix | Delete
c_exception: A C function has raised an exception.
[77] Fix | Delete
[78] Fix | Delete
For the Python events, specialized functions (see the dispatch_*()
[79] Fix | Delete
methods) are called. For the C events, no action is taken.
[80] Fix | Delete
[81] Fix | Delete
The arg parameter depends on the previous event.
[82] Fix | Delete
"""
[83] Fix | Delete
if self.quitting:
[84] Fix | Delete
return # None
[85] Fix | Delete
if event == 'line':
[86] Fix | Delete
return self.dispatch_line(frame)
[87] Fix | Delete
if event == 'call':
[88] Fix | Delete
return self.dispatch_call(frame, arg)
[89] Fix | Delete
if event == 'return':
[90] Fix | Delete
return self.dispatch_return(frame, arg)
[91] Fix | Delete
if event == 'exception':
[92] Fix | Delete
return self.dispatch_exception(frame, arg)
[93] Fix | Delete
if event == 'c_call':
[94] Fix | Delete
return self.trace_dispatch
[95] Fix | Delete
if event == 'c_exception':
[96] Fix | Delete
return self.trace_dispatch
[97] Fix | Delete
if event == 'c_return':
[98] Fix | Delete
return self.trace_dispatch
[99] Fix | Delete
print('bdb.Bdb.dispatch: unknown debugging event:', repr(event))
[100] Fix | Delete
return self.trace_dispatch
[101] Fix | Delete
[102] Fix | Delete
def dispatch_line(self, frame):
[103] Fix | Delete
"""Invoke user function and return trace function for line event.
[104] Fix | Delete
[105] Fix | Delete
If the debugger stops on the current line, invoke
[106] Fix | Delete
self.user_line(). Raise BdbQuit if self.quitting is set.
[107] Fix | Delete
Return self.trace_dispatch to continue tracing in this scope.
[108] Fix | Delete
"""
[109] Fix | Delete
if self.stop_here(frame) or self.break_here(frame):
[110] Fix | Delete
self.user_line(frame)
[111] Fix | Delete
if self.quitting: raise BdbQuit
[112] Fix | Delete
return self.trace_dispatch
[113] Fix | Delete
[114] Fix | Delete
def dispatch_call(self, frame, arg):
[115] Fix | Delete
"""Invoke user function and return trace function for call event.
[116] Fix | Delete
[117] Fix | Delete
If the debugger stops on this function call, invoke
[118] Fix | Delete
self.user_call(). Raise BdbQuit if self.quitting is set.
[119] Fix | Delete
Return self.trace_dispatch to continue tracing in this scope.
[120] Fix | Delete
"""
[121] Fix | Delete
# XXX 'arg' is no longer used
[122] Fix | Delete
if self.botframe is None:
[123] Fix | Delete
# First call of dispatch since reset()
[124] Fix | Delete
self.botframe = frame.f_back # (CT) Note that this may also be None!
[125] Fix | Delete
return self.trace_dispatch
[126] Fix | Delete
if not (self.stop_here(frame) or self.break_anywhere(frame)):
[127] Fix | Delete
# No need to trace this function
[128] Fix | Delete
return # None
[129] Fix | Delete
# Ignore call events in generator except when stepping.
[130] Fix | Delete
if self.stopframe and frame.f_code.co_flags & GENERATOR_AND_COROUTINE_FLAGS:
[131] Fix | Delete
return self.trace_dispatch
[132] Fix | Delete
self.user_call(frame, arg)
[133] Fix | Delete
if self.quitting: raise BdbQuit
[134] Fix | Delete
return self.trace_dispatch
[135] Fix | Delete
[136] Fix | Delete
def dispatch_return(self, frame, arg):
[137] Fix | Delete
"""Invoke user function and return trace function for return event.
[138] Fix | Delete
[139] Fix | Delete
If the debugger stops on this function return, invoke
[140] Fix | Delete
self.user_return(). Raise BdbQuit if self.quitting is set.
[141] Fix | Delete
Return self.trace_dispatch to continue tracing in this scope.
[142] Fix | Delete
"""
[143] Fix | Delete
if self.stop_here(frame) or frame == self.returnframe:
[144] Fix | Delete
# Ignore return events in generator except when stepping.
[145] Fix | Delete
if self.stopframe and frame.f_code.co_flags & GENERATOR_AND_COROUTINE_FLAGS:
[146] Fix | Delete
return self.trace_dispatch
[147] Fix | Delete
try:
[148] Fix | Delete
self.frame_returning = frame
[149] Fix | Delete
self.user_return(frame, arg)
[150] Fix | Delete
finally:
[151] Fix | Delete
self.frame_returning = None
[152] Fix | Delete
if self.quitting: raise BdbQuit
[153] Fix | Delete
# The user issued a 'next' or 'until' command.
[154] Fix | Delete
if self.stopframe is frame and self.stoplineno != -1:
[155] Fix | Delete
self._set_stopinfo(None, None)
[156] Fix | Delete
return self.trace_dispatch
[157] Fix | Delete
[158] Fix | Delete
def dispatch_exception(self, frame, arg):
[159] Fix | Delete
"""Invoke user function and return trace function for exception event.
[160] Fix | Delete
[161] Fix | Delete
If the debugger stops on this exception, invoke
[162] Fix | Delete
self.user_exception(). Raise BdbQuit if self.quitting is set.
[163] Fix | Delete
Return self.trace_dispatch to continue tracing in this scope.
[164] Fix | Delete
"""
[165] Fix | Delete
if self.stop_here(frame):
[166] Fix | Delete
# When stepping with next/until/return in a generator frame, skip
[167] Fix | Delete
# the internal StopIteration exception (with no traceback)
[168] Fix | Delete
# triggered by a subiterator run with the 'yield from' statement.
[169] Fix | Delete
if not (frame.f_code.co_flags & GENERATOR_AND_COROUTINE_FLAGS
[170] Fix | Delete
and arg[0] is StopIteration and arg[2] is None):
[171] Fix | Delete
self.user_exception(frame, arg)
[172] Fix | Delete
if self.quitting: raise BdbQuit
[173] Fix | Delete
# Stop at the StopIteration or GeneratorExit exception when the user
[174] Fix | Delete
# has set stopframe in a generator by issuing a return command, or a
[175] Fix | Delete
# next/until command at the last statement in the generator before the
[176] Fix | Delete
# exception.
[177] Fix | Delete
elif (self.stopframe and frame is not self.stopframe
[178] Fix | Delete
and self.stopframe.f_code.co_flags & GENERATOR_AND_COROUTINE_FLAGS
[179] Fix | Delete
and arg[0] in (StopIteration, GeneratorExit)):
[180] Fix | Delete
self.user_exception(frame, arg)
[181] Fix | Delete
if self.quitting: raise BdbQuit
[182] Fix | Delete
[183] Fix | Delete
return self.trace_dispatch
[184] Fix | Delete
[185] Fix | Delete
# Normally derived classes don't override the following
[186] Fix | Delete
# methods, but they may if they want to redefine the
[187] Fix | Delete
# definition of stopping and breakpoints.
[188] Fix | Delete
[189] Fix | Delete
def is_skipped_module(self, module_name):
[190] Fix | Delete
"Return True if module_name matches any skip pattern."
[191] Fix | Delete
if module_name is None: # some modules do not have names
[192] Fix | Delete
return False
[193] Fix | Delete
for pattern in self.skip:
[194] Fix | Delete
if fnmatch.fnmatch(module_name, pattern):
[195] Fix | Delete
return True
[196] Fix | Delete
return False
[197] Fix | Delete
[198] Fix | Delete
def stop_here(self, frame):
[199] Fix | Delete
"Return True if frame is below the starting frame in the stack."
[200] Fix | Delete
# (CT) stopframe may now also be None, see dispatch_call.
[201] Fix | Delete
# (CT) the former test for None is therefore removed from here.
[202] Fix | Delete
if self.skip and \
[203] Fix | Delete
self.is_skipped_module(frame.f_globals.get('__name__')):
[204] Fix | Delete
return False
[205] Fix | Delete
if frame is self.stopframe:
[206] Fix | Delete
if self.stoplineno == -1:
[207] Fix | Delete
return False
[208] Fix | Delete
return frame.f_lineno >= self.stoplineno
[209] Fix | Delete
if not self.stopframe:
[210] Fix | Delete
return True
[211] Fix | Delete
return False
[212] Fix | Delete
[213] Fix | Delete
def break_here(self, frame):
[214] Fix | Delete
"""Return True if there is an effective breakpoint for this line.
[215] Fix | Delete
[216] Fix | Delete
Check for line or function breakpoint and if in effect.
[217] Fix | Delete
Delete temporary breakpoints if effective() says to.
[218] Fix | Delete
"""
[219] Fix | Delete
filename = self.canonic(frame.f_code.co_filename)
[220] Fix | Delete
if filename not in self.breaks:
[221] Fix | Delete
return False
[222] Fix | Delete
lineno = frame.f_lineno
[223] Fix | Delete
if lineno not in self.breaks[filename]:
[224] Fix | Delete
# The line itself has no breakpoint, but maybe the line is the
[225] Fix | Delete
# first line of a function with breakpoint set by function name.
[226] Fix | Delete
lineno = frame.f_code.co_firstlineno
[227] Fix | Delete
if lineno not in self.breaks[filename]:
[228] Fix | Delete
return False
[229] Fix | Delete
[230] Fix | Delete
# flag says ok to delete temp. bp
[231] Fix | Delete
(bp, flag) = effective(filename, lineno, frame)
[232] Fix | Delete
if bp:
[233] Fix | Delete
self.currentbp = bp.number
[234] Fix | Delete
if (flag and bp.temporary):
[235] Fix | Delete
self.do_clear(str(bp.number))
[236] Fix | Delete
return True
[237] Fix | Delete
else:
[238] Fix | Delete
return False
[239] Fix | Delete
[240] Fix | Delete
def do_clear(self, arg):
[241] Fix | Delete
"""Remove temporary breakpoint.
[242] Fix | Delete
[243] Fix | Delete
Must implement in derived classes or get NotImplementedError.
[244] Fix | Delete
"""
[245] Fix | Delete
raise NotImplementedError("subclass of bdb must implement do_clear()")
[246] Fix | Delete
[247] Fix | Delete
def break_anywhere(self, frame):
[248] Fix | Delete
"""Return True if there is any breakpoint for frame's filename.
[249] Fix | Delete
"""
[250] Fix | Delete
return self.canonic(frame.f_code.co_filename) in self.breaks
[251] Fix | Delete
[252] Fix | Delete
# Derived classes should override the user_* methods
[253] Fix | Delete
# to gain control.
[254] Fix | Delete
[255] Fix | Delete
def user_call(self, frame, argument_list):
[256] Fix | Delete
"""Called if we might stop in a function."""
[257] Fix | Delete
pass
[258] Fix | Delete
[259] Fix | Delete
def user_line(self, frame):
[260] Fix | Delete
"""Called when we stop or break at a line."""
[261] Fix | Delete
pass
[262] Fix | Delete
[263] Fix | Delete
def user_return(self, frame, return_value):
[264] Fix | Delete
"""Called when a return trap is set here."""
[265] Fix | Delete
pass
[266] Fix | Delete
[267] Fix | Delete
def user_exception(self, frame, exc_info):
[268] Fix | Delete
"""Called when we stop on an exception."""
[269] Fix | Delete
pass
[270] Fix | Delete
[271] Fix | Delete
def _set_stopinfo(self, stopframe, returnframe, stoplineno=0):
[272] Fix | Delete
"""Set the attributes for stopping.
[273] Fix | Delete
[274] Fix | Delete
If stoplineno is greater than or equal to 0, then stop at line
[275] Fix | Delete
greater than or equal to the stopline. If stoplineno is -1, then
[276] Fix | Delete
don't stop at all.
[277] Fix | Delete
"""
[278] Fix | Delete
self.stopframe = stopframe
[279] Fix | Delete
self.returnframe = returnframe
[280] Fix | Delete
self.quitting = False
[281] Fix | Delete
# stoplineno >= 0 means: stop at line >= the stoplineno
[282] Fix | Delete
# stoplineno -1 means: don't stop at all
[283] Fix | Delete
self.stoplineno = stoplineno
[284] Fix | Delete
[285] Fix | Delete
# Derived classes and clients can call the following methods
[286] Fix | Delete
# to affect the stepping state.
[287] Fix | Delete
[288] Fix | Delete
def set_until(self, frame, lineno=None):
[289] Fix | Delete
"""Stop when the line with the lineno greater than the current one is
[290] Fix | Delete
reached or when returning from current frame."""
[291] Fix | Delete
# the name "until" is borrowed from gdb
[292] Fix | Delete
if lineno is None:
[293] Fix | Delete
lineno = frame.f_lineno + 1
[294] Fix | Delete
self._set_stopinfo(frame, frame, lineno)
[295] Fix | Delete
[296] Fix | Delete
def set_step(self):
[297] Fix | Delete
"""Stop after one line of code."""
[298] Fix | Delete
# Issue #13183: pdb skips frames after hitting a breakpoint and running
[299] Fix | Delete
# step commands.
[300] Fix | Delete
# Restore the trace function in the caller (that may not have been set
[301] Fix | Delete
# for performance reasons) when returning from the current frame.
[302] Fix | Delete
if self.frame_returning:
[303] Fix | Delete
caller_frame = self.frame_returning.f_back
[304] Fix | Delete
if caller_frame and not caller_frame.f_trace:
[305] Fix | Delete
caller_frame.f_trace = self.trace_dispatch
[306] Fix | Delete
self._set_stopinfo(None, None)
[307] Fix | Delete
[308] Fix | Delete
def set_next(self, frame):
[309] Fix | Delete
"""Stop on the next line in or below the given frame."""
[310] Fix | Delete
self._set_stopinfo(frame, None)
[311] Fix | Delete
[312] Fix | Delete
def set_return(self, frame):
[313] Fix | Delete
"""Stop when returning from the given frame."""
[314] Fix | Delete
if frame.f_code.co_flags & GENERATOR_AND_COROUTINE_FLAGS:
[315] Fix | Delete
self._set_stopinfo(frame, None, -1)
[316] Fix | Delete
else:
[317] Fix | Delete
self._set_stopinfo(frame.f_back, frame)
[318] Fix | Delete
[319] Fix | Delete
def set_trace(self, frame=None):
[320] Fix | Delete
"""Start debugging from frame.
[321] Fix | Delete
[322] Fix | Delete
If frame is not specified, debugging starts from caller's frame.
[323] Fix | Delete
"""
[324] Fix | Delete
if frame is None:
[325] Fix | Delete
frame = sys._getframe().f_back
[326] Fix | Delete
self.reset()
[327] Fix | Delete
while frame:
[328] Fix | Delete
frame.f_trace = self.trace_dispatch
[329] Fix | Delete
self.botframe = frame
[330] Fix | Delete
frame = frame.f_back
[331] Fix | Delete
self.set_step()
[332] Fix | Delete
sys.settrace(self.trace_dispatch)
[333] Fix | Delete
[334] Fix | Delete
def set_continue(self):
[335] Fix | Delete
"""Stop only at breakpoints or when finished.
[336] Fix | Delete
[337] Fix | Delete
If there are no breakpoints, set the system trace function to None.
[338] Fix | Delete
"""
[339] Fix | Delete
# Don't stop except at breakpoints or when finished
[340] Fix | Delete
self._set_stopinfo(self.botframe, None, -1)
[341] Fix | Delete
if not self.breaks:
[342] Fix | Delete
# no breakpoints; run without debugger overhead
[343] Fix | Delete
sys.settrace(None)
[344] Fix | Delete
frame = sys._getframe().f_back
[345] Fix | Delete
while frame and frame is not self.botframe:
[346] Fix | Delete
del frame.f_trace
[347] Fix | Delete
frame = frame.f_back
[348] Fix | Delete
[349] Fix | Delete
def set_quit(self):
[350] Fix | Delete
"""Set quitting attribute to True.
[351] Fix | Delete
[352] Fix | Delete
Raises BdbQuit exception in the next call to a dispatch_*() method.
[353] Fix | Delete
"""
[354] Fix | Delete
self.stopframe = self.botframe
[355] Fix | Delete
self.returnframe = None
[356] Fix | Delete
self.quitting = True
[357] Fix | Delete
sys.settrace(None)
[358] Fix | Delete
[359] Fix | Delete
# Derived classes and clients can call the following methods
[360] Fix | Delete
# to manipulate breakpoints. These methods return an
[361] Fix | Delete
# error message if something went wrong, None if all is well.
[362] Fix | Delete
# Set_break prints out the breakpoint line and file:lineno.
[363] Fix | Delete
# Call self.get_*break*() to see the breakpoints or better
[364] Fix | Delete
# for bp in Breakpoint.bpbynumber: if bp: bp.bpprint().
[365] Fix | Delete
[366] Fix | Delete
def set_break(self, filename, lineno, temporary=False, cond=None,
[367] Fix | Delete
funcname=None):
[368] Fix | Delete
"""Set a new breakpoint for filename:lineno.
[369] Fix | Delete
[370] Fix | Delete
If lineno doesn't exist for the filename, return an error message.
[371] Fix | Delete
The filename should be in canonical form.
[372] Fix | Delete
"""
[373] Fix | Delete
filename = self.canonic(filename)
[374] Fix | Delete
import linecache # Import as late as possible
[375] Fix | Delete
line = linecache.getline(filename, lineno)
[376] Fix | Delete
if not line:
[377] Fix | Delete
return 'Line %s:%d does not exist' % (filename, lineno)
[378] Fix | Delete
list = self.breaks.setdefault(filename, [])
[379] Fix | Delete
if lineno not in list:
[380] Fix | Delete
list.append(lineno)
[381] Fix | Delete
bp = Breakpoint(filename, lineno, temporary, cond, funcname)
[382] Fix | Delete
return None
[383] Fix | Delete
[384] Fix | Delete
def _prune_breaks(self, filename, lineno):
[385] Fix | Delete
"""Prune breakpoints for filename:lineno.
[386] Fix | Delete
[387] Fix | Delete
A list of breakpoints is maintained in the Bdb instance and in
[388] Fix | Delete
the Breakpoint class. If a breakpoint in the Bdb instance no
[389] Fix | Delete
longer exists in the Breakpoint class, then it's removed from the
[390] Fix | Delete
Bdb instance.
[391] Fix | Delete
"""
[392] Fix | Delete
if (filename, lineno) not in Breakpoint.bplist:
[393] Fix | Delete
self.breaks[filename].remove(lineno)
[394] Fix | Delete
if not self.breaks[filename]:
[395] Fix | Delete
del self.breaks[filename]
[396] Fix | Delete
[397] Fix | Delete
def clear_break(self, filename, lineno):
[398] Fix | Delete
"""Delete breakpoints for filename:lineno.
[399] Fix | Delete
[400] Fix | Delete
If no breakpoints were set, return an error message.
[401] Fix | Delete
"""
[402] Fix | Delete
filename = self.canonic(filename)
[403] Fix | Delete
if filename not in self.breaks:
[404] Fix | Delete
return 'There are no breakpoints in %s' % filename
[405] Fix | Delete
if lineno not in self.breaks[filename]:
[406] Fix | Delete
return 'There is no breakpoint at %s:%d' % (filename, lineno)
[407] Fix | Delete
# If there's only one bp in the list for that file,line
[408] Fix | Delete
# pair, then remove the breaks entry
[409] Fix | Delete
for bp in Breakpoint.bplist[filename, lineno][:]:
[410] Fix | Delete
bp.deleteMe()
[411] Fix | Delete
self._prune_breaks(filename, lineno)
[412] Fix | Delete
return None
[413] Fix | Delete
[414] Fix | Delete
def clear_bpbynumber(self, arg):
[415] Fix | Delete
"""Delete a breakpoint by its index in Breakpoint.bpbynumber.
[416] Fix | Delete
[417] Fix | Delete
If arg is invalid, return an error message.
[418] Fix | Delete
"""
[419] Fix | Delete
try:
[420] Fix | Delete
bp = self.get_bpbynumber(arg)
[421] Fix | Delete
except ValueError as err:
[422] Fix | Delete
return str(err)
[423] Fix | Delete
bp.deleteMe()
[424] Fix | Delete
self._prune_breaks(bp.file, bp.line)
[425] Fix | Delete
return None
[426] Fix | Delete
[427] Fix | Delete
def clear_all_file_breaks(self, filename):
[428] Fix | Delete
"""Delete all breakpoints in filename.
[429] Fix | Delete
[430] Fix | Delete
If none were set, return an error message.
[431] Fix | Delete
"""
[432] Fix | Delete
filename = self.canonic(filename)
[433] Fix | Delete
if filename not in self.breaks:
[434] Fix | Delete
return 'There are no breakpoints in %s' % filename
[435] Fix | Delete
for line in self.breaks[filename]:
[436] Fix | Delete
blist = Breakpoint.bplist[filename, line]
[437] Fix | Delete
for bp in blist:
[438] Fix | Delete
bp.deleteMe()
[439] Fix | Delete
del self.breaks[filename]
[440] Fix | Delete
return None
[441] Fix | Delete
[442] Fix | Delete
def clear_all_breaks(self):
[443] Fix | Delete
"""Delete all existing breakpoints.
[444] Fix | Delete
[445] Fix | Delete
If none were set, return an error message.
[446] Fix | Delete
"""
[447] Fix | Delete
if not self.breaks:
[448] Fix | Delete
return 'There are no breakpoints'
[449] Fix | Delete
for bp in Breakpoint.bpbynumber:
[450] Fix | Delete
if bp:
[451] Fix | Delete
bp.deleteMe()
[452] Fix | Delete
self.breaks = {}
[453] Fix | Delete
return None
[454] Fix | Delete
[455] Fix | Delete
def get_bpbynumber(self, arg):
[456] Fix | Delete
"""Return a breakpoint by its index in Breakpoint.bybpnumber.
[457] Fix | Delete
[458] Fix | Delete
For invalid arg values or if the breakpoint doesn't exist,
[459] Fix | Delete
raise a ValueError.
[460] Fix | Delete
"""
[461] Fix | Delete
if not arg:
[462] Fix | Delete
raise ValueError('Breakpoint number expected')
[463] Fix | Delete
try:
[464] Fix | Delete
number = int(arg)
[465] Fix | Delete
except ValueError:
[466] Fix | Delete
raise ValueError('Non-numeric breakpoint number %s' % arg) from None
[467] Fix | Delete
try:
[468] Fix | Delete
bp = Breakpoint.bpbynumber[number]
[469] Fix | Delete
except IndexError:
[470] Fix | Delete
raise ValueError('Breakpoint number %d out of range' % number) from None
[471] Fix | Delete
if bp is None:
[472] Fix | Delete
raise ValueError('Breakpoint %d already deleted' % number)
[473] Fix | Delete
return bp
[474] Fix | Delete
[475] Fix | Delete
def get_break(self, filename, lineno):
[476] Fix | Delete
"""Return True if there is a breakpoint for filename:lineno."""
[477] Fix | Delete
filename = self.canonic(filename)
[478] Fix | Delete
return filename in self.breaks and \
[479] Fix | Delete
lineno in self.breaks[filename]
[480] Fix | Delete
[481] Fix | Delete
def get_breaks(self, filename, lineno):
[482] Fix | Delete
"""Return all breakpoints for filename:lineno.
[483] Fix | Delete
[484] Fix | Delete
If no breakpoints are set, return an empty list.
[485] Fix | Delete
"""
[486] Fix | Delete
filename = self.canonic(filename)
[487] Fix | Delete
return filename in self.breaks and \
[488] Fix | Delete
lineno in self.breaks[filename] and \
[489] Fix | Delete
Breakpoint.bplist[filename, lineno] or []
[490] Fix | Delete
[491] Fix | Delete
def get_file_breaks(self, filename):
[492] Fix | Delete
"""Return all lines with breakpoints for filename.
[493] Fix | Delete
[494] Fix | Delete
If no breakpoints are set, return an empty list.
[495] Fix | Delete
"""
[496] Fix | Delete
filename = self.canonic(filename)
[497] Fix | Delete
if filename in self.breaks:
[498] Fix | Delete
return self.breaks[filename]
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function