a
    lc2                     @   sX  d Z ddlZddlZddlZddlmZ ddlmZmZm	Z	m
Z
mZmZ ddlmZ ddlmZmZmZmZmZ ddlmZ g d	Zd
d e D ZeedddZedddddddddd	Zee	e dddZeedddZedZ G dd deZ!e!j"Z#G dd deZ$edZ%e	e edddZ&e	e dd d!d"Z'G d#d deZ(dS )$z-
Tool for creating styles from a dictionary.
    N)Enum)DictHashableListSetTupleTypeVar)SimpleCache   )ANSI_COLOR_NAMESANSI_COLOR_NAMES_ALIASESDEFAULT_ATTRSAttrs	BaseStyle)NAMED_COLORS)Styleparse_colorPrioritymerge_stylesc                 C   s    i | ]\}}|  |d qS )#)lowerlstrip).0kv r   W/var/www/html/django/DPS/env/lib/python3.9/site-packages/prompt_toolkit/styles/style.py
<dictcomp>       r   )textreturnc                 C   s   | t v r| S | tv rt|  S zt|   W S  ty<   Y n0 | dd dkr| dd }|t v rf|S |tv rvt| S t|dkr|S t|dkr|d d |d d  |d d  S n| dv r| S td	|  dS )
z
    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.)
    r   r
   r   N         ) defaultzWrong color format %r)r   r   _named_colors_lowercaser   KeyErrorlen
ValueError)r   colr   r   r   r      s*    &r   	colorbgcolorbold	underlinestrikeitalicblinkreversehidden)	classnamer    c                 C   sF   g }|  d}tdt|d D ] }|d|d|   q |S )z
    Split a single class name at the `.` operator, and build a list of classes.

    E.g. 'a.b.c' becomes ['a', 'a.b', 'a.b.c']
    .r
   N)splitranger(   appendjoinr   )r5   resultpartsir   r   r   _expand_classname\   s
    
r>   )	style_strr    c                 C   s   d| v rt }nt}|  D ]}|dkr*q|dkr@|jdd}q|dkrV|jdd}q|dkrl|jdd}q|d	kr|jdd}q|d
kr|jdd}q|dkr|jdd}q|dkr|jdd}q|dkr|jdd}q|dk r|jdd}q|dkr
|jdd}q|dkr"|jdd}q|dkr:|jdd}q|dkrR|jdd}q|dkrj|jdd}q|dv rvq|drq|dr|drq|dr|jt|dd d }q|d!r|jt|dd d"}q|jt|d"}q|S )#zd
    Take a style string, e.g.  'bg:red #88ff00 class:title'
    and return a `Attrs` instance.
    	noinheritr.   Tr.   noboldFr1   r1   noitalicr/   r/   nounderliner0   r0   Znostriker2   r2   Znoblinkr3   r3   Z	noreverser4   r4   Znohidden)romansansmonozborder:[]zbg:r"   Nr-   zfg:r,   )r   _EMPTY_ATTRSr7   _replace
startswithendswithr   )r?   attrspartr   r   r   _parse_style_strk   s\    






rX   z^[a-z0-9.\s_-]*$c                   @   s   e Zd ZdZdZdZdS )r   a  
    The priority of the rules, when a style is created from a dictionary.

    In a `Style`, rules that are defined later will always override previous
    defined rules, however in a dictionary, the key order was arbitrary before
    Python 3.6. This means that the style could change at random between rules.

    We have two options:

    - `DICT_KEY_ORDER`: This means, iterate through the dictionary, and take
       the key/value pairs in order as they come. This is a good option if you
       have Python >3.6. Rules at the end will override rules at the beginning.
    - `MOST_PRECISE`: keys that are defined with most precision will get higher
      priority. (More precise means: more elements.)
    Z	KEY_ORDERMOST_PRECISEN)__name__
__module____qualname____doc__DICT_KEY_ORDERrY   r   r   r   r   r      s   r   c                   @   s   e Zd ZdZeeeef  ddddZeeeeef  dddZ	e
efeeef ed d	d
dZefeeedddZedddZdS )r   a  
    Create a ``Style`` instance from a list of style rules.

    The `style_rules` is supposed to be a list of ('classnames', 'style') tuples.
    The classnames are a whitespace separated string of class names and the
    style string is just like a Pygments style definition, but with a few
    additions: it supports 'reverse' and 'blink'.

    Later rules always override previous rules.

    Usage::

        Style([
            ('title', '#ff0000 bold underline'),
            ('something-else', 'reverse'),
            ('class1 class2', 'reverse'),
        ])

    The ``from_dict`` classmethod is similar, but takes a dictionary as input.
    N)style_rulesr    c                 C   s^   g }|D ]D\}}t |s&J t|t|  }t|}|||f q|| _|| _	d S N)
CLASS_NAMES_REmatchrepr	frozensetr   r7   rX   r9   _style_rulesclass_names_and_attrs)selfr_   rf   class_namesr?   Zclass_names_setrV   r   r   r   __init__   s    zStyle.__init__r    c                 C   s   | j S r`   )re   rg   r   r   r   r_      s    zStyle.style_rules)
style_dictpriorityr    c                 C   sJ   |t jkr6tttf tddd}| t| |dS | t| S dS )za
        :param style_dict: Style dictionary.
        :param priority: `Priority` value.
        )itemr    c                 S   s   t dd | d  D S )Nc                 s   s   | ]}t |d V  qdS )r6   N)r(   r7   )r   r=   r   r   r   	<genexpr>  r   z/Style.from_dict.<locals>.key.<locals>.<genexpr>r   )sumr7   )rn   r   r   r   key  s    zStyle.from_dict.<locals>.key)rq   N)r   rY   r   strintsorteditemslist)clsrl   rm   rq   r   r   r   	from_dict   s    
zStyle.from_dictr?   r%   r    c              	   C   s  |g}t  }| jD ]\}}|s|| q| D ]}|drg }|dd  dD ]}	|t|	 qZ|D ]}
t  }|t	|
g t
dt|d D ]*}t||D ]}|t	||
f  qq| jD ]\}}||v r|| q||
 qrq2t|}|| q2t|S )z9
        Get `Attrs` for the given style string.
        zclass:r!   N,r
   )setrf   r9   r7   rT   r   extendr>   addrd   r8   r(   	itertoolscombinationsrX   _merge_attrs)rg   r?   r%   list_of_attrsrh   namesattrrW   Znew_class_namespnew_nameZcomboscountc2Zinline_attrsr   r   r   get_attrs_for_style_str
  s.    
zStyle.get_attrs_for_style_strc                 C   s
   t | jS r`   )idrf   rk   r   r   r   invalidation_hash;  s    zStyle.invalidation_hash)rZ   r[   r\   r]   r   r   rr   ri   propertyr_   classmethoddefault_priorityr   r   rx   r   r   r   r   r   r   r   r   r   r      s    1r   _T)r   r    c                 C   s   t t ddd}t|dgdd | D R  |dgdd | D R  |dgd	d | D R  |dgd
d | D R  |dgdd | D R  |dgdd | D R  |dgdd | D R  |dgdd | D R  |dgdd | D R  d	S )z
    Take a list of :class:`.Attrs` instances and merge them into one.
    Every `Attr` in the list can override the styling of the previous one. So,
    the last one has highest priority.
    )valuesr    c                  W   s,   | ddd D ]}|dur|  S qt dS )z/Take first not-None value, starting at the end.N)r)   )r   r   r   r   r   _orI  s    
z_merge_attrs.<locals>._orr$   c                 S   s   g | ]
}|j qS r   rQ   r   ar   r   r   
<listcomp>Q  r   z _merge_attrs.<locals>.<listcomp>c                 S   s   g | ]
}|j qS r   rP   r   r   r   r   r   R  r   Fc                 S   s   g | ]
}|j qS r   rA   r   r   r   r   r   S  r   c                 S   s   g | ]
}|j qS r   rE   r   r   r   r   r   T  r   c                 S   s   g | ]
}|j qS r   rG   r   r   r   r   r   U  r   c                 S   s   g | ]
}|j qS r   rC   r   r   r   r   r   V  r   c                 S   s   g | ]
}|j qS r   rH   r   r   r   r   r   W  r   c                 S   s   g | ]
}|j qS r   rI   r   r   r   r   r   X  r   c                 S   s   g | ]
}|j qS r   rJ   r   r   r   r   r   Y  r   r+   )r   r   )r   r   r   r   r   r   B  s    r   _MergedStylestylesr    c                 C   s   dd | D } t | S )z)
    Merge multiple `Style` objects.
    c                 S   s   g | ]}|d ur|qS r`   r   r   sr   r   r   r   a  r   z merge_styles.<locals>.<listcomp>)r   )r   r   r   r   r   ]  s    r   c                   @   sx   e Zd ZdZee ddddZeedddZ	eee
eef  dd	d
ZefeeedddZedddZdS )r   z
    Merge multiple `Style` objects into one.
    This is supposed to ensure consistency: if any of the given styles changes,
    then this style will be updated.
    Nr   c                 C   s   || _ tdd| _d S )Nr
   )maxsize)r   r	   _style)rg   r   r   r   r   ri   u  s    z_MergedStyle.__init__rj   c                    s$   t d fdd} j  |S )z=The `Style` object that has the other styles merged together.rj   c                      s
   t  jS r`   )r   r_   r   rk   r   r   get}  s    z'_MergedStyle._merged_style.<locals>.get)r   r   r   r   )rg   r   r   rk   r   _merged_styley  s    z_MergedStyle._merged_stylec                 C   s    g }| j D ]}||j q
|S r`   )r   r|   r_   )rg   r_   r   r   r   r   r_     s    
z_MergedStyle.style_rulesry   c                 C   s   | j ||S r`   )r   r   )rg   r?   r%   r   r   r   r     s    z$_MergedStyle.get_attrs_for_style_strc                 C   s   t dd | jD S )Nc                 s   s   | ]}|  V  qd S r`   )r   r   r   r   r   ro     r   z1_MergedStyle.invalidation_hash.<locals>.<genexpr>)tupler   rk   r   r   r   r     s    z_MergedStyle.invalidation_hash)rZ   r[   r\   r]   r   r   ri   r   r   r   r   rr   r_   r   r   r   r   r   r   r   r   r   r   e  s   ))r]   r~   resysenumr   typingr   r   r   r   r   r   Zprompt_toolkit.cacher	   baser   r   r   r   r   Znamed_colorsr   __all__ru   r&   rr   r   rR   r>   rX   compilera   r   r^   r   r   r   r   r   r   r   r   r   r   <module>   s@    0D
s