def __format__(self, fmt):
        """ Allow format specs to apply to self.data, such as <, >, and ^.
            This adds a few color-specific features to the format_spec,
            not found in the `ChainedBase` class.
            Colr format spec example:
                '{:[fore=COLOR, back=COLOR, style=STYLE]}'
                ..where COLOR is a stringified version of a valid color arg,
                such as a known name, number, hex code, or RGB value (R;G;B).
                RGB values should be separated with a semicolon, like:
                    '{x:[fore=255;255;255]}'.format(x=Colr('test'))
                Also, `f`,`b`, and `s` are accepted for `fore`, `back`,
                and `style`.

            Example:
                'Hello {x:[fore=red, back=white, style=bright]}'.format(
                    x=Colr('Test')
                )
            Note, if any conversion is done on the object beforehand
            (using !s, !a, !r, and friends) this method is never called.
            It only deals with the `format_spec` described in
            `help('FORMATTING')`.
        """
        if not fmt:
            return str(self)
        if not ('[' in fmt) and (']' in fmt):
            # No color specs found in the format.
            return super().__format__(fmt)

        # Has color specifications. Parse them out.
        normal, _, spec = fmt.partition('[')
        spec = spec.rstrip(']').strip().lower()
        specargs = {}
        # Shorter aliases to use with the spec keys.
        aliases = {
            'f': 'fore',
            'b': 'back',
            's': 'style',
        }
        for kvpairstr in spec.split(','):
            kvpairstr = kvpairstr.strip()
            if not kvpairstr:
                continue
            try:
                k, v = kvpairstr.split('=')
            except ValueError:
                # This happens when extra commas are present, probably
                # from a bad RGB color spec.
                raise InvalidFormatColr(spec, kvpairstr)
            # Handle any aliases that were used.
            k = aliases.get(k, k)
            # Handle RGB values.
            if v.count(';') in (2, 3):
                try:
                    rgb = tuple(int(x) for x in v.split(';'))
                except ValueError:
                    raise InvalidFormatColr(spec, v) from None
                specargs[k] = rgb
            else:
                specargs[k] = v

        try:
            clr = Colr(str(self), **specargs)
        except InvalidColr as ex:
            raise InvalidFormatColr(spec, ex.value) from None
        if normal:
            # Apply non-color-specific format specs from ChainedBase.
            return super(self.__class__, clr).__format__(normal)
        return str(clr)
def __format__ ( self , fmt ) : if not fmt : return str ( self ) if not ( '[' in fmt ) and ( ']' in fmt ) : return super ( ) . __format__ ( fmt ) normal , _ , spec = fmt . partition ( '[' ) spec = spec . rstrip ( ']' ) . strip ( ) . lower ( ) specargs = { } aliases = { 'f' : 'fore' , 'b' : 'back' , 's' : 'style' , } for kvpairstr in spec . split ( ',' ) : kvpairstr = kvpairstr . strip ( ) if not kvpairstr : continue try : k , v = kvpairstr . split ( '=' ) except ValueError : raise InvalidFormatColr ( spec , kvpairstr ) k = aliases . get ( k , k ) if v . count ( ';' ) in ( 2 , 3 ) : try : rgb = tuple ( int ( x ) for x in v . split ( ';' ) ) except ValueError : raise InvalidFormatColr ( spec , v ) from None specargs [ k ] = rgb else : specargs [ k ] = v try : clr = Colr ( str ( self ) , ** specargs ) except InvalidColr as ex : raise InvalidFormatColr ( spec , ex . value ) from None if normal : return super ( self . __class__ , clr ) . __format__ ( normal ) return str ( clr )
Allow format specs to apply to self.data, such as <, >, and ^.
            This adds a few color-specific features to the format_spec,
            not found in the `ChainedBase` class.
            Colr format spec example:
                '{:[fore=COLOR, back=COLOR, style=STYLE]}'
                ..where COLOR is a stringified version of a valid color arg,
                such as a known name, number, hex code, or RGB value (R;G;B).
                RGB values should be separated with a semicolon, like:
                    '{x:[fore=255;255;255]}'.format(x=Colr('test'))
                Also, `f`,`b`, and `s` are accepted for `fore`, `back`,
                and `style`.

            Example:
                'Hello {x:[fore=red, back=white, style=bright]}'.format(
                    x=Colr('Test')
                )
            Note, if any conversion is done on the object beforehand
            (using !s, !a, !r, and friends) this method is never called.
            It only deals with the `format_spec` described in
            `help('FORMATTING')`.