'This generator function is for the user. All outgoing data has to be
properly escaped, so that no IAC character in the data stream messes up
the Telnet state machine in the server.
socket.sendall(escape(data))'

def escape(self, data):

    for byte in iterbytes(data):
        if (byte == IAC):
            (yield IAC)
            (yield IAC)
        else:
            (yield byte)
