
xYc           @   s   d  Z  d d l m Z d d l m Z m Z m Z d d l m Z d d l	 m
 Z
 m Z d d l m Z d Z d	   Z e d
  Z d e f d     YZ d S(   s   
Tool for creating styles from a dictionary.

This is very similar to the Pygments style dictionary, with some additions:
- Support for reverse and blink.
- Support for ANSI color names. (These will map directly to the 16 terminal
  colors.)
i(   t   Mappingi   (   t   Stylet   DEFAULT_ATTRSt   ANSI_COLOR_NAMES(   t   DEFAULT_STYLE_EXTENSIONS(   t   merge_attrst   split_token_in_parts(   t   ranget   style_from_dictc         C   s   |  d d !d k r| |  d } | t  k r- | St |  d k rC | St |  d k r | d d | d d | d d Sn |  d k r |  St d |    d	 S(
   s   
    Parse/validate color format.

    Like in Pygments, but also support the ANSI color names.
    (These will map to the colors of the 16 color palette.)
    i    i   t   #i   i   i   t    s   Wrong color format %rN(   R   t   lent
   ValueError(   t   textt   col(    (    s>   lib/python2.7/site-packages/prompt_toolkit/styles/from_dict.pyt   _colorformat   s    
'c   	      C   s  t  |  t  s t  | rD i  } | j t  | j |   | }  n  i  } xbt |  j    D]N\ } } t } d | k r xL t d t	 |  d  D]. } y | | |  } Wn t
 k
 r q XPq Wn  x| j   D]} | d k r q | d k r| j d t  } q | d k r.| j d t  } q | d k rO| j d t  } q | d k rp| j d t  } q | d k r| j d t  } q | d k r| j d t  } q | d	 k r| j d	 t  } q | d
 k r| j d	 t  } q | d k r| j d t  } q | d k r6| j d t  } q | d k rEq | j d  rWq | j d  r| j d t | d   } q | j d t |   } q W| | | <q] Wt |  S(   s  
    Create a ``Style`` instance from a dictionary or other mapping.

    The dictionary is equivalent to the ``Style.styles`` dictionary from
    pygments, with a few additions: it supports 'reverse' and 'blink'.

    Usage::

        style_from_dict({
            Token: '#ff0000 bold underline',
            Token.Title: 'blink',
            Token.SomethingElse: 'reverse',
        })

    :param include_defaults: Include the defaults (built-in) styling for
        selected text, etc...)
    t	   noinheriti   t   boldt   noboldt   italict   noitalict	   underlinet   nounderlinet   blinkt   noblinkt   reverset	   noreverset   romant   sanst   monos   border:s   bg:t   bgcolori   t   color(   R   R   R   (   t
   isinstanceR    t   AssertionErrort   updateR   t   sortedt   itemsR   R   R   t   KeyErrort   splitt   _replacet   Truet   Falset
   startswithR   t   _StyleFromDict(	   t
   style_dictt   include_defaultst   s2t   token_to_attrst   ttypet   styledeft   attrst   it   part(    (    s>   lib/python2.7/site-packages/prompt_toolkit/styles/from_dict.pyR   *   s`    	 R+   c           B   s)   e  Z d  Z d   Z d   Z d   Z RS(   s   
    Turn a dictionary that maps `Token` to `Attrs` into a style class.

    :param token_to_attrs: Dictionary that maps `Token` to `Attrs`.
    c         C   s   | |  _  d  S(   N(   R/   (   t   selfR/   (    (    s>   lib/python2.7/site-packages/prompt_toolkit/styles/from_dict.pyt   __init__   s    c         C   sC   g  } x0 t  |  D]" } | j |  j j | t   q Wt |  S(   N(   R   t   appendR/   t   getR   R   (   R5   t   tokent   list_of_attrs(    (    s>   lib/python2.7/site-packages/prompt_toolkit/styles/from_dict.pyt   get_attrs_for_token   s     c         C   s   t  |  j  S(   N(   t   idR/   (   R5   (    (    s>   lib/python2.7/site-packages/prompt_toolkit/styles/from_dict.pyt   invalidation_hash   s    (   t   __name__t
   __module__t   __doc__R6   R;   R=   (    (    (    s>   lib/python2.7/site-packages/prompt_toolkit/styles/from_dict.pyR+      s   		N(   R   (   R@   t   collectionsR    t   baseR   R   R   t   defaultsR   t   utilsR   R   t	   six.movesR   t   __all__R   R(   R   R+   (    (    (    s>   lib/python2.7/site-packages/prompt_toolkit/styles/from_dict.pyt   <module>   s   	Y