HEX
Server: LiteSpeed
System: Linux s1049.use1.mysecurecloudhost.com 4.18.0-477.27.2.lve.el8.x86_64 #1 SMP Wed Oct 11 12:32:56 UTC 2023 x86_64
User: xedaptot (3356)
PHP: 8.3.31
Disabled: NONE
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/rich/__pycache__/style.cpython-310.pyc
o

;j�i�@sddlZddlmZddlmZddlmZddlmZm	Z	ddl
mZddlm
Z
mZmZmZmZmZmZmZdd	lmZdd
lmZmZmZmZddlmZmZddlm Z m!Z!ed
ddddd�Z"ee#dfZ$eed��Z%Gdd�d�Z&eGdd�d��Z'e'�Z(Gdd�d�Z)dS)�N)�	lru_cache)�count)�
attrgetter)�dumps�loads)�getrandbits)�Any�Dict�Iterable�List�Optional�Type�Union�cast�)�errors)�Color�ColorParseError�ColorSystem�	blend_rgb)�Result�	rich_repr)�DEFAULT_TERMINAL_THEME�
TerminalTheme�_color�_bgcolor�_attributes�_set_attributes�_link�_meta�Style�c@sFeZdZdZdgZdeddfdd�Zdd	d
ed	dee	fdd�Z
dS)
�_Bitz.A descriptor to get/set a style attribute bit.�bit�bit_no�returnNcCsd|>|_dS)Nr)r#)�selfr$�r'�>/opt/saltstack/salt/lib/python3.10/site-packages/rich/style.py�__init__�z
_Bit.__init__�objr �objtypecCs |j|j@r|j|j@dkSdS)Nr)rr#r)r&r+r,r'r'r(�__get__!sz_Bit.__get__)�__name__�
__module__�__qualname__�__doc__�	__slots__�intr)r
r�boolr-r'r'r'r(r"s
"r"c&@seZdZUdZeeed<eeed<eed<eed<eeed<eed<ee	ed<gd	�Z
d
ddd
dddddddddd�
Zidd�dd�dd�dd�dd�dd�dd�dd�d d �d!d!�d"d"�d#d"�d$d$�d%d$�d&d&�d'd&�d(d(�d(d)d*d+d+d,��Zd-d-d-d-d-d-d-d-d-d-d-d-d-d-d-d-d-d.�d/ee
eefd0ee
eefdeedeedeedeed eed!eed"eed$eed&eed(eed)eed*eed+eed1eed2eeeeff"d3d4�Zed�d6d7��Ze	-d�d/eed0eed5dfd8d9��Zed2eeeefd5dfd:d;��Zed�d2eeeefd<ed5dfd=d>��Zed?�Zed@�ZedA�ZedB�ZedC�ZedD�ZedE�ZedF�ZedG�Z edH�Z!edI�Z"edJ�Z#edK�Z$e%d5efdLdM��Z&d5efdNdO�Z'd5efdPdQ�Z(dRe)d5efdSdT�Z*ee+dUdV�dWed5efdXdY���Z,edZee-d5e-fd[d\��Z.d5e/fd]d^�Z0d_ed5efd`da�Z1d_ed5efdbdc�Z2d5efddde�Z3e%d5eefdfdg��Z4e%d5eefdhdi��Z5e%d5eefdjdk��Z6e%d5efdldm��Z7e%d�dndo��Z8e%d5eeeffdpdq��Z9e%d�drds��Z:ee+dtdV�dued5dfdvdw���Z;e+dUdV�d�dxee<d5efdydz��Z=ed{e>dd5dfd|d}��Z?ed�d~d��Z@d�d�d��ZAe+d�dV�d�d�d���ZBd�d1eed5dfd�d��ZC	�d�e)jDd�d��d�edRee)d�ed5efd�d��ZEd�d�eed5d-fd�d��ZFe+dUdV�dWedd5dfd�d���ZGdWedd5dfd�d��ZHd-S)�r a�A terminal style.

    A terminal style consists of a color (`color`), a background color (`bgcolor`), and a number of attributes, such
    as bold, italic etc. The attributes have 3 states: they can either be on
    (``True``), off (``False``), or not set (``None``).

    Args:
        color (Union[Color, str], optional): Color of terminal text. Defaults to None.
        bgcolor (Union[Color, str], optional): Color of terminal background. Defaults to None.
        bold (bool, optional): Enable bold text. Defaults to None.
        dim (bool, optional): Enable dim text. Defaults to None.
        italic (bool, optional): Enable italic text. Defaults to None.
        underline (bool, optional): Enable underlined text. Defaults to None.
        blink (bool, optional): Enabled blinking text. Defaults to None.
        blink2 (bool, optional): Enable fast blinking text. Defaults to None.
        reverse (bool, optional): Enabled reverse text. Defaults to None.
        conceal (bool, optional): Enable concealed text. Defaults to None.
        strike (bool, optional): Enable strikethrough text. Defaults to None.
        underline2 (bool, optional): Enable doubly underlined text. Defaults to None.
        frame (bool, optional): Enable framed text. Defaults to None.
        encircle (bool, optional): Enable encircled text. Defaults to None.
        overline (bool, optional): Enable overlined text. Defaults to None.
        link (str, link): Link URL. Defaults to None.

    rrrr�_hash�_nullr)rrrrr�_link_id�_ansi�_style_definitionr5r6r�1�2�3�4�5�6�7�8�9Z21Z51Z52Z53)
rr��������	�
���dim�d�bold�b�italic�i�	underline�u�blink�blink2�reverse�r�conceal�c�strike�s�
underline2�frame�encircle�overline)�uur_r`ra�oN)�color�bgcolorrPrNrRrTrVrWrXrZr\r^r_r`ra�link�metardrerfrgcCs�d|_d|_dtttfdtfdd�}|durdn||�|_|dur$dn||�|_t|du|duo2d|duo7d|duo<d|duoAd|duoFd	|	duoKd
|
duoPd|duoUd|duoZd
|
duo_d|duodd|duoidf
�|_|jr�t|rudpvd|rzdp{d|rdp�d|r�dp�d|r�dp�d|r�d	p�d|	r�d
p�d|
r�dp�d|r�dp�d|r�d
p�d|
r�dp�d|r�dp�d|r�dp�df
�nd|_	||_
|dur�dnt|�|_|s�|r�t
t��t|j���nd|_d|_|jp�|p�|p�|p�||_dS)Nrdr%cSst|t�r|St�|�S�N)�
isinstancer�parse)rdr'r'r(�_make_color�sz#Style.__init__.<locals>._make_colorrCrErI�� �@������rr�)r8r9rr�strrr�sumrrrrr�next�
_id_generator�hashr7r5r6)r&rdrerPrNrRrTrVrWrXrZr\r^r_r`rarfrgrkr'r'r(r)�s\











��#�












��� �zStyle.__init__r%cCstS)zCCreate an 'null' style, equivalent to Style(), but more performant.)�
NULL_STYLE)�clsr'r'r(�null�sz
Style.nullcCsV|�t�}d|_d|_||_||_d|_d|_d|_d|_	d|_
|p#||_d|_|S)aCreate a new style with colors and no attributes.

        Returns:
            color (Optional[Color]): A (foreground) color, or None for no color. Defaults to None.
            bgcolor (Optional[Color]): A (background) color, or None for no color. Defaults to None.
        Nrru)
�__new__r r8r9rrrrrr7rr6r5)r|rdre�styler'r'r(�
from_color�s

zStyle.from_colorcCsh|�t�}d|_d|_d|_d|_d|_d|_d|_t	|�|_
tt��t
|j
���|_d|_||_|S)z�Create a new style with meta data.

        Returns:
            meta (Optional[Dict[str, Any]]): A dictionary of meta data. Defaults to None.
        Nr)r~r r8r9rrrrrrrrxryrzr7r5r6)r|rgrr'r'r(�	from_meta�s

zStyle.from_meta�handlerscKs2|durin|}|�dd�|��D��|�|�S)a�Create a blank style with meta information.

        Example:
            style = Style.on(click=self.on_click)

        Args:
            meta (Optional[Dict[str, Any]], optional): An optional dict of meta information.
            **handlers (Any): Keyword arguments are translated in to handlers.

        Returns:
            Style: A Style with meta information attached.
        NcSsi|]
\}}d|��|�qS)�@r')�.0�key�valuer'r'r(�
<dictcomp>szStyle.on.<locals>.<dictcomp>)�update�itemsr�)r|rgr�r'r'r(�ons
zStyle.onrrrCrDrErFrGrHrIrJrKrLrMcC�|jS)z+Get a link id, used in ansi code for links.)r7�r&r'r'r(�link_id!�z
Style.link_idcCs�|jdur�g}|j}|j}|d@rE|d@r||jrdnd�|d@r+||jr(dnd�|d	@r8||jr5d
nd�|d@rE||jrBd
nd�|d@r�|d@rV||jrSdnd�|d@rc||jr`dnd�|d@rp||j	rmdnd�|d@r}||j
rzdnd�|d@r�||jr�dnd�|d@r�|d @r�||jr�d!nd"�|d#@r�||j
r�d$nd%�|d&@r�||jr�d'nd(�|d)@r�||jr�d*nd+�|jdur�||jj�|jdur�|d,�||jj�|jr�|d-�||j�d.�|�p�d/|_|jS)0z-Re-generate style definition from attributes.N�rrPznot boldrCrNznot dimrErRz
not italicrIrTz
not underline��rlrVz	not blinkrmrWz
not blink2rnrXznot reverserorZznot concealrpr\z
not strike�rqr^znot underline2rrr_z	not framersr`znot encirclertraznot overliner�rf� �none)r9�appendrrPrNrRrTrVrWrXrZr\r^r_r`rar�namerr�join)r&�
attributesr��bitsr'r'r(�__str__&sV



z
Style.__str__cCs|jS)z;A Style is false if it has no attributes, colors, or links.)r6r�r'r'r(�__bool__TszStyle.__bool__�color_systemcCs0|jdur�g}|j}|j}|j|j@}|rm|d@r||d�|d@r)||d�|d@r3||d�|d@r=||d�|d@rUtdd	�D]}|d|>@rT|||�qF|d
@rmtd	d�D]}|d|>@rl|||�q^|jdur}|�|j�|��	��|j
dur�|�|j
�|�j	dd
��d�|�|_|jS)z�Generate ANSI codes for this style.

        Args:
            color_system (ColorSystem): Color system.

        Returns:
            str: String containing codes.
        NrrrCrErIrDr�rJr��
F�Z
foreground�;)r8r��
_style_maprr�ranger�extendZ	downgradeZget_ansi_codesrr�)r&r�Zsgrr�r�r�r#r'r'r(�_make_ansi_codesXsD

��

��zStyle._make_ansi_codesrr)�maxsizercCs2zt|�|��WStjy|����YSw)z�Normalize a style definition so that styles with the same effect have the same string
        representation.

        Args:
            style (str): A style definition.

        Returns:
            str: Normal form of style definition.
        )rvrjr�StyleSyntaxError�strip�lower)r|rr'r'r(�	normalize�s
�zStyle.normalize�valuescGs"|D]
}|dur|Sqtd��)zPick first non-None style.Nz$expected at least one non-None style)�
ValueError)r|r�r�r'r'r(�
pick_first�s
�zStyle.pick_firstccs��d|jdfVd|jdfVd|jdfVd|jdfVd|jdfVd|jdfVd|jdfVd|jdfVd	|jdfVd
|j	dfVd|j
dfVd|jdfVd
|jdfVd|j
dfVd|jdfV|jrud|jfVdSdS)NrdrerPrNrRrTrVrWrXrZr\r^r_r`rfrg)rdrerPrNrRrTrVrWrXrZr\r^r_r`rfrrgr�r'r'r(�
__rich_repr__�s&��zStyle.__rich_repr__�othercCst|t�stS|��|��kSrh�rir �NotImplemented�__hash__�r&r�r'r'r(�__eq__��
zStyle.__eq__cCst|t�stS|��|��kSrhr�r�r'r'r(�__ne__�r�zStyle.__ne__cCs$|jdur|jStt|��|_|jSrh)r5rz�_hash_getterr�r'r'r(r��s
zStyle.__hash__cCr�)z.The foreground color or None if it is not set.)rr�r'r'r(rd�r�zStyle.colorcCr�)z.The background color or None if it is not set.)rr�r'r'r(re�r�z
Style.bgcolorcCr�)zLink text, if set.)rr�r'r'r(rf�r�z
Style.linkcCs|jdup|jjS)z6Check if the style specified a transparent background.N)reZ
is_defaultr�r'r'r(�transparent_background�szStyle.transparent_backgroundcCst|jd�S)zA Style with background only.)re)r rer�r'r'r(�background_style�szStyle.background_stylecCs&|jduriSttttft|j��S)z=Get meta information (can not be changed after construction).N)rrr	rvrrr�r'r'r(rg�s&z
Style.metacCsp|jrtS|�t�}d|_d|_d|_d|_|j|_|j	|_	|j
|_
|j
r*tt��nd|_
d|_d|_d|_|S)z+Get a copy of the style with color removed.NruF)r6r{r~r r8r9rrrrrrxryr7rr5�r&rr'r'r(�
without_color�s
zStyle.without_colorrt�style_definitionc
Cs�|��dks|s|��S|j}d}d}i}d}t|���}|D]�}|��}	|	dkrXt|d�}	|	s5t�d��zt	�
|	�WntyT}
zt�d|	�d|
���d�d}
~
ww|	}q|	dkrwt|d�}	|�|	�}|durrt�d	|	����d
||<q|	dkr�t|d�}	|	s�t�d��|	}q|	|vr�d
|||	<qzt	�
|	�Wnty�}
zt�d|	�d|
���d�d}
~
ww|	}qt
d|||d�|��}|S)aParse a style definition.

        Args:
            style_definition (str): A string containing a style.

        Raises:
            errors.StyleSyntaxError: If the style definition syntax is invalid.

        Returns:
            `Style`: A Style instance.
        r�Nr�ruzcolor expected after 'on'zunable to parse z as background color; �notz,expected style attribute after 'not', found FrfzURL expected after 'link'Tz as color; )rdrerfr')r�r}�STYLE_ATTRIBUTES�iter�splitr�rxrr�rrjr�getr )
r|r�r�rdrer�rf�wordsZ
original_word�word�errorZ	attributerr'r'r(rj�sj

����

�


����zStyle.parse�themecCs|pt}g}|j}|j}|j}|jr||}}|jr0|dur!|jn|�|�}t�	t
||jd��}|durI|�|�}|d|j���|d|j���|dur\|j|dd�}|d|j���|j
rc|d�|jrj|d	�|jrq|d
�|jrx|d�|jr|d�d
�|�S)zGet a CSS style rule.Ng�?zcolor: ztext-decoration-color: Fr�zbackground-color: zfont-weight: boldzfont-style: italicztext-decoration: underlineztext-decoration: line-throughztext-decoration: overlinez; )rr�rdrerXrN�foreground_colorZ
get_truecolorrZfrom_tripletrZbackground_color�hexrPrRrTr\rar�)r&r��cssr�rdrer�Ztheme_colorr'r'r(�get_html_style3s>
��

zStyle.get_html_style�stylescC�t|�}t|t|��S)z�Combine styles and get result.

        Args:
            styles (Iterable[Style]): Styles to combine.

        Returns:
            Style: A new style instance.
        �r�rwrx�r|r�Ziter_stylesr'r'r(�combineX�
z
Style.combinecGr�)z�Combine styles from positional argument in to a single style.

        Args:
            *styles (Iterable[Style]): Styles to combine.

        Returns:
            Style: A new style instance.
        r�r�r'r'r(�chainer�zStyle.chaincCs||jrtS|�t�}|j|_|j|_|j|_|j|_|j|_|j	|_	|j
|_
|j
r.tt��nd|_
|j|_d|_|j|_|S)zwGet a copy of this style.

        Returns:
            Style: A new Style instance with identical attributes.
        ruF)r6r{r~r r8r9rrrrrrxryr7r5rr�r'r'r(�copyrs
z
Style.copyrocCsf|jrtS|�t�}|j|_|j|_|j|_|j|_|j|_|j	|_	d|_
d|_d|_d|_d|_
|S)z�Get a copy of this style with link and meta information removed.

        Returns:
            Style: New style object.
        NruF)r6r{r~r r8r9rrrrrr7r5rr�r'r'r(�clear_meta_and_links�s
zStyle.clear_meta_and_linkscCsl|�t�}|j|_|j|_|j|_|j|_|j|_|j|_||_|r't	t
��nd|_d|_d|_
|j|_|S)z�Get a copy with a different value for link.

        Args:
            link (str, optional): New value for link. Defaults to None.

        Returns:
            Style: A new Style instance.
        ruNF)r~r r8r9rrrrrrxryr7r5r6r)r&rfrr'r'r(�update_link�s
	zStyle.update_linkruF)r��legacy_windows�textr�cCsd|r|dur|S|jp|�|�}|rd|�d|�d�n|}|jr0|s0d|j�d|j�d|�d�}|S)	aDRender the ANSI codes for the style.

        Args:
            text (str, optional): A string to style. Defaults to "".
            color_system (Optional[ColorSystem], optional): Color system to render to. Defaults to ColorSystem.TRUECOLOR.

        Returns:
            str: A string containing ANSI style codes.
        Nz[�mzz]8;id=r�z\z]8;;\)r8r�rr7)r&r�r�r��attrsZrenderedr'r'r(�render�s
�zStyle.rendercCs(|pt|�}tj�|�|��d��dS)z�Write text with style directly to terminal.

        This method is for testing purposes only.

        Args:
            text (Optional[str], optional): Text to style or None for style name.

        �
N)rv�sys�stdout�writer�)r&r�r'r'r(�test�s	z
Style.testcCs�|dus|jr	|S|jr|S|�t�}d|_d|_|jp|j|_|jp%|j|_|j|j@|j|j@B|_|j|jB|_|j	pA|j	|_	|j
pH|j
|_
|j|_|jr`|jr`ti|j
�|j
��|_n|jpe|j|_d|_|Srh)r6r~r r8r9rrrrrr7rrrgr5)r&rZ	new_styler'r'r(�_add�s*

�z
Style._addcCs|�|�}|jr|��S|Srh)r�rfr�)r&rZcombined_styler'r'r(�__add__�s
z
Style.__add__)r%r )NNrh)r�r r%r )ru)Ir.r/r0r1rr�__annotations__r3r4�bytesr2r�r�rrvr	rr)�classmethodr}r�r�r�r"rPrNrRrTrVrWrXrZr\r^r_r`ra�propertyr�r�r�rr�rr��	StyleTyper�rr�r�r�r�rdrerfr�r�rgr�rjrr�r
r�r�r�r�r�Z	TRUECOLORr�r�r�r�r'r'r'r(r 's�
���������	�
���
�������������	�
���
������
�L���� &.+A$
�����
�c@s`eZdZdZdgZddd�Zdefd	d
�Zede	fdd��Z
d
e	ddfdd�Zde	fdd�ZdS)�
StyleStackzA stack of styles.�_stack�
default_styler r%NcCs|g|_dSrh�r�)r&r�r'r'r(r)szStyleStack.__init__cCsd|j�d�S)Nz<stylestack �>r�r�r'r'r(�__repr__r*zStyleStack.__repr__cCs
|jdS)z&Get the Style at the top of the stack.���r�r�r'r'r(�currents
zStyleStack.currentrcCs|j�|jd|�dS)z}Push a new style on to the stack.

        Args:
            style (Style): New style to combine with current style.
        r�N)r�r�r�r'r'r(�push
szStyleStack.pushcCs|j��|jdS)z}Pop last style and discard.

        Returns:
            Style: New current style (also available as stack.current)
        r�)r��popr�r'r'r(r�s

zStyleStack.pop)r�r r%N)
r.r/r0r1r2r)rvr�r�r r�r�r�r'r'r'r(r��s
r�)*r��	functoolsr�	itertoolsr�operatorr�picklerr�randomr�typingrr	r
rrr
rrrurrdrrrr�reprrrZterminal_themerrr�rvr�ryr"r r{r�r'r'r'r(�<module>s4(�W