Code style cleanup in bdb.
This commit is contained in:
parent
8175daec10
commit
2660747a0b
52
Lib/bdb.py
52
Lib/bdb.py
|
@ -3,16 +3,14 @@
|
||||||
import fnmatch
|
import fnmatch
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
import types
|
|
||||||
|
|
||||||
__all__ = ["BdbQuit","Bdb","Breakpoint"]
|
__all__ = ["BdbQuit", "Bdb", "Breakpoint"]
|
||||||
|
|
||||||
class BdbQuit(Exception):
|
class BdbQuit(Exception):
|
||||||
"""Exception to give up completely"""
|
"""Exception to give up completely."""
|
||||||
|
|
||||||
|
|
||||||
class Bdb:
|
class Bdb:
|
||||||
|
|
||||||
"""Generic Python debugger base class.
|
"""Generic Python debugger base class.
|
||||||
|
|
||||||
This class takes care of details of the trace facility;
|
This class takes care of details of the trace facility;
|
||||||
|
@ -120,14 +118,14 @@ class Bdb:
|
||||||
|
|
||||||
def break_here(self, frame):
|
def break_here(self, frame):
|
||||||
filename = self.canonic(frame.f_code.co_filename)
|
filename = self.canonic(frame.f_code.co_filename)
|
||||||
if not filename in self.breaks:
|
if filename not in self.breaks:
|
||||||
return False
|
return False
|
||||||
lineno = frame.f_lineno
|
lineno = frame.f_lineno
|
||||||
if not lineno in self.breaks[filename]:
|
if lineno not in self.breaks[filename]:
|
||||||
# The line itself has no breakpoint, but maybe the line is the
|
# The line itself has no breakpoint, but maybe the line is the
|
||||||
# first line of a function with breakpoint set by function name.
|
# first line of a function with breakpoint set by function name.
|
||||||
lineno = frame.f_code.co_firstlineno
|
lineno = frame.f_code.co_firstlineno
|
||||||
if not lineno in self.breaks[filename]:
|
if lineno not in self.breaks[filename]:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# flag says ok to delete temp. bp
|
# flag says ok to delete temp. bp
|
||||||
|
@ -243,12 +241,9 @@ class Bdb:
|
||||||
import linecache # Import as late as possible
|
import linecache # Import as late as possible
|
||||||
line = linecache.getline(filename, lineno)
|
line = linecache.getline(filename, lineno)
|
||||||
if not line:
|
if not line:
|
||||||
return 'Line %s:%d does not exist' % (filename,
|
return 'Line %s:%d does not exist' % (filename, lineno)
|
||||||
lineno)
|
list = self.breaks.setdefault(filename, [])
|
||||||
if not filename in self.breaks:
|
if lineno not in list:
|
||||||
self.breaks[filename] = []
|
|
||||||
list = self.breaks[filename]
|
|
||||||
if not lineno in list:
|
|
||||||
list.append(lineno)
|
list.append(lineno)
|
||||||
bp = Breakpoint(filename, lineno, temporary, cond, funcname)
|
bp = Breakpoint(filename, lineno, temporary, cond, funcname)
|
||||||
|
|
||||||
|
@ -260,11 +255,10 @@ class Bdb:
|
||||||
|
|
||||||
def clear_break(self, filename, lineno):
|
def clear_break(self, filename, lineno):
|
||||||
filename = self.canonic(filename)
|
filename = self.canonic(filename)
|
||||||
if not filename in self.breaks:
|
if filename not in self.breaks:
|
||||||
return 'There are no breakpoints in %s' % filename
|
return 'There are no breakpoints in %s' % filename
|
||||||
if lineno not in self.breaks[filename]:
|
if lineno not in self.breaks[filename]:
|
||||||
return 'There is no breakpoint at %s:%d' % (filename,
|
return 'There is no breakpoint at %s:%d' % (filename, lineno)
|
||||||
lineno)
|
|
||||||
# If there's only one bp in the list for that file,line
|
# If there's only one bp in the list for that file,line
|
||||||
# pair, then remove the breaks entry
|
# pair, then remove the breaks entry
|
||||||
for bp in Breakpoint.bplist[filename, lineno][:]:
|
for bp in Breakpoint.bplist[filename, lineno][:]:
|
||||||
|
@ -281,7 +275,7 @@ class Bdb:
|
||||||
|
|
||||||
def clear_all_file_breaks(self, filename):
|
def clear_all_file_breaks(self, filename):
|
||||||
filename = self.canonic(filename)
|
filename = self.canonic(filename)
|
||||||
if not filename in self.breaks:
|
if filename not in self.breaks:
|
||||||
return 'There are no breakpoints in %s' % filename
|
return 'There are no breakpoints in %s' % filename
|
||||||
for line in self.breaks[filename]:
|
for line in self.breaks[filename]:
|
||||||
blist = Breakpoint.bplist[filename, line]
|
blist = Breakpoint.bplist[filename, line]
|
||||||
|
@ -354,31 +348,30 @@ class Bdb:
|
||||||
i = max(0, len(stack) - 1)
|
i = max(0, len(stack) - 1)
|
||||||
return stack, i
|
return stack, i
|
||||||
|
|
||||||
#
|
|
||||||
|
|
||||||
def format_stack_entry(self, frame_lineno, lprefix=': '):
|
def format_stack_entry(self, frame_lineno, lprefix=': '):
|
||||||
import linecache, reprlib
|
import linecache, reprlib
|
||||||
frame, lineno = frame_lineno
|
frame, lineno = frame_lineno
|
||||||
filename = self.canonic(frame.f_code.co_filename)
|
filename = self.canonic(frame.f_code.co_filename)
|
||||||
s = '%s(%r)' % (filename, lineno)
|
s = '%s(%r)' % (filename, lineno)
|
||||||
if frame.f_code.co_name:
|
if frame.f_code.co_name:
|
||||||
s = s + frame.f_code.co_name
|
s += frame.f_code.co_name
|
||||||
else:
|
else:
|
||||||
s = s + "<lambda>"
|
s += "<lambda>"
|
||||||
if '__args__' in frame.f_locals:
|
if '__args__' in frame.f_locals:
|
||||||
args = frame.f_locals['__args__']
|
args = frame.f_locals['__args__']
|
||||||
else:
|
else:
|
||||||
args = None
|
args = None
|
||||||
if args:
|
if args:
|
||||||
s = s + reprlib.repr(args)
|
s += reprlib.repr(args)
|
||||||
else:
|
else:
|
||||||
s = s + '()'
|
s += '()'
|
||||||
if '__return__' in frame.f_locals:
|
if '__return__' in frame.f_locals:
|
||||||
rv = frame.f_locals['__return__']
|
rv = frame.f_locals['__return__']
|
||||||
s = s + '->'
|
s += '->'
|
||||||
s = s + reprlib.repr(rv)
|
s += reprlib.repr(rv)
|
||||||
line = linecache.getline(filename, lineno, frame.f_globals)
|
line = linecache.getline(filename, lineno, frame.f_globals)
|
||||||
if line: s = s + lprefix + line.strip()
|
if line:
|
||||||
|
s += lprefix + line.strip()
|
||||||
return s
|
return s
|
||||||
|
|
||||||
# The following methods can be called by clients to use
|
# The following methods can be called by clients to use
|
||||||
|
@ -442,8 +435,7 @@ def set_trace():
|
||||||
|
|
||||||
|
|
||||||
class Breakpoint:
|
class Breakpoint:
|
||||||
|
"""Breakpoint class.
|
||||||
"""Breakpoint class
|
|
||||||
|
|
||||||
Implements temporary breakpoints, ignore counts, disabling and
|
Implements temporary breakpoints, ignore counts, disabling and
|
||||||
(re)-enabling, and conditionals.
|
(re)-enabling, and conditionals.
|
||||||
|
@ -485,7 +477,6 @@ class Breakpoint:
|
||||||
else:
|
else:
|
||||||
self.bplist[file, line] = [self]
|
self.bplist[file, line] = [self]
|
||||||
|
|
||||||
|
|
||||||
def deleteMe(self):
|
def deleteMe(self):
|
||||||
index = (self.file, self.line)
|
index = (self.file, self.line)
|
||||||
self.bpbynumber[self.number] = None # No longer in list
|
self.bpbynumber[self.number] = None # No longer in list
|
||||||
|
@ -606,6 +597,7 @@ def effective(file, line, frame):
|
||||||
return (b, False)
|
return (b, False)
|
||||||
return (None, None)
|
return (None, None)
|
||||||
|
|
||||||
|
|
||||||
# -------------------- testing --------------------
|
# -------------------- testing --------------------
|
||||||
|
|
||||||
class Tdb(Bdb):
|
class Tdb(Bdb):
|
||||||
|
@ -638,5 +630,3 @@ def bar(a):
|
||||||
def test():
|
def test():
|
||||||
t = Tdb()
|
t = Tdb()
|
||||||
t.run('import bdb; bdb.foo(10)')
|
t.run('import bdb; bdb.foo(10)')
|
||||||
|
|
||||||
# end
|
|
||||||
|
|
Loading…
Reference in New Issue