diff options
author | Guido van Rossum <guido@python.org> | 1999-01-29 22:03:51 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1999-01-29 22:03:51 (GMT) |
commit | 170e190f261b1c86bd9ab6d0a3ab253a8319c1c6 (patch) | |
tree | 60f96ccf8abb51bc115d782ef5f883818537e18a | |
parent | f761287e0aaa282c564ca15fde56e5d8e9af8f29 (diff) | |
download | cpython-170e190f261b1c86bd9ab6d0a3ab253a8319c1c6.zip cpython-170e190f261b1c86bd9ab6d0a3ab253a8319c1c6.tar.gz cpython-170e190f261b1c86bd9ab6d0a3ab253a8319c1c6.tar.bz2 |
Support a canonical() method, implementable by a derived class, to be
applied to all filenames before they are compared, looked up in the
breaks dictionary, etc. The default implementation does nothing --
it's implented as fast as possible via str(). A useful implementation
would make everything a absolute, e.g. return os.path.normcase(
os.path.abspath(filename)).
-rw-r--r-- | Lib/bdb.py | 26 |
1 files changed, 20 insertions, 6 deletions
@@ -17,6 +17,12 @@ class Bdb: def __init__(self): self.breaks = {} + # We want to have a method self.canonic() which + # canonicalizes filenames before comparing them + # but we want the default to be a very fast no-op. + # Solution: the built-in str function. + if not hasattr(self, "canonic"): + self.canonic = str def reset(self): import linecache @@ -86,10 +92,10 @@ class Bdb: return 0 def break_here(self, frame): - filename=frame.f_code.co_filename + filename = self.canonic(frame.f_code.co_filename) if not self.breaks.has_key(filename): return 0 - lineno=frame.f_lineno + lineno = frame.f_lineno if not lineno in self.breaks[filename]: return 0 # flag says ok to delete temp. bp @@ -103,7 +109,8 @@ class Bdb: return 0 def break_anywhere(self, frame): - return self.breaks.has_key(frame.f_code.co_filename) + return self.breaks.has_key( + self.canonic(frame.f_code.co_filename)) # Derived classes should override the user_* methods # to gain control. @@ -191,6 +198,7 @@ class Bdb: # for bp in Breakpoint.bpbynumber: if bp: bp.bpprint(). def set_break(self, filename, lineno, temporary=0, cond = None): + filename = self.canonic(filename) import linecache # Import as late as possible line = linecache.getline(filename, lineno) if not line: @@ -202,8 +210,10 @@ class Bdb: if not lineno in list: list.append(lineno) bp = Breakpoint(filename, lineno, temporary, cond) + print "Breakpoint in", filename, "at", lineno def clear_break(self, filename, lineno): + filename = self.canonic(filename) if not self.breaks.has_key(filename): return 'There are no breakpoints in %s' % filename if lineno not in self.breaks[filename]: @@ -232,6 +242,7 @@ class Bdb: self.clear_break(bp.file, bp.line) def clear_all_file_breaks(self, filename): + filename = self.canonic(filename) if not self.breaks.has_key(filename): return 'There are no breakpoints in %s' % filename for line in self.breaks[filename]: @@ -249,15 +260,18 @@ class Bdb: self.breaks = {} def get_break(self, filename, lineno): + filename = self.canonic(filename) return self.breaks.has_key(filename) and \ lineno in self.breaks[filename] def get_breaks(self, filename, lineno): + filename = self.canonic(filename) return self.breaks.has_key(filename) and \ lineno in self.breaks[filename] and \ Breakpoint.bplist[filename, lineno] or [] def get_file_breaks(self, filename): + filename = self.canonic(filename) if self.breaks.has_key(filename): return self.breaks[filename] else: @@ -290,7 +304,7 @@ class Bdb: def format_stack_entry(self, frame_lineno, lprefix=': '): import linecache, repr, string frame, lineno = frame_lineno - filename = frame.f_code.co_filename + filename = self.canonic(frame.f_code.co_filename) s = filename + '(' + `lineno` + ')' if frame.f_code.co_name: s = s + frame.f_code.co_name @@ -403,7 +417,7 @@ class Breakpoint: # effective break .... see effective() def __init__(self, file, line, temporary=0, cond = None): - self.file = file + self.file = file # This better be in canonical form! self.line = line self.temporary = temporary self.cond = cond @@ -519,7 +533,7 @@ class Tdb(Bdb): import linecache, string name = frame.f_code.co_name if not name: name = '???' - fn = frame.f_code.co_filename + fn = self.canonic(frame.f_code.co_filename) line = linecache.getline(fn, frame.f_lineno) print '+++', fn, frame.f_lineno, name, ':', string.strip(line) def user_return(self, frame, retval): |