# Path: twyg/css3colors.py
# def color_to_rgba(col):
#     # Convert to string to handle hex colors consisting of decimal
#     # digits only correctly
#     col = str(col).strip()
#     a = 1.0
# 
#     if col in colornames:
#         r, g, b = colornames[col]
#         return r / 255., g / 255., b / 255., a
# 
#     try:
#         r, g, b = _parse_hex(col)
#         return r, g, b, a
#     except ValueError:
#         pass
# 
#     # rgb(r, g, b)
#     m = _re_rgb.match(col)
#     if m:
#         r, g, b =  m.groups()
#         r = _conv_rgb(r)
#         g = _conv_rgb(g)
#         b = _conv_rgb(b)
#         return r, g, b, a
# 
#     # rgb(r%, g%, b%)
#     m = _re_rgb_p.match(col)
#     if m:
#         r, g, b =  m.groups()
#         r = _conv_percent(r)
#         g = _conv_percent(g)
#         b = _conv_percent(b)
#         return r, g, b, a
# 
#     # rgba(r, g, b, a)
#     m = _re_rgba.match(col)
#     if m:
#         r, g, b, a =  m.groups()
#         r = _conv_rgb(r)
#         g = _conv_rgb(g)
#         b = _conv_rgb(b)
#         a = _conv_alpha(a)
#         return r, g, b, a
# 
#     # rgba(r%, g%, b%, a)
#     m = _re_rgba_p.match(col)
#     if m:
#         r, g, b, a =  m.groups()
#         r = _conv_percent(r)
#         g = _conv_percent(g)
#         b = _conv_percent(b)
#         a = _conv_alpha(a)
#         return r, g, b, a
# 
#     # hsl(h, s, l)
#     m = _re_hsl.match(col)
#     if m:
#         h, s, l =  m.groups()
#         h = _conv_hue(h)
#         s = _conv_percent(s)
#         l = _conv_percent(l)
#         r, g, b = colorsys.hls_to_rgb(h, l, s)
#         return r, g, b, a
# 
#     # hsla(h, s, l, a)
#     m = _re_hsla.match(col)
#     if m:
#         h, s, l, a =  m.groups()
#         h = _conv_hue(h)
#         s = _conv_percent(s)
#         l = _conv_percent(l)
#         a = _conv_alpha(a)
#         r, g, b = colorsys.hls_to_rgb(h, l, s)
#         return r, g, b, a
# 
#     raise ValueError, ('Invalid color: %s' % col)
# 
# def rgba_to_color(r, g, b, a, format='rgba'):
#     r = min(max(r, 0), 1)
#     g = min(max(g, 0), 1)
#     b = min(max(b, 0), 1)
#     a = min(max(a, 0), 1)
# 
#     if format == 'hex':
#         return '#%02x%02x%02x' % (r * 255 + .5, g * 255 + .5, b * 255 + .5)
# 
#     if format == 'rgb':
#         return 'rgb(%.0f, %.0f, %.0f)' % (r * 255, g * 255, b * 255)
# 
#     if format == 'rgba':
#         return 'rgba(%.0f, %.0f, %.0f, %.3f)' % (r * 255, g * 255, b * 255, a)
# 
#     if format == 'rgb_p':
#         return 'rgb(%.0f%%, %.0f%%, %.0f%%)' % (r * 100, g * 100, b * 100)
# 
#     if format == 'rgba_p':
#         return ('rgba(%.0f%%, %.0f%%, %.0f%%, %.3f)'
#                 % (r * 100, g * 100, b * 100, a))
# 
#     if format == 'hsl':
#         h, l, s = colorsys.rgb_to_hls(r, g, b)
#         return 'hsl(%.0f, %.0f%%, %.0f%%)' % (h * 360, s * 100, l * 100)
# 
#     if format == 'hsla':
#         h, l, s = colorsys.rgb_to_hls(r, g, b)
#         return ('hsla(%.0f, %.0f%%, %.0f%%, %.3f)'
#                 % (h * 360, s * 100, l * 100, a))
# 
#     raise ValueError, 'Invalid color format: %s' % format


import os, sys, unittest
from twyg.css3colors import color_to_rgba, rgba_to_color



sys.path.append(os.path.join('..'))



class TestCSS3Colors(unittest.TestCase):

    def test_valid(self):
        r, g, b, a = color_to_rgba('aquamarine')

# Path: twyg/css3colors.py
# def color_to_rgba(col):
#     # Convert to string to handle hex colors consisting of decimal
#     # digits only correctly
#     col = str(col).strip()
#     a = 1.0
# 
#     if col in colornames:
#         r, g, b = colornames[col]
#         return r / 255., g / 255., b / 255., a
# 
#     try:
#         r, g, b = _parse_hex(col)
#         return r, g, b, a
#     except ValueError:
#         pass
# 
#     # rgb(r, g, b)
#     m = _re_rgb.match(col)
#     if m:
#         r, g, b =  m.groups()
#         r = _conv_rgb(r)
#         g = _conv_rgb(g)
#         b = _conv_rgb(b)
#         return r, g, b, a
# 
#     # rgb(r%, g%, b%)
#     m = _re_rgb_p.match(col)
#     if m:
#         r, g, b =  m.groups()
#         r = _conv_percent(r)
#         g = _conv_percent(g)
#         b = _conv_percent(b)
#         return r, g, b, a
# 
#     # rgba(r, g, b, a)
#     m = _re_rgba.match(col)
#     if m:
#         r, g, b, a =  m.groups()
#         r = _conv_rgb(r)
#         g = _conv_rgb(g)
#         b = _conv_rgb(b)
#         a = _conv_alpha(a)
#         return r, g, b, a
# 
#     # rgba(r%, g%, b%, a)
#     m = _re_rgba_p.match(col)
#     if m:
#         r, g, b, a =  m.groups()
#         r = _conv_percent(r)
#         g = _conv_percent(g)
#         b = _conv_percent(b)
#         a = _conv_alpha(a)
#         return r, g, b, a
# 
#     # hsl(h, s, l)
#     m = _re_hsl.match(col)
#     if m:
#         h, s, l =  m.groups()
#         h = _conv_hue(h)
#         s = _conv_percent(s)
#         l = _conv_percent(l)
#         r, g, b = colorsys.hls_to_rgb(h, l, s)
#         return r, g, b, a
# 
#     # hsla(h, s, l, a)
#     m = _re_hsla.match(col)
#     if m:
#         h, s, l, a =  m.groups()
#         h = _conv_hue(h)
#         s = _conv_percent(s)
#         l = _conv_percent(l)
#         a = _conv_alpha(a)
#         r, g, b = colorsys.hls_to_rgb(h, l, s)
#         return r, g, b, a
# 
#     raise ValueError, ('Invalid color: %s' % col)
# 
# def rgba_to_color(r, g, b, a, format='rgba'):
#     r = min(max(r, 0), 1)
#     g = min(max(g, 0), 1)
#     b = min(max(b, 0), 1)
#     a = min(max(a, 0), 1)
# 
#     if format == 'hex':
#         return '#%02x%02x%02x' % (r * 255 + .5, g * 255 + .5, b * 255 + .5)
# 
#     if format == 'rgb':
#         return 'rgb(%.0f, %.0f, %.0f)' % (r * 255, g * 255, b * 255)
# 
#     if format == 'rgba':
#         return 'rgba(%.0f, %.0f, %.0f, %.3f)' % (r * 255, g * 255, b * 255, a)
# 
#     if format == 'rgb_p':
#         return 'rgb(%.0f%%, %.0f%%, %.0f%%)' % (r * 100, g * 100, b * 100)
# 
#     if format == 'rgba_p':
#         return ('rgba(%.0f%%, %.0f%%, %.0f%%, %.3f)'
#                 % (r * 100, g * 100, b * 100, a))
# 
#     if format == 'hsl':
#         h, l, s = colorsys.rgb_to_hls(r, g, b)
#         return 'hsl(%.0f, %.0f%%, %.0f%%)' % (h * 360, s * 100, l * 100)
# 
#     if format == 'hsla':
#         h, l, s = colorsys.rgb_to_hls(r, g, b)
#         return ('hsla(%.0f, %.0f%%, %.0f%%, %.3f)'
#                 % (h * 360, s * 100, l * 100, a))
# 
#     raise ValueError, 'Invalid color format: %s' % format


# Path: twyg/tests/css3colors_test.py
import os, sys, unittest
from twyg.css3colors import color_to_rgba, rgba_to_color



sys.path.append(os.path.join('..'))



class TestCSS3Colors(unittest.TestCase):

    def test_valid(self):
        r, g, b, a = color_to_rgba('aquamarine')

        c = rgba_to_color(r, g, b, a, format='rgb')
