Skip to content

Commit 32ef70c

Browse files
committed
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.
1 parent 8edd99d commit 32ef70c

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

Lib/telnetlib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ def msg(self, msg, *args):
236236
237237
"""
238238
if self.debuglevel > 0:
239-
print('Telnet(%s,%d):' % (self.host, self.port), end=' ')
239+
print('Telnet(%s,%s):' % (self.host, self.port), end=' ')
240240
if args:
241241
print(msg % args)
242242
else:

Lib/test/test_telnetlib.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,16 @@ def test_debuglevel_write(self):
342342
expected = "send b'xxx'\n"
343343
self.assertIn(expected, telnet._messages)
344344

345+
def test_debug_accepts_str_port(self):
346+
# Issue 10695
347+
with test_socket([]):
348+
telnet = TelnetAlike('dummy', '0')
349+
telnet._messages = ''
350+
telnet.set_debuglevel(1)
351+
telnet.msg('test')
352+
self.assertRegex(telnet._messages, r'0.*test')
353+
354+
345355
def test_main(verbose=None):
346356
support.run_unittest(GeneralTests, ReadTests, WriteTests, OptionTests)
347357

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ What's New in Python 3.2 Beta 2?
1111
Library
1212
-------
1313

14+
- Issue #10695: passing the port as a string value to telnetlib no longer
15+
causes debug mode to fail.
16+
1417
- Issue #1078919: add_header now automatically RFC2231 encodes parameters
1518
that contain non-ascii values.
1619

0 commit comments

Comments
 (0)