]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
canonic(): This used to be equivalent to str() but that caused too
authorBarry Warsaw <barry@python.org>
Thu, 9 Sep 1999 23:24:33 +0000 (23:24 +0000)
committerBarry Warsaw <barry@python.org>
Thu, 9 Sep 1999 23:24:33 +0000 (23:24 +0000)
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.

Lib/bdb.py

index abfb7ded1304ceefbf5c7d699cb766662d4c7af7..89908fc1d16a3d8b5f3a3eb749ce70ea480de35f 100644 (file)
@@ -1,6 +1,7 @@
 # Debugger basics
 
 import sys
+import os
 import types
 
 BdbQuit = 'bdb.BdbQuit' # Exception to give up completely
@@ -17,12 +18,14 @@ 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
+               self.fncache = {}
+
+       def canonic(self, filename):
+               canonic = self.fncache.get(filename)
+               if not canonic:
+                       canonic = os.path.abspath(filename)
+                       self.fncache[filename] = canonic
+               return canonic
        
        def reset(self):
                import linecache