???<!-- GIF89;a -->
123123123123
.....................................................................................................................................???<!-- GIF89;a -->
123123123123
.....................................................................................................................................ó
¿œ^c        	   @   s  d  Z  d d l Z d d l Z d d l Td d l Z d e f d „  ƒ  YZ d a d Z	 d Z
 d d3 d	 „  ƒ  YZ d
 e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ e j d ƒ e f e j d ƒ e f e j d ƒ e f e j d ƒ e f e j d ƒ e f g Z d d „ Z i  Z d „  Z i  a d „  Z d5 Z d „  Z d „  Z e d k re d ƒ Z e sœd  GHe j d! ƒ n  d" Z e j e ƒ \ Z Z  Z! Z" e Gd# Ge Ge  Ge! Ge e" ƒ GHe j# e" ƒ \ Z$ Z% d$ Ge$ Gd% Ge
 j& e% ƒ GHd6 \ Z' Z( Z) d7 \ Z' Z( Z) d8 \ Z' Z( Z) d- Ge Gd. GHd d l* Z* e* j* ƒ  Z+ e j, e' e( e) ƒ Z, e* j* ƒ  Z- d/ Ge, Gd0 Ge- e+ Gd1 GHxi e j. ƒ  D]X Z/ e j e/ ƒ \ Z' Z( Z) e j0 e' e( e) ƒ Z% d2 e/ e' e( e) e	 j& e% d! ƒ f GHq¥Wn  d S(9   sG  Color Database.

This file contains one class, called ColorDB, and several utility functions.
The class must be instantiated by the get_colordb() function in this file,
passing it a filename to read a database out of.

The get_colordb() function will try to examine the file to figure out what the
format of the file is.  If it can't figure out the file format, or it has
trouble reading the file, None is returned.  You can pass get_colordb() an
optional filetype argument.

Supporte file types are:

    X_RGB_TXT -- X Consortium rgb.txt format files.  Three columns of numbers
                 from 0 .. 255 separated by whitespace.  Arbitrary trailing
                 columns used as the color name.

The utility functions are useful for converting between the various expected
color formats, and for calculating other color values.

iÿÿÿÿN(   t   *t   BadColorc           B   s   e  Z RS(    (   t   __name__t
   __module__(    (    (    s4   /usr/lib64/python2.7/site-packages/pynche/ColorDB.pyR      s   t    s   , t   ColorDBc           B   sY   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 RS(	   c         C   sA  d } | j  |  _ i  |  _ i  |  _ d  |  _ x| D]} |  j j | ƒ } | s„ t j	 d I| j  Id I| IJ| d 7} q4 n  |  j
 | ƒ \ } } } |  j | ƒ } | j ƒ  }	 | | | f }
 |  j j |
 | g  f ƒ \ } } | | k r| | k r| j | ƒ n  | | f |  j |
 <|
 |  j |	 <| d } q4 Wd  S(   Ni   s   Error ins    linei   (   t   namet   _ColorDB__namet   _ColorDB__byrgbt   _ColorDB__bynamet   Nonet   _ColorDB__allnamest   _ret   matcht   syst   stderrt   _extractrgbt   _extractnamet   lowert   gett   append(   t   selft   fpt   linenot   linet   mot   redt   greent   blueR   t   keynamet   keyt	   foundnamet   aliases(    (    s4   /usr/lib64/python2.7/site-packages/pynche/ColorDB.pyt   __init__'   s*    			"
!c         C   s,   g  | j  d d d ƒ D] } t | ƒ ^ q S(   NR   R   R   (   t   groupt   int(   R   R   t   x(    (    s4   /usr/lib64/python2.7/site-packages/pynche/ColorDB.pyR   M   s    c         C   s   | j  d ƒ S(   NR   (   R"   (   R   R   (    (    s4   /usr/lib64/python2.7/site-packages/pynche/ColorDB.pyR   P   s    c         C   s   |  j  S(   N(   R   (   R   (    (    s4   /usr/lib64/python2.7/site-packages/pynche/ColorDB.pyt   filenameS   s    c         C   s3   y |  j  | SWn t k
 r. t | ƒ ‚ n Xd S(   s   Return name for rgbtupleN(   R   t   KeyErrorR   (   R   t   rgbtuple(    (    s4   /usr/lib64/python2.7/site-packages/pynche/ColorDB.pyt
   find_byrgbV   s    c         C   s?   | j  ƒ  } y |  j | SWn t k
 r: t | ƒ ‚ n Xd S(   s"   Return (red, green, blue) for nameN(   R   R	   R&   R   (   R   R   (    (    s4   /usr/lib64/python2.7/site-packages/pynche/ColorDB.pyt   find_byname]   s
    c         C   s«   d } d } x˜ |  j  j ƒ  D]‡ \ } } |  j | j ƒ  \ } }	 }
 | | } | |	 } | |
 } | | | | | | } | d k s” | | k  r | } | } q q W| S(   s3   Return the name of color nearest (red, green, blue)iÿÿÿÿt    (   R   t   valuesR	   R   (   R   R   R   R   t   nearestt   nearest_nameR   R    t   rt   gt   bt   rdeltat   gdeltat   bdeltat   distance(    (    s4   /usr/lib64/python2.7/site-packages/pynche/ColorDB.pyR,   e   s    


c         C   se   |  j  s^ g  |  _  x- |  j j ƒ  D] \ } } |  j  j | ƒ q" Wd „  } |  j  j | ƒ n  |  j  S(   Nc         S   s   t  |  j ƒ  | j ƒ  ƒ S(   N(   t   cmpR   (   t   n1t   n2(    (    s4   /usr/lib64/python2.7/site-packages/pynche/ColorDB.pyt
   nocase_cmp~   s    (   R   R   R+   R   t   sort(   R   R   R    R8   (    (    s4   /usr/lib64/python2.7/site-packages/pynche/ColorDB.pyt   unique_namesw   s    			c         C   sT   y  |  j  | | | f \ } } Wn& t k
 rH t | | | f ƒ ‚ n X| g | S(   N(   R   R&   R   (   R   R   R   R   R   R    (    (    s4   /usr/lib64/python2.7/site-packages/pynche/ColorDB.pyt
   aliases_ofƒ   s
     (   R   R   R!   R   R   R%   R(   R)   R,   R:   R;   (    (    (    s4   /usr/lib64/python2.7/site-packages/pynche/ColorDB.pyR   &   s   	&							t
   RGBColorDBc           B   s   e  Z e j d  ƒ Z RS(   s?   \s*(?P<red>\d+)\s+(?P<green>\d+)\s+(?P<blue>\d+)\s+(?P<name>.*)(   R   R   t   ret   compileR   (    (    (    s4   /usr/lib64/python2.7/site-packages/pynche/ColorDB.pyR<   ‹   s   t   HTML40DBc           B   s    e  Z e j d  ƒ Z d „  Z RS(   s+   (?P<name>\S+)\s+(?P<hexrgb>#[0-9a-fA-F]{6})c         C   s   t  | j d ƒ ƒ S(   Nt   hexrgb(   t   rrggbb_to_tripletR"   (   R   R   (    (    s4   /usr/lib64/python2.7/site-packages/pynche/ColorDB.pyR   “   s    (   R   R   R=   R>   R   R   (    (    (    s4   /usr/lib64/python2.7/site-packages/pynche/ColorDB.pyR?      s   t   LightlinkDBc           B   s    e  Z e j d  ƒ Z d „  Z RS(   s,   (?P<name>(.+))\s+(?P<hexrgb>#[0-9a-fA-F]{6})c         C   s   | j  d ƒ j ƒ  S(   NR   (   R"   t   strip(   R   R   (    (    s4   /usr/lib64/python2.7/site-packages/pynche/ColorDB.pyR   ™   s    (   R   R   R=   R>   R   R   (    (    (    s4   /usr/lib64/python2.7/site-packages/pynche/ColorDB.pyRB   –   s   t	   WebsafeDBc           B   s)   e  Z e j d  ƒ Z d „  Z d „  Z RS(   s   (?P<hexrgb>#[0-9a-fA-F]{6})c         C   s   t  | j d ƒ ƒ S(   NR@   (   RA   R"   (   R   R   (    (    s4   /usr/lib64/python2.7/site-packages/pynche/ColorDB.pyR   Ÿ   s    c         C   s   | j  d ƒ j ƒ  S(   NR@   (   R"   t   upper(   R   R   (    (    s4   /usr/lib64/python2.7/site-packages/pynche/ColorDB.pyR   ¢   s    (   R   R   R=   R>   R   R   R   (    (    (    s4   /usr/lib64/python2.7/site-packages/pynche/ColorDB.pyRD   œ   s   	t   Xorgt   XConsortiumt   HTMLt	   lightlinkt   Websafec   	      C   s¢   d  } t |  ƒ } zx | j ƒ  } | s+ d  S| d  k r@ t } n	 | g } x1 | D]% \ } } | j | ƒ } | rP PqP qP Wd  S| | ƒ } Wd  | j ƒ  X| a | S(   N(   R
   t   opent   readlinet	   FILETYPESt   searcht   closet
   DEFAULT_DB(	   t   filet   filetypet   colordbR   R   t	   filetypest   typeret   class_R   (    (    s4   /usr/lib64/python2.7/site-packages/pynche/ColorDB.pyt   get_colordb³   s$    		c         C   sœ   t  j |  ƒ } | d k r˜ |  d d k r: t |  ƒ ‚ n  |  d d !} |  d d !} |  d d !} t | d ƒ t | d ƒ t | d ƒ f } | t  |  <n  | S(	   s9   Converts a #rrggbb color to the tuple (red, green, blue).i    t   #i   i   i   i   i   N(   t	   _namedictR   R
   R   R#   (   t   colorR'   R   R   R   (    (    s4   /usr/lib64/python2.7/site-packages/pynche/ColorDB.pyRA   Ó   s    *c         C   s6   t  j |  ƒ } | d k r2 d |  } | t  |  <n  | S(   s/   Converts a (red, green, blue) tuple to #rrggbb.s   #%02x%02x%02xN(   t	   _tripdictR   R
   (   R'   t   hexname(    (    s4   /usr/lib64/python2.7/site-packages/pynche/ColorDB.pyt   triplet_to_rrggbbâ   s
    
g      p@i   c         C   s   t  t j |  t ƒ S(   N(   t   mapt   operatort   __div__t	   _maxtuple(   R'   (    (    s4   /usr/lib64/python2.7/site-packages/pynche/ColorDB.pyt   triplet_to_fractional_rgbí   s    c         C   s6   d } d } d } | |  d | |  d | |  d S(   Ng‰A`åÐ"Ó?gbX9´Èâ?gÉv¾Ÿ/½?i    i   i   (    (   R'   R.   R/   R0   (    (    s4   /usr/lib64/python2.7/site-packages/pynche/ColorDB.pyt   triplet_to_brightnessñ   s    t   __main__s   /usr/openwin/lib/rgb.txts!   No parseable color database foundi   t   navyt   :s   name:s   aliases:i€   i‘   iî   i   iÿ   iû   iú   s   finding nearest tos   ...s   found nearest colort   int   secondss   %20s: (%3d/%3d/%3d) == %s(    (   g      p@(   g      p@g      p@g      p@(   i   i   i€   (   i‘   iî   i   (   iÿ   iû   iú   (1   t   __doc__R   R=   t   typesR_   t	   ExceptionR   R
   RP   t   SPACEt
   COMMASPACER   R<   R?   RB   RD   R>   RM   RW   RY   RA   R[   R]   Ra   Rb   Rc   R   RS   t   exitt   targetR)   R   R   R   R'   R(   R   R    t   joinR.   R/   R0   t   timet   t0R,   t   t1R:   t   nR;   (    (    (    s4   /usr/lib64/python2.7/site-packages/pynche/ColorDB.pyt   <module>   sd   
e		
		
