def test_mudlet_ttype(self):
    self.transport.client = ['localhost']
    self.transport.setTcpKeepAlive = Mock()
    d = self.proto.makeConnection(self.transport)
    self.assertTrue(self.proto.protocol_flags['NOGOAHEAD'])
    self.proto.dataReceived(((IAC + DONT) + SUPPRESS_GA))
    self.assertFalse(self.proto.protocol_flags['NOGOAHEAD'])
    self.assertEqual(self.proto.handshakes, 7)
    self.assertEqual(self.proto.protocol_flags['SCREENWIDTH'], {0: DEFAULT_WIDTH})
    self.assertEqual(self.proto.protocol_flags['SCREENHEIGHT'], {0: DEFAULT_HEIGHT})
    self.proto.dataReceived(((IAC + WILL) + NAWS))
    self.proto.dataReceived([IAC, SB, NAWS, '', 'x', '', 'd', IAC, SE])
    self.assertEqual(self.proto.protocol_flags['SCREENWIDTH'][0], 120)
    self.assertEqual(self.proto.protocol_flags['SCREENHEIGHT'][0], 100)
    self.assertEqual(self.proto.handshakes, 6)
    self.assertTrue(self.proto.protocol_flags['FORCEDENDLINE'])
    self.assertFalse(self.proto.protocol_flags['TTYPE'])
    self.assertTrue(self.proto.protocol_flags['ANSI'])
    self.proto.dataReceived(((IAC + WILL) + TTYPE))
    self.proto.dataReceived([IAC, SB, TTYPE, IS, 'MUDLET', IAC, SE])
    self.assertTrue(self.proto.protocol_flags['XTERM256'])
    self.assertEqual(self.proto.protocol_flags['CLIENTNAME'], 'MUDLET')
    self.proto.dataReceived([IAC, SB, TTYPE, IS, 'XTERM', IAC, SE])
    self.proto.dataReceived([IAC, SB, TTYPE, IS, 'MTTS 137', IAC, SE])
    self.assertEqual(self.proto.handshakes, 5)
    self.proto.dataReceived(((IAC + DONT) + MCCP))
    self.assertFalse(self.proto.protocol_flags['MCCP'])
    self.assertEqual(self.proto.handshakes, 4)
    self.proto.dataReceived(((IAC + DONT) + MSSP))
    self.assertEqual(self.proto.handshakes, 3)
    self.proto.dataReceived(((IAC + DO) + MSDP))
    self.proto.dataReceived([IAC, SB, MSDP, MSDP_VAR, 'LIST', MSDP_VAL, 'COMMANDS', IAC, SE])
    self.assertTrue(self.proto.protocol_flags['OOB'])
    self.assertEqual(self.proto.handshakes, 2)
    self.proto.dataReceived(((IAC + DONT) + MXP))
    self.assertFalse(self.proto.protocol_flags['MXP'])
    self.assertEqual(self.proto.handshakes, 1)
    self.proto.nop_keep_alive.stop()
    self.proto._handshake_delay.cancel()
    return d
def test_mudlet_ttype(self):
    self.transport.client = ['localhost']
    self.transport.setTcpKeepAlive = Mock()
    d = self.proto.makeConnection(self.transport)
    self.assertTrue(self.proto.protocol_flags['NOGOAHEAD'])
    self.proto.dataReceived(((IAC + DONT) + SUPPRESS_GA))
    self.assertFalse(self.proto.protocol_flags['NOGOAHEAD'])
    self.assertEqual(self.proto.handshakes, 7)
    self.assertEqual(self.proto.protocol_flags['SCREENWIDTH'], {0: DEFAULT_WIDTH})
    self.assertEqual(self.proto.protocol_flags['SCREENHEIGHT'], {0: DEFAULT_HEIGHT})
    self.proto.dataReceived(((IAC + WILL) + NAWS))
    self.proto.dataReceived([IAC, SB, NAWS, , 'x', , 'd', IAC, SE])
    self.assertEqual(self.proto.protocol_flags['SCREENWIDTH'][0], 120)
    self.assertEqual(self.proto.protocol_flags['SCREENHEIGHT'][0], 100)
    self.assertEqual(self.proto.handshakes, 6)
    self.assertTrue(self.proto.protocol_flags['FORCEDENDLINE'])
    self.assertFalse(self.proto.protocol_flags['TTYPE'])
    self.assertTrue(self.proto.protocol_flags['ANSI'])
    self.proto.dataReceived(((IAC + WILL) + TTYPE))
    self.proto.dataReceived([IAC, SB, TTYPE, IS, 'MUDLET', IAC, SE])
    self.assertTrue(self.proto.protocol_flags['XTERM256'])
    self.assertEqual(self.proto.protocol_flags['CLIENTNAME'], 'MUDLET')
    self.proto.dataReceived([IAC, SB, TTYPE, IS, 'XTERM', IAC, SE])
    self.proto.dataReceived([IAC, SB, TTYPE, IS, 'MTTS 137', IAC, SE])
    self.assertEqual(self.proto.handshakes, 5)
    self.proto.dataReceived(((IAC + DONT) + MCCP))
    self.assertFalse(self.proto.protocol_flags['MCCP'])
    self.assertEqual(self.proto.handshakes, 4)
    self.proto.dataReceived(((IAC + DONT) + MSSP))
    self.assertEqual(self.proto.handshakes, 3)
    self.proto.dataReceived(((IAC + DO) + MSDP))
    self.proto.dataReceived([IAC, SB, MSDP, MSDP_VAR, 'LIST', MSDP_VAL, 'COMMANDS', IAC, SE])
    self.assertTrue(self.proto.protocol_flags['OOB'])
    self.assertEqual(self.proto.handshakes, 2)
    self.proto.dataReceived(((IAC + DONT) + MXP))
    self.assertFalse(self.proto.protocol_flags['MXP'])
    self.assertEqual(self.proto.handshakes, 1)
    self.proto.nop_keep_alive.stop()
    self.proto._handshake_delay.cancel()
    return d