[Python-checkins] cpython (2.7): PDB now will properly escape backslashes in the names of modules it executes.

jason.coombs python-checkins at python.org
Fri Nov 18 00:53:08 CET 2011


http://hg.python.org/cpython/rev/f7dd5178f36a
changeset:   73601:f7dd5178f36a
branch:      2.7
parent:      73585:2a3b60d28f6c
user:        Jason R. Coombs <jaraco at jaraco.com>
date:        Thu Nov 17 18:03:24 2011 -0500
summary:
  PDB now will properly escape backslashes in the names of modules it executes. Fixes #7750

files:
  Lib/pdb.py           |   2 +-
  Lib/test/test_pdb.py |  27 +++++++++++++++++++++++++++
  2 files changed, 28 insertions(+), 1 deletions(-)


diff --git a/Lib/pdb.py b/Lib/pdb.py
--- a/Lib/pdb.py
+++ b/Lib/pdb.py
@@ -1229,7 +1229,7 @@
         self._wait_for_mainpyfile = 1
         self.mainpyfile = self.canonic(filename)
         self._user_requested_quit = 0
-        statement = 'execfile( "%s")' % filename
+        statement = 'execfile(%r)' % filename
         self.run(statement)
 
 # Simplified interface
diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py
--- a/Lib/test/test_pdb.py
+++ b/Lib/test/test_pdb.py
@@ -3,6 +3,9 @@
 
 import imp
 import sys
+import os
+import unittest
+import subprocess
 
 from test import test_support
 # This little helper class is essential for testing pdb under doctest.
@@ -277,6 +280,29 @@
     4
     """
 
+class Tester7750(unittest.TestCase):
+    # if the filename has something that resolves to a python
+    #  escape character (such as \t), it will fail
+    test_fn = '.\\test7750.py'
+
+    msg = "issue7750 only applies when os.sep is a backslash"
+    @unittest.skipUnless(os.path.sep == '\\', msg)
+    def test_issue7750(self):
+        with open(self.test_fn, 'w') as f:
+            f.write('print("hello world")')
+        cmd = [sys.executable, '-m', 'pdb', self.test_fn,]
+        proc = subprocess.Popen(cmd,
+            stdout=subprocess.PIPE,
+            stdin=subprocess.PIPE,
+            stderr=subprocess.STDOUT,
+            )
+        stdout, stderr = proc.communicate('quit\n')
+        self.assertNotIn('IOError', stdout, "pdb munged the filename")
+
+    def tearDown(self):
+        if os.path.isfile(self.test_fn):
+            os.remove(self.test_fn)
+
 
 def test_main():
     from test import test_pdb
@@ -285,3 +311,4 @@
 
 if __name__ == '__main__':
     test_main()
+    unittest.main()

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list