

def will_ttype(self, option):
    '\n        Handles negotiation of the ttype protocol once the client has\n        confirmed that it will respond with the ttype protocol.\n\n        Args:\n            option (Option): Not used.\n\n        Notes:\n            The negotiation proceeds in several steps, each returning a\n            certain piece of information about the client. All data is\n            stored on protocol.protocol_flags under the TTYPE key.\n\n        '
    options = self.protocol.protocol_flags.get('TTYPE')
    if ((options and options.get('init_done')) 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()
        xterm256 = False
        if clientname.startswith('MUDLET'):
            xterm256 = (clientname.split('MUDLET', 1)[1].strip() >= '1.1')
        else:
            xterm256 = (clientname.startswith('XTERM') or clientname.endswith('-256COLOR') or (clientname in ('ATLANTIS', 'CMUD', 'KILDCLIENT', 'MUDLET', 'MUSHCLIENT', 'PUTTY', 'BEIP')))
        self.protocol.protocol_flags['TTYPE']['ANSI'] = True
        self.protocol.protocol_flags['TTYPE']['256 COLORS'] = xterm256
        self.protocol.protocol_flags['TTYPE']['CLIENTNAME'] = clientname
        self.protocol.requestNegotiation(TTYPE, SEND)
    elif (self.ttype_step == 2):
        term = option
        xterm256 = (term.endswith('-256color') or (term.endswith('xterm') and (not term.endswith('-color'))))
        if xterm256:
            self.protocol.protocol_flags['TTYPE']['ANSI'] = True
            self.protocol.protocol_flags['TTYPE']['256 COLORS'] = xterm256
        self.protocol.protocol_flags['TTYPE']['TERM'] = term
        self.protocol.requestNegotiation(TTYPE, SEND)
    elif (self.ttype_step == 3):
        if option.startswith('MTTS'):
            option = option.split(' ')[1]
            if option.isdigit():
                option = int(option)
                support = dict(((capability, True) for (bitval, capability) in MTTS if ((option & bitval) > 0)))
                self.protocol.protocol_flags['TTYPE'].update(support)
            else:
                self.protocol.protocol_flags['TTYPE'][option.upper()] = True
        self.protocol.protocol_flags['TTYPE']['init_done'] = True
        self.protocol.handshake_done()
    self.ttype_step += 1

dataset/ETHPy150Open evennia/evennia/evennia/server/portal/ttype.py Ttype.will_ttype/original