From 0ce3a8fa2bd3f4e72358bb53ecd0acf8fe448483 Mon Sep 17 00:00:00 2001 From: Diane Trout Date: Sat, 4 Nov 2017 23:32:32 -0700 Subject: Avoid errors from Python caused by the deliberatly invalid Unicode Because stream.nick is Unicode when sendMessage combines the command, nick, and invalid utf8 python 2.7 ends up converting everything to Unicode. Since this test deliberately includes invalid Unicode, Python notices and throws an exception. In Python 3, network traffic is usually encoded as bytes. So I thought coercing the nick to bytes would be appropriate, and as bytes can contain anything including invalid Unicode, Python doesn't throw an exception. --- tests/twisted/messages/invalid-utf8.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/twisted/messages/invalid-utf8.py b/tests/twisted/messages/invalid-utf8.py index a48c2f4..725e3bd 100644 --- a/tests/twisted/messages/invalid-utf8.py +++ b/tests/twisted/messages/invalid-utf8.py @@ -33,7 +33,7 @@ def test_with_message(q, stream, parts): # Idle's default character set is UTF-8. We send it a message which is # basically UTF-8, except that one of its code points is invalid. - stream.sendMessage('PRIVMSG', stream.nick, ':%s' % invalid_utf8, + stream.sendMessage('PRIVMSG', bytes(stream.nick), ':%s' % invalid_utf8, prefix='remoteuser') # Idle should signal that *something* was received. If it hasn't validated -- cgit v1.2.1