]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Backport 1.13 through 1.15, after getting a begging letter from a certain
authorAnthony Baxter <anthonybaxter@gmail.com>
Thu, 18 Dec 2003 09:43:33 +0000 (09:43 +0000)
committerAnthony Baxter <anthonybaxter@gmail.com>
Thu, 18 Dec 2003 09:43:33 +0000 (09:43 +0000)
BDFL <wink>

  The fullmodname() function chopped off the first character if the
  module existed in the current directory.

  Open results files, which contain binary pickles, in binary mode.
  Remove fallback code that tries to read marshal data from a results
  file, since this module never writes marshal data.

Lib/trace.py

index 0f27273f5f1227a391042a49334e427a18f9a09e..7f412633cf809af1f60fea94e9c11c130d12e02e 100644 (file)
@@ -180,7 +180,11 @@ def fullmodname(path):
             if len(dir) > len(longest):
                 longest = dir
 
-    base = path[len(longest) + 1:].replace("/", ".")
+    if longest:
+        base = path[len(longest) + 1:]
+    else:
+        base = path
+    base = base.replace("/", ".")
     filename, ext = os.path.splitext(base)
     return filename
 
@@ -200,13 +204,11 @@ class CoverageResults:
         if self.infile:
             # Try to merge existing counts file.
             try:
-                counts, calledfuncs = pickle.load(open(self.infile, 'r'))
+                counts, calledfuncs = pickle.load(open(self.infile, 'rb'))
                 self.update(self.__class__(counts, calledfuncs))
             except (IOError, EOFError, ValueError), err:
                 print >> sys.stderr, ("Skipping counts file %r: %s"
                                       % (self.infile, err))
-            except pickle.UnpicklingError:
-                self.update(self.__class__(marshal.load(open(self.infile))))
 
     def update(self, other):
         """Merge in the data from another CoverageResults"""
@@ -284,7 +286,7 @@ class CoverageResults:
             # try and store counts and module info into self.outfile
             try:
                 pickle.dump((self.counts, self.calledfuncs),
-                            open(self.outfile, 'w'), 1)
+                            open(self.outfile, 'wb'), 1)
             except IOError, err:
                 print >> sys.stderr, "Can't save counts files because %s" % err