If color is an rgb tuple return it, if it is a string, parse it
    and return the respective rgb tuple.
481684
def any_to_rgb(color):
    '''

    '''
    if isinstance(color, tuple):
        if len(color) == 3:
            color = color + (255,)
        return color
        
    if isinstance(color, str):
        return parse_color(color)
        
    raise ValueError("Color not recognized: {}".format(color))
123651
def _hex_to_rgb(color):
    
    if color[0] == '#':
        color = color[1:]
    if len(color) == 3:
        color = color[0] * 2 + color[1] * 2 + color[2] * 2
    if len(color) != 6:
        raise ValueError('Input #{0} is not in #RRGGBB format'.format(color))
    return [int(n, 16) for n in (color[:2], color[2:4], color[4:])]
550683
def _get_background_color(self):
        """"""

        color = self.cell_attributes[self.key]["bgcolor"]
        return tuple(c / 255.0 for c in color_pack2rgb(color))
315701
def rgb(self, color_tuple):
        """"""
        # Check bounds
        self.color = tuple(map(self._apply_float_bounds, color_tuple[:3]))

        # Include alpha if necessary
        if len(color_tuple) > 3:
            self.alpha = self._apply_float_bounds(color_tuple[3])
1095910
def parse_colors(s, length=1):
    '''
    '''
    if length and length > 1:
        return parse_ctuple(s,length=length);
    if re.match('^ *{} *$'.format(isrx_s), s):
        #it's just a string.
        return [s];
    elif re.match('^ *{} *$'.format(rgbrx_s), s):
        return [eval(s)];
    else:
        return parse_ctuple(s,length=length);
36459
function _retrieveColor(palette, color, hue = '500', format) {
    if (typeof palette !== 'string' || typeof color !== 'string' || typeof hue !== 'string' || typeof format !== 'string') {
        throw new TypeError('Expected a string');
    }

    let hexColor;
    let result;

    try {
        hexColor = (palette === 'md') ? colors[palette][color][hue].hex : colors[palette][color];

        switch (format) {
            case 'rgb':
                result = _toRGB(hexColor);
                result = `rgb(${result.r}, ${result.g}, ${result.b})`;
                break;
            case 'hex':
                result = `#${hexColor}`;
                break;
            case 'raw':
                result = _toRGB(hexColor);
                result.hex = hexColor;
                break;
            default:
        }
    } catch (err) {
        throw new RangeError('No matching color.');
    }
    return result;
}
229895
def parse(self, color):
        """"""
        assert color is not None

        #parse color into rgb values
        if isinstance(color, str):
            match = self.hex_color_long.match(color)
            if match:
                color = [int(color, 16) / 65535.0 for color in match.groups()]
            else:
                match = self.hex_color_normal.match(color)
                if match:
                    color = [int(color, 16) / 255.0 for color in match.groups()]
                else:
                    match = self.hex_color_short.match(color)
                    color = [int(color + color, 16) / 255.0 for color in match.groups()]

        elif isinstance(color, gdk.Color):
            color = [color.red / 65535.0,
                     color.green / 65535.0,
                     color.blue / 65535.0]

        elif isinstance(color, (list, tuple)):
            # otherwise we assume we have color components in 0..255 range
            if color[0] > 1 or color[1] > 1 or color[2] > 1:
                color = [c / 255.0 for c in color]
        else:
            color = [color.red, color.green, color.blue]


        return color
897364
def normalizeColor(value):
    
    from fontParts.base.color import Color
    if not isinstance(value, (tuple, list, Color)):
        raise TypeError("Colors must be tuple instances, not %s."
                        % type(value).__name__)
    if not len(value) == 4:
        raise ValueError("Colors must contain four values, not %d."
                         % len(value))
    for component, v in zip("rgba", value):
        if not isinstance(v, (int, float)):
            raise TypeError("The value for the %s component (%s) is not "
                            "an int or float." % (component, v))
        if v < 0 or v > 1:
            raise ValueError("The value for the %s component (%s) is not "
                             "between 0 and 1." % (component, v))
    return tuple([float(v) for v in value])
1001623
def as_rgb(self):
        

        html = self.as_html()

        return (
            int(html[1:3], 16),
            int(html[3:5], 16),
            int(html[5:7], 16)
        )
1084377
function ( color, parse ) {
            var type = this.type( color, 'color.toHsl() : "' + color + '" ' + MSG_NOT_COLOR ),
                objColor;
    
            switch ( type ) {
                case 'rgb':
                case 'rgba':
                    objColor = this.rgbToHsl( color, true );
                    break;
                case 'hsl':
                    return parse? this.parseHsla( color ) : color;
                    break;
                case 'hsla':
                    objColor = this.parseHsla( color );
                    break;
                case 'keyword':
                    color = this.keyword( color, 'color.toHsl() : "' + color + '" ' + MSG_NOT_COLOR );
                case 'hex':
                    color = this.hexToRgb( color );
                    objColor = this.rgbToHsl( color, true );
                    break;
            }
    
            return parse? objColor : 'hsl(' + objColor.h + ', ' + objColor.s + '%, ' + objColor.l + '%)';
        }
1061140
def get_rgb_color(color):
    
    if color == INVERTED:
        foreground = (0, 255, 0)
        background = (0, 65, 0)
    elif color == NORMAL:
        foreground = (0, 65, 0)
        background = (0, 255, 0)
    else:
        foreground = (0, 0, 0)
        background = COLOR_INFO[color]
    return (foreground, background)
940582
def HTMLColorToRGB(colorstring):
    
    colorstring = colorstring.strip()
    if colorstring[0] == '#':
        colorstring = colorstring[1:]
    if len(colorstring) != 6:
        raise ValueError(
            "input #{0} is not in #RRGGBB format".format(colorstring))
    r, g, b = colorstring[:2], colorstring[2:4], colorstring[4:]
    r, g, b = [int(n, 16) for n in (r, g, b)]
    return (r, g, b)
920050
def formatcolor(string, fg=None, bg=None):
    
    if fg is bg is None:
        return string

    temp = (['fg='+fg] if fg else []) +\
           (['bg='+bg] if bg else [])
    fmt = _color_format_parser._COLOR_DELIM.join(temp)

    return _color_format_parser._START_TOKEN + fmt +\
        _color_format_parser._FMT_TOKEN + string +\
        _color_format_parser._STOP_TOKEN
218188
def get_color(color = nil) # :nodoc:
    if color.respond_to?(:to_int) && color.respond_to?(:+)
      # the default color if arg is outside range,
      if color < 0 || 63 < color
        0x7FFF
      # or an index < 8 mapped into the correct range,
      elsif color < 8
        (color + 8).to_i
      # or an integer in the valid range
      else
        color.to_i
      end
    elsif color.respond_to?(:to_sym)
      color = color.downcase.to_sym if color.respond_to?(:to_str)
      # or the color string converted to an integer,
      if COLORS.has_key?(color)
        COLORS[color]
      # or the default color if string is unrecognised,
      else
        0x7FFF
      end
    else
      0x7FFF
    end
  end
1100929
def check_color_input(value):
    
    value = value.lower()
    # Trim a leading hash
    if value.startswith('#'):
        value = value[1:]

    if len(value) != 6:
        raise ValueError(
            'Color should be six hexadecimal digits, got %r (%s)' %
            (value, len(value)))

    if re.sub(r'[a-f0-9]', '', value):
        raise ValueError(
            'Color should only contain hex characters, got %r' % value)

    red = int(value[0:2], base=16)
    green = int(value[2:4], base=16)
    blue = int(value[4:6], base=16)
    return RGBColor(red, green, blue)
191076
function parseColor(color, contrast) {
      contrast = contrast || false;
      var rgbValues = $mdTheming.PALETTES[color.palette][color.hue];

      rgbValues = contrast ? rgbValues.contrast : rgbValues.value;

      return $mdUtil.supplant('rgba({0}, {1}, {2}, {3})',
        [rgbValues[0], rgbValues[1], rgbValues[2], rgbValues[3] || color.opacity]
      );
    }
1207784
def code2color(color_string):
    """"""

    color_tuple = ast.literal_eval(color_string)
    color_tuple_int = map(lambda x: int(x * 255.0), color_tuple)

    return wx.Colour(*color_tuple_int)