mirror of
https://github.com/python/cpython.git
synced 2025-08-02 16:13:13 +00:00
Merged revisions 83380 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k ........ r83380 | r.david.murray | 2010-07-31 23:31:09 -0400 (Sat, 31 Jul 2010) | 17 lines #8620: Cmd no longer truncates last character if stdin ends without newline Cmd used to blindly chop off the last character of every input line. If the input reached EOF and there was no final new line, it would truncate the last character of the last command. This fix instead strips trailing \r\n from the input lines. While this is a small behavior change, it should not break any working code, since feeding a '\r\n' terminated file to Cmd would previously leave the \r's on the lines, resulting in failed command execution. I wrote the unit test in preparation for a PyOhio TeachMe session run by Catherine Devlin, and we can thank Catherine and the PyOhio session attendees for the fix. I've added Catherine to the Acks file for organizing and leading the TeachMe session, out of which we will hopefully get some new contributors. ........
This commit is contained in:
parent
5a34b7f50a
commit
ea6ff81323
4 changed files with 31 additions and 2 deletions
|
@ -134,7 +134,7 @@ class Cmd:
|
||||||
if not len(line):
|
if not len(line):
|
||||||
line = 'EOF'
|
line = 'EOF'
|
||||||
else:
|
else:
|
||||||
line = line[:-1] # chop \n
|
line = line.rstrip('\r\n')
|
||||||
line = self.precmd(line)
|
line = self.precmd(line)
|
||||||
stop = self.onecmd(line)
|
stop = self.onecmd(line)
|
||||||
stop = self.postcmd(stop, line)
|
stop = self.postcmd(stop, line)
|
||||||
|
|
|
@ -9,7 +9,8 @@ import cmd
|
||||||
import sys
|
import sys
|
||||||
import trace
|
import trace
|
||||||
import re
|
import re
|
||||||
from io import StringIO
|
import unittest
|
||||||
|
import io
|
||||||
|
|
||||||
class samplecmdclass(cmd.Cmd):
|
class samplecmdclass(cmd.Cmd):
|
||||||
"""
|
"""
|
||||||
|
@ -166,9 +167,33 @@ class samplecmdclass(cmd.Cmd):
|
||||||
def do_exit(self, arg):
|
def do_exit(self, arg):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
class TestAlternateInput(unittest.TestCase):
|
||||||
|
|
||||||
|
class simplecmd(cmd.Cmd):
|
||||||
|
|
||||||
|
def do_print(self, args):
|
||||||
|
print(args, file=self.stdout)
|
||||||
|
|
||||||
|
def do_EOF(self, args):
|
||||||
|
return True
|
||||||
|
|
||||||
|
def test_file_with_missing_final_nl(self):
|
||||||
|
input = io.StringIO("print test\nprint test2")
|
||||||
|
output = io.StringIO()
|
||||||
|
cmd = self.simplecmd(stdin=input, stdout=output)
|
||||||
|
cmd.use_rawinput = False
|
||||||
|
cmd.cmdloop()
|
||||||
|
self.assertMultiLineEqual(output.getvalue(),
|
||||||
|
("(Cmd) test\n"
|
||||||
|
"(Cmd) test2\n"
|
||||||
|
"(Cmd) "))
|
||||||
|
|
||||||
|
|
||||||
def test_main(verbose=None):
|
def test_main(verbose=None):
|
||||||
from test import support, test_cmd
|
from test import support, test_cmd
|
||||||
support.run_doctest(test_cmd, verbose)
|
support.run_doctest(test_cmd, verbose)
|
||||||
|
support.run_unittest(TestAlternateInput)
|
||||||
|
|
||||||
def test_coverage(coverdir):
|
def test_coverage(coverdir):
|
||||||
tracer=trace.Trace(ignoredirs=[sys.prefix, sys.exec_prefix,],
|
tracer=trace.Trace(ignoredirs=[sys.prefix, sys.exec_prefix,],
|
||||||
|
|
|
@ -179,6 +179,7 @@ Vincent Delft
|
||||||
Arnaud Delobelle
|
Arnaud Delobelle
|
||||||
Erik Demaine
|
Erik Demaine
|
||||||
Roger Dev
|
Roger Dev
|
||||||
|
Catherine Devlin
|
||||||
Raghuram Devarakonda
|
Raghuram Devarakonda
|
||||||
Toby Dickenson
|
Toby Dickenson
|
||||||
Mark Dickinson
|
Mark Dickinson
|
||||||
|
|
|
@ -78,6 +78,9 @@ C-API
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- Issue #8620: when a Cmd is fed input that reaches EOF without a final
|
||||||
|
newline, it no longer truncates the last character of the last command line.
|
||||||
|
|
||||||
- Issue #3704: http.cookiejar was not properly handling URLs with a / in the
|
- Issue #3704: http.cookiejar was not properly handling URLs with a / in the
|
||||||
parameters.
|
parameters.
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue