(value)
Parse a color from a value.

    Accepts:
    * rgb() instances
    * hsl() instances
    * '#RGB'
    * '#RGBA'
    * '#RRGGBB'
    * '#RRGGBBAA'
    * 'rgb(0, 0, 0)'
    * 'rgba(0, 0, 0, 0.0)'
    * 'hsl(0, 0%, 0%)'
    * 'hsla(0, 0%, 0%, 0.0)'
    * A named color
Parse a color from a value.
Parse a color from a value .
def color(value):
    """Parse a color from a value.

    Accepts:
    * rgb() instances
    * hsl() instances
    * '#RGB'
    * '#RGBA'
    * '#RRGGBB'
    * '#RRGGBBAA'
    * 'rgb(0, 0, 0)'
    * 'rgba(0, 0, 0, 0.0)'
    * 'hsl(0, 0%, 0%)'
    * 'hsla(0, 0%, 0%, 0.0)'
    * A named color
    """

    if isinstance(value, (rgb, hsl)):
        return value

    elif isinstance(value, str):
        if value[0] == '#':
            return pound_sign_color(value)
        elif value.startswith('rgba'):
            try:
                values = value[5:-1].split(',')
                if len(values) == 4:
                    return rgb(int(values[0]), int(values[1]), int(values[2]), float(values[3]))
            except ValueError:
                pass
        elif value.startswith('rgb'):
            try:
                values = value[4:-1].split(',')
                if len(values) == 3:
                    return rgb(int(values[0]), int(values[1]), int(values[2]))
            except ValueError:
                pass

        elif value.startswith('hsla'):
            try:
                values = value[5:-1].split(',')
                if len(values) == 4:
                    return hsl(
                        int(values[0]),
                        int(values[1].strip().rstrip('%')) / 100.0,
                        int(values[2].strip().rstrip('%')) / 100.0,
                        float(values[3])
                    )
            except ValueError:
                pass

        elif value.startswith('hsl'):
            try:
                values = value[4:-1].split(',')
                if len(values) == 3:
                    return hsl(
                        int(values[0]),
                        int(values[1].strip().rstrip('%')) / 100.0,
                        int(values[2].strip().rstrip('%')) / 100.0,
                    )
            except ValueError:
                pass
        else:
            try:
                return NAMED_COLOR[value.lower()]
            except KeyError:
                pass

    raise ValueError('Unknown color %s' % value)
def color ( value ) : if isinstance ( value , ( rgb , hsl ) ) : return value elif isinstance ( value , str ) : if value [ 0 ] == '#' : return pound_sign_color ( value ) elif value . startswith ( 'rgba' ) : try : values = value [ 5 : - 1 ] . split ( ',' ) if len ( values ) == 4 : return rgb ( int ( values [ 0 ] ) , int ( values [ 1 ] ) , int ( values [ 2 ] ) , float ( values [ 3 ] ) ) except ValueError : pass elif value . startswith ( 'rgb' ) : try : values = value [ 4 : - 1 ] . split ( ',' ) if len ( values ) == 3 : return rgb ( int ( values [ 0 ] ) , int ( values [ 1 ] ) , int ( values [ 2 ] ) ) except ValueError : pass elif value . startswith ( 'hsla' ) : try : values = value [ 5 : - 1 ] . split ( ',' ) if len ( values ) == 4 : return hsl ( int ( values [ 0 ] ) , int ( values [ 1 ] . strip ( ) . rstrip ( '%' ) ) / 100.0 , int ( values [ 2 ] . strip ( ) . rstrip ( '%' ) ) / 100.0 , float ( values [ 3 ] ) ) except ValueError : pass elif value . startswith ( 'hsl' ) : try : values = value [ 4 : - 1 ] . split ( ',' ) if len ( values ) == 3 : return hsl ( int ( values [ 0 ] ) , int ( values [ 1 ] . strip ( ) . rstrip ( '%' ) ) / 100.0 , int ( values [ 2 ] . strip ( ) . rstrip ( '%' ) ) / 100.0 , ) except ValueError : pass else : try : return NAMED_COLOR [ value . lower ( ) ] except KeyError : pass raise ValueError ( 'Unknown color %s' % value )