Index: Lib/pdb.py =================================================================== --- Lib/pdb.py (revision 78295) +++ Lib/pdb.py (working copy) @@ -1211,7 +1211,7 @@ self._wait_for_mainpyfile = 1 self.mainpyfile = self.canonic(filename) self._user_requested_quit = 0 - with open(filename, "rb") as fp: + with open(filename, "r") as fp: statement = "exec(compile(%r, %r, 'exec'))" % \ (fp.read(), self.mainpyfile) self.run(statement) Index: Lib/test/test_pdb.py =================================================================== --- Lib/test/test_pdb.py (revision 78295) +++ Lib/test/test_pdb.py (working copy) @@ -5,7 +5,9 @@ import os import sys import doctest +import subprocess import tempfile +import unittest from test import support # This little helper class is essential for testing pdb under doctest. @@ -125,7 +127,29 @@ (Pdb) continue """ +class Tester7964(unittest.TestCase): + # Issue 7964 identifies a bug in the way script files are opened + # which causes scripts with windows newlines to fail when invoked + # by pdb + test_fn = '.\\test7964.py' + def test_issue7964(self): + # open the file as binary so we can force \r\n newline + with open(self.test_fn, 'wb') as f: + f.write(b'print("hello world")\r\n') + 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(b'quit\n') + self.assertNotIn(b'SyntaxError', stdout, "Got a syntax error running hello world under PDB") + + def tearDown(self): + if os.path.isfile(self.test_fn): + os.remove(self.test_fn) + def test_main(): from test import test_pdb support.run_doctest(test_pdb, verbosity=True) @@ -133,3 +157,4 @@ if __name__ == '__main__': test_main() + unittest.main()