#NEWLINE# def parse_color( token ) : #NEWLINE# #INDENT# "Parse single token as a color value.\n\n    :param token:\n        A single :class:`~.token_data.Token` or\n        :class:`~.token_data.ContainerToken`, as found eg. in a\n        property value.\n    :returns:\n        * ``None``, if the token is not a valid CSS 3 color value.\n          (No exception is raised.)\n        * For the *currentColor* keyword: the string ``'currentColor'``\n        * Every other values (including keywords, HSL and HSLA) is converted\n          to RGBA and returned as an :class:`RGBA` object (a 4-tuple with\n          attribute access).\n          The alpha channel is clipped to [0, 1], but R, G, or B can be\n          out of range (eg. ``rgb(-51, 306, 0)`` is represented as\n          ``(-.2, 1.2, 0, 1)``.)\n\n    " #NEWLINE# if ( token . type == 'IDENT' ) : #NEWLINE# #INDENT# return COLOR_KEYWORDS . get ( token . value . lower ( ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( token . type == 'HASH' ) : #NEWLINE# #INDENT# for ( multiplier , regexp ) in HASH_REGEXPS : #NEWLINE# #INDENT# match = regexp ( token . value ) #NEWLINE# if match : #NEWLINE# #INDENT# ( r , g , b ) = [ ( int ( ( group * multiplier ) , 16 ) / 255 ) for group in match . groups ( ) ] #NEWLINE# return RGBA ( r , g , b , 1.0 ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( token . type == 'FUNCTION' ) : #NEWLINE# #INDENT# args = parse_comma_separated ( token . content ) #NEWLINE# if multiplier : #NEWLINE# #INDENT# name = token . function_name . lower ( ) #NEWLINE# if ( name == 'rgb' ) : #NEWLINE# #INDENT# return parse_rgb ( args , alpha = 1.0 ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( name == 'rgba' ) : #NEWLINE# #INDENT# alpha = parse_alpha ( args [ 3 : ] ) #NEWLINE# if ( alpha is not None ) : #NEWLINE# #INDENT# return parse_rgb ( args [ : 3 ] , alpha ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( name == 'hsl' ) : #NEWLINE# #INDENT# return parse_hsl ( args , alpha = 1.0 ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( name == 'hsla' ) : #NEWLINE# #INDENT# alpha = parse_alpha ( args [ 3 : ] ) #NEWLINE# if ( alpha is not None ) : #NEWLINE# #INDENT# return parse_hsl ( args [ : 3 ] , alpha )