From: R. David Murray Date: Tue, 14 Dec 2010 14:16:20 +0000 (+0000) Subject: #10695: use %s not %d so that a string 'port' does not cause a debug traceback X-Git-Tag: v3.2b2~103 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=32ef70c827997f869a8d8393e8bde74016b6c8a9;p=python #10695: use %s not %d so that a string 'port' does not cause a debug traceback Passing the port as a string value works fine in regular mode, but if you turned debug on it would throw an error trying to print the port number, which is surprising and confusing. --- diff --git a/Lib/telnetlib.py b/Lib/telnetlib.py index c60578debf..82b5e8fc1b 100644 --- a/Lib/telnetlib.py +++ b/Lib/telnetlib.py @@ -236,7 +236,7 @@ class Telnet: """ if self.debuglevel > 0: - print('Telnet(%s,%d):' % (self.host, self.port), end=' ') + print('Telnet(%s,%s):' % (self.host, self.port), end=' ') if args: print(msg % args) else: diff --git a/Lib/test/test_telnetlib.py b/Lib/test/test_telnetlib.py index e4210c5cf4..843daf1585 100644 --- a/Lib/test/test_telnetlib.py +++ b/Lib/test/test_telnetlib.py @@ -342,6 +342,16 @@ class OptionTests(TestCase): expected = "send b'xxx'\n" self.assertIn(expected, telnet._messages) + def test_debug_accepts_str_port(self): + # Issue 10695 + with test_socket([]): + telnet = TelnetAlike('dummy', '0') + telnet._messages = '' + telnet.set_debuglevel(1) + telnet.msg('test') + self.assertRegex(telnet._messages, r'0.*test') + + def test_main(verbose=None): support.run_unittest(GeneralTests, ReadTests, WriteTests, OptionTests) diff --git a/Misc/NEWS b/Misc/NEWS index aa90c16a43..d2a2c42b87 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -11,6 +11,9 @@ What's New in Python 3.2 Beta 2? Library ------- +- Issue #10695: passing the port as a string value to telnetlib no longer + causes debug mode to fail. + - Issue #1078919: add_header now automatically RFC2231 encodes parameters that contain non-ascii values.