HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //proc/1233/root/usr/lib/python3/dist-packages/pip/_vendor/rich/__pycache__/style.cpython-310.pyc
o

@%Neeg�@s�ddlZddlmZddlmZmZddlmZddlm	Z	m
Z
mZmZm
Z
mZmZmZddlmZddlmZmZmZmZdd	lmZmZdd
lmZmZeedfZGdd
�d
�Z eGdd�d��Z!e!�Z"Gdd�d�Z#dS)�N)�	lru_cache)�loads�dumps)�randint)�Any�cast�Dict�Iterable�List�Optional�Type�Union�)�errors)�Color�ColorParseError�ColorSystem�	blend_rgb)�	rich_repr�Result)�DEFAULT_TERMINAL_THEME�
TerminalTheme�Stylec@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�8/usr/lib/python3/dist-packages/pip/_vendor/rich/style.py�__init__�z
_Bit.__init__�objr�objtypecCs |j|j@r|j|j@dkSdS)Nr)�_set_attributesr�_attributes)rr"r#rrr�__get__sz_Bit.__get__)�__name__�
__module__�__qualname__�__doc__�	__slots__�intr rr�boolr&rrrrrs
"rc&@s�eZdZUdZeeed<eeed<eed<eed<eed<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�Z1d5efdbdc�Z2e%d5eefddde��Z3e%d5eefdfdg��Z4e%d5eefdhdi��Z5e%d5efdjdk��Z6e%d�dldm��Z7e%d5eeeffdndo��Z8e%d�dpdq��Z9ee+drdV�dsed5dfdtdu���Z:e+dUdV�d�dvee;d5efdwdx��Z<edye=dd5dfdzd{��Z>ed�d|d}��Z?d�d~d�Z@d�d1eed5dfd�d��ZA	�d�e)jBd�d��d�edRee)d�ed5efd�d��ZCd�d�eed5d-fd�d��ZDdWedd5dfd�d��ZEd-S)�ra�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.

    �_color�_bgcolorr%r$�_hash�_null�_meta)r.r/r%r$�_link�_link_id�_ansi�_style_definitionr0r1r2�1�2�3�4�5�6�7�8�9�21�51�52�53)
rr��������	�
���dim�d�bold�b�italic�i�	underline�u�blink�blink2�reverse�r�conceal�c�strike�s�
underline2�frame�encircle�overline)�uur`rarb�oN)�color�bgcolorrQrOrSrUrWrXrYr[r]r_r`rarb�link�metarerfrgrhcCs�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|_	||_
|r�tdd��nd|_|dur�dnt
|�|_t|j|j|j	|j||jf�|_|jp�|p�|p�|p�||_dS)NrercSst|t�r|St�|�S�N)�
isinstancer�parse)rerrr�_make_color�sz#Style.__init__.<locals>._make_colorrDrFrJ�� �@������rr�?B�)r5r6r
r�strr.r/�sumr$r%r3rr4rr2�hashr0r1)rrerfrQrOrSrUrWrXrYr[r]r_r`rarbrgrhrlrrrr {sj











��#�












�����
zStyle.__init__rcCstS)zCCreate an 'null' style, equivalent to Style(), but more performant.)�
NULL_STYLE)�clsrrr�null�sz
Style.nullcCsf|�t�}d|_d|_||_||_d|_d|_d|_d|_	d|_
t||ddddf�|_|p.||_
|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.
        Nrrw)�__new__rr5r6r.r/r$r%r3r4r2rzr0r1)r|rerf�stylerrr�
from_color�s*

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

        Returns:
            meta (Optional[Dict[str, Any]]): A dictionary of meta data. Defaults to None.
        Nrrw)r~rr5r6r.r/r$r%r3r4rr2rzr0r1)r|rhrrrr�	from_meta�s*

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

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

        Args:
            meta (Optiona[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�valuerrr�
<dictcomp>!szStyle.on.<locals>.<dictcomp>)�update�itemsr�)r|rhr�rrr�ons
zStyle.onrrrDrErFrGrHrIrJrKrLrMrNcC�|jS)z+Get a link id, used in ansi code for links.)r4�rrrr�link_id2�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�rrQznot boldrDrOznot dimrFrSz
not italicrJrUz
not underline��rmrWz	not blinkrnrXz
not blink2rorYznot reverserpr[znot concealrqr]z
not strike�rrr_znot underline2rsr`z	not framertraznot encirclerurbznot overliner�rg� �none)r6�appendr$rQrOrSrUrWrXrYr[r]r_r`rarbr.�namer/r3�join)r�
attributesr��bitsrrr�__str__7sV



z
Style.__str__cCs|jS)z;A Style is false if it has no attributes, colors, or links.)r1r�rrr�__bool__eszStyle.__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.
        NrrrDrFrJrEr�rKr��
F��
foreground�;)r5r��
_style_mapr%r$�ranger.�extend�	downgrade�get_ansi_codesr/r�)rr��sgrr�r�r�rrrr�_make_ansi_codesisD
	��

��zStyle._make_ansi_codesrs)�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.
        )rxrkr�StyleSyntaxError�strip�lower)r|rrrr�	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�rrr�
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)NrerfrQrOrSrUrWrXrYr[r]r_r`rargrh)rerfrQrOrSrUrWrXrYr[r]r_r`rargr2rhr�rrr�
__rich_repr__�s&��zStyle.__rich_repr__�othercCsVt|t�stS|j|jko*|j|jko*|j|jko*|j|jko*|j|jko*|j|jkSri)	rjr�NotImplementedr.r/r$r%r3r2)rr�rrr�__eq__�s

�
�
�
�
�zStyle.__eq__cCr�ri)r0r�rrr�__hash__�szStyle.__hash__cCr�)z.The foreground color or None if it is not set.)r.r�rrrre�r�zStyle.colorcCr�)z.The background color or None if it is not set.)r/r�rrrrf�r�z
Style.bgcolorcCr�)zLink text, if set.)r3r�rrrrg�r�z
Style.linkcCs|jdup|jjS)z6Check if the style specified a transparent background.N)rf�
is_defaultr�rrr�transparent_background�szStyle.transparent_backgroundcCst|jd�S)zA Style with background only.)rf)rrfr�rrr�background_style�szStyle.background_stylecCs&|jduriSttttft|j��S)z=Get meta information (can not be changed after construction).N)r2rrrxrrr�rrrrh�s&z
Style.metacCst|jrtS|�t�}d|_d|_d|_d|_|j|_|j	|_	|j
|_
|j
r+tdd��nd|_|j
|_
d|_d|_|S)z+Get a copy of the style with color removed.NrrvrwF�r1r{r~rr5r6r.r/r%r$r3rr4r0r2�rrrrr�
without_color�s
zStyle.without_colorru�style_definitionc
Cs�|��dks|s|��S|j}d}d}i}d}t|���}|D]�}|��}	|	dkrZt|d�}	|	s5t�d��z	t	�
|	�duWntyV}
zt�d|	�d|
���d�d}
~
ww|	}q|	dkryt|d�}	|�|	�}|durtt�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�rwzcolor expected after 'on'zunable to parse z as background color; �notz,expected style attribute after 'not', found FrgzURL expected after 'link'Tz as color; )rerfrgr)r�r}�STYLE_ATTRIBUTES�iter�splitr��nextrr�rrkr�getr)
r|r�r�rerfr�rg�words�
original_word�word�error�	attributerrrrrk�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�rerfrYrO�foreground_color�
get_truecolorr�from_tripletr�background_color�hexrQrSrUr]rbr�)rr��cssr�rerfr��theme_colorrrr�get_html_styleBs>
��

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�ryr��r|r��iter_stylesrrr�combineg�
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�rrr�chaintr�zStyle.chaincCs~|jrtS|�t�}|j|_|j|_|j|_|j|_|j|_|j	|_	|j
|_
|j
r/tdd��nd|_|j
|_
d|_|j|_|S)zwGet a copy of this style.

        Returns:
            Style: A new Style instance with identical attributes.
        rrvrwFr�r�rrr�copy�s
z
Style.copycCsp|�t�}|j|_|j|_|j|_|j|_|j|_|j|_||_|r(t	dd��nd|_
|j|_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.
        rrvrwF)r~rr5r6r.r/r%r$r3rr4r0r1r2)rrgrrrr�update_link�s
	zStyle.update_linkrwF)r��legacy_windows�textr�cCs^|r|dur|S|�|�}|rd|�d|�d�n|}|jr-|s-d|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;;\)r�r3r4)rr�r�r��attrs�renderedrrr�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)rx�sys�stdout�writer�)rr�rrr�test�s	z
Style.testcCs�t|t�s|dustS|dus|jr|S|jr|S|�t�}d|_d|_|jp)|j|_|jp0|j|_|j	|j
@|j	|j
@B|_	|j
|j
B|_
|jpL|j|_|jpS|j|_|j
|_
|jp^|j|_|jrs|jrsti|j�|j��|_|S|jpx|j|_|Sri)rjrr�r1r~r5r6r.r/r%r$r3r4r0r2rrh)rr�	new_stylerrr�__add__�s0

��z
Style.__add__)rr)NNri)r�rrr)rw)Fr'r(r)r*rr�__annotations__r,r-�bytesr+r�r�r
rxrrr �classmethodr}r�r�r�rrQrOrSrUrWrXrYr[r]r_r`rarb�propertyr�r�r�rr�rr��	StyleTyper�rr�r�r�rerfrgr�r�rhr�rkrr�r	r�r�r�r��	TRUECOLORr�r�r�rrrrrs�
���������	�
���
�������������	�
���
������
�S����  &.*A$
�����
�c@s`eZdZdZdgZddd�Zdefd	d
�Zede	fdd��Z
d
e	ddfdd�Zde	fdd�ZdS)�
StyleStackzA stack of styles.�_stack�
default_stylerrNcCs|g|_dSri�r�)rr�rrrr �szStyleStack.__init__cCsd|j�d�S)Nz<stylestack �>r�r�rrr�__repr__�r!zStyleStack.__repr__cCs
|jdS)z&Get the Style at the top of the stack.���r�r�rrr�current�s
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�rrr�pushszStyleStack.pushcCs|j��|jdS)z}Pop last style and discard.

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

zStyleStack.pop)r�rrN)
r'r(r)r*r+r rxr�r�rr�r�r�rrrrr��s
r�)$r��	functoolsr�marshalrr�randomr�typingrrrr	r
rrr
rwrrerrrr�reprrr�terminal_themerrrxr�rrr{r�rrrr�<module>s((T