E5E6 bpo-29621: telnetlib.write() raise TypeError if recv non-bytes type. by corona10 · Pull Request #1321 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Lib/telnetlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,8 @@ def write(self, buffer):
OSError if the connection is closed.

"""
if not isinstance(buffer, (bytes, bytearray)):
raise TypeError('%s must be a bytes-like type.' % buffer)
if IAC in buffer:
buffer = buffer.replace(IAC, IAC+IAC)
self.msg("send %r", buffer)
Expand Down
11 changes: 11 additions & 0 deletions Lib/test/test_telnetlib.py EA78
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,17 @@ def test_write(self):
written = b''.join(telnet.sock.writes)
self.assertEqual(data.replace(tl.IAC,tl.IAC+tl.IAC), written)


def test_write_type_error(self):
non_bytes_data_sample = ['data sample with string',
[b'data sample without IAC'],
[b'data sample with', tl.IAC, b' one IAC'],
(b'data sample with', tl.IAC ,b' one IAC'),
'']
for data in non_bytes_data_sample:
telnet = test_telnet()
self.assertRaises(TypeError, telnet.write, data)

class OptionTests(unittest.TestCase):
# RFC 854 commands
cmds = [tl.AO, tl.AYT, tl.BRK, tl.EC, tl.EL, tl.GA, tl.IP, tl.NOP]
Expand Down
3 changes: 3 additions & 0 deletions Misc/NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,9 @@ Extension Modules
Library
-------

- bpo-29621: If telnetlib.write() receive non-byte-like type
then raise TypeError. Patched by Dong-hee Na.

- bpo-30101: Add support for curses.A_ITALIC.

- bpo-29822: inspect.isabstract() now works during __init_subclass__. Patch
Expand Down
0