8fi(ddlZddlmZddlmZmZddlmZddlm Z m Z m Z m Z m Z mZmZmZddlmZddlmZmZmZmZdd lmZmZdd lmZmZeed fZGd d Z eGdd Z!e!Z"GddZ#dS)N) lru_cache)dumpsloads)randint)AnyDictIterableListOptionalTypeUnioncast)errors)ColorColorParseError ColorSystem blend_rgb)Result rich_repr)DEFAULT_TERMINAL_THEME TerminalThemeStylecTeZdZdZdgZdeddfdZddd eddee fd Z dS) _Bitz.A descriptor to get/set a style attribute bit.bitbit_noreturnNcd|z|_dS)Nr)r)selfrs v/builddir/build/BUILD/imunify360-venv-2.3.5/opt/imunify360/venv/lib/python3.11/site-packages/pip/_vendor/rich/style.py__init__z _Bit.__init__s;objrobjtypecJ|j|jzr|j|jzdkSdS)Nr)_set_attributesr _attributes)r r$r%s r!__get__z _Bit.__get__s-   ) 3?TX-2 2tr#) __name__ __module__ __qualname____doc__ __slots__intr"r r boolr)r#r!rrst88Ist7T']x~r#rc&:eZdZUdZeeed<eeed<eed<eed<eeed<eed<ee ed<gd Z d d d d dddddddddd Z iddddddddddddddddd 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"d3Zedsd5Ze dtd/eed0eed4dfd6Zed2eeeefd4dfd7Zedud2eeeefd8ed4dfd9Zed:Zed;Zed<Zed=Zed>Zed?Zed@ZedAZedBZ edCZ!edDZ"edEZ#edFZ$e%d4efdGZ&d4efdHZ'd4efdIZ(dJe)d4efdKZ*ee+dLMdNed4efdOZ,edPee-d4e-fdQZ.d4e/fdRZ0dSed4efdTZ1dSed4efdUZ2d4efdVZ3e%d4eefdWZ4e%d4eefdXZ5e%d4eefdYZ6e%d4efdZZ7e%dsd[Z8e%d4eeeffd\Z9e%dsd]Z:ee+d^Md_ed4dfd`Z;e+dLMdudaee<d4efdbZ=edce>dd4dfddZ?edvdeZ@dsdfZAe+dgMdsdhZBdud1eed4dfdiZC dwe)jDdkdldmedJee)dned4efdoZEdudmeed4d-fdpZFe+dLMdNedd4dfdqZGdNedd4dfdrZHd-S)xraA 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) r3r4r(r'_link_link_id_ansi_style_definitionr5r6r712345678921515253) rr dimdboldbitalici underlineublinkblink2reverserconcealcstrikes underline2frameencircleoverline)uurerfrgoN)colorbgcolorrVrTrXrZr\r]r^r`rbrdrerfrglinkmetarjrkrlrmcd|_d|_dtttfdtfd}|dn |||_|dn |||_t|du|duod|duod|duod|duod|duod| duod | duod | duod | duod | duod |duod|duodf |_|jrPt|rdpd|rdpd|rdpd|rdpd|rdpd|rdpd| rd pd| rd pd| rd pd| rd pd| rd pd|rdpd|rdpdf nd|_ ||_ |dnt||_ |s|r&tddt|j nd|_d|_|jp|p|p|p| |_dS)NrjrcXt|tr|ntj|SN) isinstancerparse)rjs r! _make_colorz#Style.__init__.._make_colors%&ue44L55%+e:L:L Lr#rIrKrO @rr?B)r:r;r rstrr3r4sumr'r(r8rr7rhashr9r5r6)r rjrkrVrTrXrZr\r]r^r`rbrdrerfrgrlrmrss r!r"zStyle.__init__zs*%) 04 MuUCZ0 MU M M M M$mddU1C1C '[[5I5I "D 4%Ad"(q%+!T!(bd")rt#*t#+d"*s$&.3T!*d$-$-   F## CJQO!IANLq%AO!(qLb%AMr&QN'aO(qNs'a&3+!Nd'a%*%*   $' , !\TTuT{{ :> O$ Owq&!! 54 #3#3 5 5 5R %) .R%R7RdRdS r#rctS)zCCreate an 'null' style, equivalent to Style(), but more performant.) NULL_STYLE)clss r!nullz Style.nulls r#c|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. Nrr~) __new__rr:r;r3r4r'r(r8r9r7r6r5)rrjrkstyles r! from_colorzStyle.from_colorsr{{5)) "&   !   +G,   r#c8|t}d|_d|_d|_d|_d|_d|_d|_t||_ tddt|j |_ d|_| |_|S)zCreate a new style with meta data. Returns: meta (Optional[Dict[str, Any]]): A dictionary of meta data. Defaults to None. Nrr})rrr:r;r3r4r'r(r8rr7rrr9r5r6)rrmrs r! from_metazStyle.from_metas{{5)) "&  ! Dkk #Av..CU[0A0ACC j  r#handlersc |in|}|d|D||S)aCreate 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. Nc i|] \}}d|| S)@r1).0keyvalues r! zStyle.on..s$III*#uYYYIIIr#)updateitemsr)rrmrs r!onzStyle.onsN\rrt II8H8HIIIJJJ}}T"""r#rrrIrJrKrLrMrNrOrPrQrRrSc|jS)z+Get a link id, used in ansi code for links.)r9r s r!link_idz Style.link_id }r#c|jg}|j}|j}|dzrd|dzr||jrdnd|dzr||jrdnd|d zr||jrd nd |d zr||jrd nd|dzr}|dzr||jrdnd|dzr||jrdnd|dzr||j rdnd|dzr||j rdnd|dzr||j rdnd|dzrd|d zr||j rd!nd"|d#zr||j rd$nd%|d&zr||jrd'nd(|d)zr||jrd*nd+|j||jj|j |d,||jj|jr|d-||jd.|pd/|_|jS)0z-Re-generate style definition from attributes.NrrVznot boldrIrTznot dimrKrXz not italicrOrZz not underlinertr\z not blinkrur]z not blink2rvr^z not reverserwr`z not concealrxrbz not strikeryrdznot underline2rzrez not framer{rfz not encircler|rgz not overlinerrl none)r;appendr'rVrTrXrZr\r]r^r`rbrdrerfrgr3namer4r8join)r attributesrbitss r!__str__z Style.__str__s  ! )$&J&F'Do% O!8@FTY>66J???6?=FDH;55)<<<6?FFt{D88 EEE6?OF$.M;;oNNNo% F6?CFdjA77kBBB6?FFt{D88 EEE6?IF G99-HHH6?IF G99-HHH6?FFt{D88 EEEo% L6?RF4?P<<@PQQQ7#CFdjA77kBBB7#LFJ::NKKK7#LFJ::NKKK{&t{'(((}(t t})***z #vtz"""%(XXj%9%9%CVD "%%r#c|j S)z;A Style is false if it has no attributes, colors, or links.)r6rs r!__bool__zStyle.__bool__Ks :~r# color_systemc&|jg}|j}|j}|j|jz}|r|dzr||d|dzr||d|dzr||d|dzr||d|dzr,t dd D]}|d|zzr||||d zr,t d d D]}|d|zzr||||j?||j| |j A||j | d d ||_|jS)zGenerate ANSI codes for this style. Args: color_system (ColorSystem): Color system. Returns: str: String containing codes. NrrrIrKrOrJrrPr F foreground;) r:r _style_mapr(r'ranger3extend downgradeget_ansi_codesr4r)r rsgrrrrrs r!_make_ansi_codeszStyle._make_ansi_codesOs : CZFJ)D,@@J 4>*F:a=)))>*F:a=)))>*F:a=)))>*F:a=)))/4$Q{{44%c24"F:c?333/4$Q||44%c24"F:c?333{& 4;00>>MMOOPPP}( M++L99HH#(I #DJzr#rz)maxsizerc t||S#tj$r)|cYSwxYw)zNormalize 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. )rrrrStyleSyntaxErrorstriplower)rrs r! normalizezStyle.normalizezs_ )syy''(( (& ) ) );;==&&(( ( ( ( )s!$5AAvaluesc6|D]}||cS td)zPick first non-None style.Nz$expected at least one non-None style) ValueError)rrrs r! pick_firstzStyle.pick_firsts6  E  !?@@@r#c#Kd|jdfVd|jdfVd|jdfVd|jdfVd|jdfVd|jdfVd|jdfVd|jdfVd |jdfVd |j dfVd |j dfVd |j dfVd |j dfVd|j dfVd|jdfV|jr d|jfVdSdS)NrjrkrVrTrXrZr\r]r^r`rbrdrerfrlrm)rjrkrVrTrXrZr\r]r^r`rbrdrerfrlr7rmrs r! __rich_repr__zStyle.__rich_repr__sntz4''''t++++di&&&&TXt$$$$ T))))4>40000tz4'''' T))))t++++t++++ T))))DOT1111tz4''''$-----di%%%% : $$)# # # # # # $ $r#otherct|tstS||kSrprqrNotImplemented__hash__r rs r!__eq__z Style.__eq__7%'' "! !}}%.."2"222r#ct|tstS||kSrprrs r!__ne__z Style.__ne__rr#c|j|jSt|j|j|j|j|j|jf|_|jSrp)r5rr3r4r(r'r8r7rs r!rzStyle.__hash__sR : !:    $       zr#c|jS)z.The foreground color or None if it is not set.)r3rs r!rjz Style.colors {r#c|jS)z.The background color or None if it is not set.)r4rs r!rkz Style.bgcolorrr#c|jS)zLink text, if set.)r8rs r!rlz Style.links zr#c,|jdup |jjS)z6Check if the style specified a transparent background.N)rk is_defaultrs r!transparent_backgroundzStyle.transparent_backgrounds|t#>t|'>>r#c,t|jS)zA Style with background only.)rk)rrkrs r!background_stylezStyle.background_stylesT\****r#c|jin8ttttft |jS)z=Get meta information (can not be changed after construction).)r7rrrrrrs r!rmz Style.metas1Z'rrT$sCx.% BSBS-T-TTr#c>|jrtS|t}d|_d|_d|_d|_|j|_|j |_ |j |_ |j rtddnd|_ d|_d|_ d|_|S)z+Get a copy of the style with color removed.Nrr}r~F)r6rrrr:r;r3r4r(r'r8rr9r7r5r rs r! without_colorzStyle.without_colors :  ||E** "&  , $ 4j 48JFGAv..00B    r#r|style_definitionc|dks|s|S|j}d}d}i}d}t|}|D][}|} | dkrnt |d} | stjd tj | dun-#t$r } tjd| d| dd} ~ wwxYw| }| dkrDt |d} | | } | tjd | d || <| d kr*t |d} | stjd | }| |vr d ||| < tj | n-#t$r } tjd| d| dd} ~ wwxYw| }]td|||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. rNrr~zcolor expected after 'on'zunable to parse z as background color; notz,expected style attribute after 'not', found FrlzURL expected after 'link'Tz as color; )rjrkrlr1)rrSTYLE_ATTRIBUTESitersplitrnextrrrrrrgetr) rrrrjrkrrlwords original_wordworderror attributers r!rrz Style.parsesh  ! ! # #v - -5E -88:: /#!%/1 "%++--.."' ' M &&((Dt||E2O 12MNNN K%%---&    1P4PPPP  E2,0066 $ 1OtOO). 9%%E2O 12MNNN)))59 +D122 K%%%%&    1E4EEeEE  LE7LLLL s0%B<< C&C!!C&8F  F7F22F7themec|pt}g}|j}|j}|j}|jr||}}|jrF||jn||}tj t||j d}|;||}|d|j |d|j |*||d}|d|j |j r |d|jr |d |jr |d |jr |d |jr |d d |S)zGet a CSS style rule.Ng?zcolor: ztext-decoration-color: Frzbackground-color: zfont-weight: boldzfont-style: italicztext-decoration: underlineztext-decoration: line-throughztext-decoration: overlinez; )rrrjrkr^rTforeground_color get_truecolorr from_tripletrbackground_colorhexrVrXrZrbrgr)r rcssrrjrkr theme_colors r!get_html_stylezStyle.get_html_style3s// , < ,$e7E 8 */-&&U=P=PQV=W=W &*E,BCHHE  --e44K F.[_.. / / / F>[_>> ? ? ?  !//%/HHK F9 99 : : : 9 ( F& ' ' ' ; ) F' ( ( ( > 1 F/ 0 0 0 ; 4 F2 3 3 3 = 0 F. / / /yy~~r#stylescZt|}t|t|S)zCombine styles and get result. Args: styles (Iterable[Style]): Styles to combine. Returns: Style: A new style instance. rrrrr iter_styless r!combinez Style.combineX'6ll ;[ 1 1222r#cZt|}t|t|S)zCombine styles from positional argument in to a single style. Args: *styles (Iterable[Style]): Styles to combine. Returns: Style: A new style instance. rrs r!chainz Style.chainerr#cz|jrtS|t}|j|_|j|_|j|_|j|_|j|_|j |_ |j |_ |j rtddnd|_ |j |_ d|_|j|_|S)zwGet a copy of this style. Returns: Style: A new Style instance with identical attributes. rr}r~F)r6rrrr:r;r3r4r(r'r8rr9r5r7rs r!copyz Style.copyrs :  ||E**j "&"8{  , $ 4j 48JFGAv..00Bj  j  r#rwc6|jrtS|t}|j|_|j|_|j|_|j|_|j|_|j |_ d|_ d|_ |j |_ d|_d|_ |S)zGet a copy of this style with link and meta information removed. Returns: Style: New style object. Nr~F)r6rrrr:r;r3r4r(r'r8r9r5r7rs r!clear_meta_and_linkszStyle.clear_meta_and_linkss :  ||E**j "&"8{  , $ 4 j    r#c@|t}|j|_|j|_|j|_|j|_|j|_|j|_||_|rtddnd|_ d|_ d|_ |j |_ |S)zGet 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. rr}r~NF)rrr:r;r3r4r(r'r8rr9r5r6r7)r rlrs r! update_linkzStyle.update_links||E**j "&"8{  , $ 4 48@GAv..00b  j  r#r~F)rlegacy_windowstextrc|r||S|jp||}|r d|d|dn|}|jr|sd|jd|jd|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=rz\z]8;;\)r:rr8r9)r rrrattrsrendereds r!renderz Style.renders  |+K Ad33LAA49C050040000t : n WT]WWTZWWxWWW r#c|pt|}tj||ddS)zWrite 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)rsysstdoutwriter)r rs r!testz Style.testsE s4yy DKK--11122222r#c6||jr|S|jr|S|t}d|_d|_|jp|j|_|jp|j|_|j|jz|j|jzz|_|j|jz|_|j p|j |_ |j p|j |_ |j|_|j r*|j r#ti|j |j |_ n|j p|j |_ d|_|Srp)r6rrr:r;r3r4r(r'r8r9r7rrmr5)r r new_styles r!_addz Style._adds =EK=K : L<<..  &* # <64; "^JT~JTJT$JT$JTJTTNJT~JT 4.!JT"4.#JT$sm%JT&tCH~&'JTJTJTJTX[GKUO5=e_ [.Xd38n5'[(##htCH~.#3#7###[#" 477D $q''C T!WWFQI DGGE T!WWFd1ggGd1ggG T!WWFaJ DHHEtBxxHtBxxH X,&,&,&,&,&\$)[)S))))VYt )c )c ) ) )[ )A)!4AAAA[A$v$$$$&3C3D3333 3C3D3333 #    xX%XhsmX????X?+++X+Ud38nUUUXUX$Yt?S?W???[?BYt""H]$;"s""""H 3Xg. 37 3 3 3[ 3 3 3 3[ 3,Ys, 2/:.C$ {+    4 3 3# 3$ 3 3 3 3Yt(7+0PXg.P7PPPPPPr#cdeZdZdZdgZd dZdefdZede fd Z d e ddfd Z de fd Z dS) StyleStackzA stack of styles._stack default_stylerrNc|g|_dSrpr)r rs r!r"zStyleStack.__init__s$1? r#cd|jdS)Nz rrs r!__repr__zStyleStack.__repr__s.dk....r#c|jdS)z&Get the Style at the top of the stack.rrs r!currentzStyleStack.currents{2r#rcV|j|jd|zdS)z}Push a new style on to the stack. Args: style (Style): New style to combine with current style. r"N)rrrs r!pushzStyleStack.push s+ 4;r?U233333r#cN|j|jdS)z}Pop last style and discard. Returns: Style: New current style (also available as stack.current) r")rpoprs r!r'zStyleStack.pops" {2r#)rrrN) r*r+r,r-r.r"rr rrr#r%r'r1r#r!rrs I3333/#////X4%4D4444Ur#r)$r functoolsrmarshalrrrandomrtypingrrr r r r r rr~rrjrrrrreprrrterminal_themerrrrrrrrr1r#r!r.s  IIIIIIIIIIIIIIIIIIIIAAAAAAAAAAAA########AAAAAAAA #w,           X PX PX PX PX PX PX P X PvUWW r#