def __cbSelect(self, result, rw):
        """
        Handle lines received in response to a SELECT or EXAMINE command.

        See RFC 3501, section 6.3.1.
        """
        (lines, tagline) = result
        # In the absence of specification, we are free to assume:
        #   READ-WRITE access
        datum = {'READ-WRITE': rw}
        lines.append(parseNestedParens(tagline))
        for split in lines:
            if len(split) > 0 and split[0].upper() == b'OK':
                # Handle all the kinds of OK response.
                content = split[1]
                if isinstance(content, list):
                    key = content[0]
                else:
                    # not multi-valued, like OK LOGIN
                    key = content
                key = key.upper()
                if key == b'READ-ONLY':
                    datum['READ-WRITE'] = False
                elif key == b'READ-WRITE':
                    datum['READ-WRITE'] = True
                elif key == b'UIDVALIDITY':
                    datum['UIDVALIDITY'] = self._intOrRaise(content[1], split)
                elif key == b'UNSEEN':
                    datum['UNSEEN'] = self._intOrRaise(content[1], split)
                elif key == b'UIDNEXT':
                    datum['UIDNEXT'] = self._intOrRaise(content[1], split)
                elif key == b'PERMANENTFLAGS':
                    datum['PERMANENTFLAGS'] = tuple(
                        nativeString(flag) for flag in content[1])
                else:
                    log.err('Unhandled SELECT response (2): %s' % (split,))
            elif len(split) == 2:
                # Handle FLAGS, EXISTS, and RECENT
                if split[0].upper() == b'FLAGS':
                    datum['FLAGS'] = tuple(
                        nativeString(flag) for flag in split[1])
                elif isinstance(split[1], bytes):
                    # Must make sure things are strings before treating them as
                    # strings since some other forms of response have nesting in
                    # places which results in lists instead.
                    if split[1].upper() == b'EXISTS':
                        datum['EXISTS'] = self._intOrRaise(split[0], split)
                    elif split[1].upper() == b'RECENT':
                        datum['RECENT'] = self._intOrRaise(split[0], split)
                    else:
                        log.err('Unhandled SELECT response (0): %s' % (split,))
                else:
                    log.err('Unhandled SELECT response (1): %s' % (split,))
            else:
                log.err('Unhandled SELECT response (4): %s' % (split,))
        return datum

        Handle lines received in response to a SELECT or EXAMINE command.

        See RFC 3501, section 6.3.1.
        
stackoverflow/venv/lib/python3.6/site-packages/twisted/mail/imap4.py