Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 148ffbc

Browse files
committed
canonic(): This used to be equivalent to str() but that caused too
much breakage (esp. in JPython which holds absolute path names in co_filename already). This implementation uses os.path.abspath() as a slightly better way to canonicalize path names. It implements a cache.
1 parent 2bee8fe commit 148ffbc

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

Lib/bdb.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Debugger basics
22

33
import sys
4+
import os
45
import types
56

67
BdbQuit = 'bdb.BdbQuit' # Exception to give up completely
@@ -17,12 +18,14 @@ class Bdb:
1718

1819
def __init__(self):
1920
self.breaks = {}
20-
# We want to have a method self.canonic() which
21-
# canonicalizes filenames before comparing them
22-
# but we want the default to be a very fast no-op.
23-
# Solution: the built-in str function.
24-
if not hasattr(self, "canonic"):
25-
self.canonic = str
21+
self.fncache = {}
22+
23+
def canonic(self, filename):
24+
canonic = self.fncache.get(filename)
25+
if not canonic:
26+
canonic = os.path.abspath(filename)
27+
self.fncache[filename] = canonic
28+
return canonic
2629

2730
def reset(self):
2831
import linecache

0 commit comments

Comments
 (0)