'Handles negotiation of the ttype protocol once the client has
confirmed that it will respond with the ttype protocol.
Args:
option (Option): Not used.
Notes:
The negotiation proceeds in several steps, each returning a
certain piece of information about the client. All data is
stored on protocol.protocol_flags under the TTYPE key.'

def will_ttype(self, option):

    options = self.protocol.protocol_flags
    if ((options and options.get('TTYPE', False)) or (self.ttype_step > 3)):
        return
    try:
        option = ''.join(option).lstrip(IS)
    except TypeError:
        pass
    if (self.ttype_step == 0):
        self.protocol.requestNegotiation(TTYPE, SEND)
    elif (self.ttype_step == 1):
        clientname = option.upper()
        cupper = clientname.upper()
        if cupper.startswith('MUDLET'):
            xterm256 = (cupper.split('MUDLET', 1)[1].strip() >= '1.1')
        else:
            xterm256 = (cupper.startswith('XTERM') or cupper.endswith('-256COLOR') or (cupper in ('ATLANTIS', 'CMUD', 'KILDCLIENT', 'MUDLET', 'MUSHCLIENT', 'PUTTY', 'BEIP', 'POTATO')))
        self.protocol.protocol_flags['ANSI'] = True
        self.protocol.protocol_flags['XTERM256'] = xterm256
        self.protocol.protocol_flags['CLIENTNAME'] = clientname
        self.protocol.requestNegotiation(TTYPE, SEND)
    elif (self.ttype_step == 2):
        term = option
        tupper = term.upper()
        xterm256 = (tupper.endswith('-256COLOR') or (tupper.endswith('XTERM') and (not tupper.endswith('-COLOR'))))
        if xterm256:
            self.protocol.protocol_flags['ANSI'] = True
            self.protocol.protocol_flags['XTERM256'] = xterm256
        self.protocol.protocol_flags['TERM'] = term
        self.protocol.requestNegotiation(TTYPE, SEND)
    elif (self.ttype_step == 3):
        if option.startswith('MTTS'):
            option = option[4:].strip()
            if option.isdigit():
                option = int(option)
                support = dict(((capability, True) for (bitval, capability) in MTTS if ((option & bitval) > 0)))
                self.protocol.protocol_flags.update(support)
            else:
                self.protocol.protocol_flags[option.upper()] = True
        self.protocol.protocol_flags['TTYPE'] = True
        self.protocol.handshake_done()
    self.ttype_step += 1
