"TeUddlZddlZddlZddlZddlZddlZddlmZddlmZmZm Z m Z m Z ddlm Z m Z mZddlmZddlmZddlmZddlmZmZmZmZmZmZmZmZmZmZmZm Z dd l!m"Z" ddl#Z$e%e$d Z&d d l(m)Z)d dl*m+Z+d dl,m-Z-d dl.m/Z/d dl0m1Z1d dl2m3Z3d dl4m5Z5m6Z6d dl7m8Z8d dl9m:Z:erd dl;mZ>m?Z?m@Z@mAZAdedeBfdZCdededfdZDdeEdeBfdZFejdgZHdeEdeBfdZI doded ed!d"d#d$eBd%eBd&eeJd'eeJd(eeJd)eBde eKdffd*ZLdeEd+e eMeeMd,ffdeBfd-ZN dod ed!d"d#d$eBd%eBd&eeJd'eeJd(eeJd)eBddfd.ZOGd/d0e5ZPd1eeefdeeKeKeKffd2ZQd1d3deeKeKeKffd4ZRejd5eeRe eQed6e d7eTd8ed9eUd:eVd;e d<eWd=eXd>ed?i ZYeeMeegeeKeKeKfffeZd@<eXeYjZ\eTejeefZ]dedeBfdAZ^e GdBdCZ_e GdDdEZ`dedeBfdFZa dpd1ed&eeJd'eeJd(eeJde_f dGZbdHdIdddd dJd1edKeJdLeJd&eeJd'eeJd(eeJd)eBdeKfdMZcddNdddd dOd1ed ed!d%eBd&eeJd'eeJd(eeJd)eBddfdPZdeedQk(rGdRdSZfddTlmgZgGdUdVegZhe eJZidWeidX<d dYdZd[d\hd]geUhd^e eVd_gd`iegdadbehdcdddedfdgdhgefdiZjejdXjejddjllmmZmemePejdNdklGdmdnZnemePenyy#e'$rd Z&YwxYw)qN)array)CounterUserDictUserList defaultdictdeque) dataclassfields is_dataclass)isclass)islice)MappingProxyType) TYPE_CHECKINGAnyCallable DefaultDictDictIterableListOptionalSequenceSetTupleUnion)RichReprResultibF get_console) loop_last) pick_bool)RichRenderablecell_len)ReprHighlighter) JupyterMixinJupyterRenderable) Measurement)Text)ConsoleConsoleOptionsHighlighterType JustifyMethodOverflowMethod RenderResultobjreturncNtxrtjt|S)z1Check if an object was created with attrs module.) _has_attrs _attr_modulehastyper0s -/usr/lib/python3/dist-packages/rich/pretty.py_is_attr_objectr9:s  5,**4955z_attr_module.Attribute[Any]cNtrtjt|SgS)zGet fields for an attrs object.)r3r4r r6r7s r8_get_attr_fieldsr<?s-7<  tCy )?R?r:c |jjjtjk(S#t $rYywxYw)zCheck if an instance of a dataclass contains the default repr. Args: obj (object): A dataclass instance. Returns: bool: True if the default repr is used, False if there is a custom repr. F)__repr____code__ co_filename dataclasses__file__ Exceptionr7s r8_is_dataclass_reprrDDs:||$$00K4H4HHH s 03 ??_dummy_namedtuplecd} tj|j}tjt j}||k(S#ttf$rY9wxYw)zCheck if an instance of namedtuple contains the default repr Args: obj (object): A namedtuple Returns: bool: True if the default repr is used, False if there's a custom repr. N)inspectgetfiler>OSError TypeErrorrE)r0obj_filedefault_repr_files r8_has_default_namedtuple_reprrMXs_H ??3<<0  (9(B(BC ( (( Y    sA AAvalueconsoler*overflowr.crop indent_guides max_length max_string max_depth expand_allc ddlm} t|ts|y|xs t }|j 5} t|| r|j |jt|tr|nt|||||||d|ddddd jjdS#1swY(xYw) Nr)ConsoleRenderable )rPrRrSrTrUrVmarginT)rQnew_line_startend ) rOrX_safe_isinstancer'rcapturelineprintr"Prettygetrstrip) rNrOrPrQrRrSrTrUrVrXr`s r8_ipy_display_hookrfls+01U]&G   g E#4 5 LLN ~6 !+%%#%    . ;;=   %%/  s AB44B=class_or_tuple.c: t||S#t$rYywxYw)zFisinstance can fail in rare cases, for example types with no __class__F) isinstancerC)r0rgs r8r_r_s&#~.. s  c & ddlm xs Jdtddffd } t} ddlm} G fdd | } | } | | j jd <y#t$r|t_ YywxYw) aInstall automatic pretty printing in the Python REPL. Args: console (Console, optional): Console instance or ``None`` to use global console. Defaults to None. overflow (Optional[OverflowMethod], optional): Overflow method. Defaults to "ignore". crop (Optional[bool], optional): Enable cropping of long lines. Defaults to False. indent_guides (bool, optional): Enable indentation guides. Defaults to False. max_length (int, optional): Maximum length of containers before abbreviating, or None for no abbreviation. Defaults to None. max_string (int, optional): Maximum length of string before truncating, or None to disable. Defaults to None. max_depth (int, optional): Maximum depth of nested data structures, or None for no maximum. Defaults to None. expand_all (bool, optional): Expand all containers. Defaults to False. max_frames (int): Maximum number of frames to show in a traceback, 0 for no maximum. Defaults to 100. rrNrNr1c |PJdt_jt|tr|nt ||t_yy)z?Replacement sys.displayhook which prettifies objects with Rich.N)rPrRrSrTrUrV)rQ)builtins_rbr_r"rc) rNrOrQrVrRrUrSrTrPs r8 display_hookzinstall..display_hooksl  & &&HJ MM#E>:%"/))')  HJ# r:) BaseFormatterc>eZdZUdZeed<dedeffd Zy)install..RichFormatterTpprintrNr1c b|jrt|St|S)N)rOrPrRrSrTrUrV)rrrfrepr) selfrNrVrrRrUrSrTrPs r8__call__z'install..RichFormatter.__call__s=;;, + !)&3#-#-"+#-   ;&r:N)__name__ __module__ __qualname__rrbool__annotations__rrv)rVrrRrUrSrTrPsr8 RichFormatterrqs%FD  'c 'c ' 'r:r|z text/plain) richrr get_ipythonIPython.core.formattersrodisplay_formatter formatters NameErrorsys displayhook)rOrPrQrRrSrTrUrVrnipror|rich_formatterrs```````` @r8installrs0!&G   CD*G ] : ' 'M '&'8F'' 53 '&'s A99BBceZdZdZ ddddddddddddd deded d ed ed d eddeededeedeedeededededdfdZ ddZ ddZ y)rcakA rich renderable that pretty prints an object. Args: _object (Any): An object to pretty print. highlighter (HighlighterType, optional): Highlighter object to apply to result, or None for ReprHighlighter. Defaults to None. indent_size (int, optional): Number of spaces in indent. Defaults to 4. justify (JustifyMethod, optional): Justify method, or None for default. Defaults to None. overflow (OverflowMethod, optional): Overflow method, or None for default. Defaults to None. no_wrap (Optional[bool], optional): Disable word wrapping. Defaults to False. indent_guides (bool, optional): Enable indentation guides. Defaults to False. max_length (int, optional): Maximum length of containers before abbreviating, or None for no abbreviation. Defaults to None. max_string (int, optional): Maximum length of string before truncating, or None to disable. Defaults to None. max_depth (int, optional): Maximum depth of nested data structures, or None for no maximum. Defaults to None. expand_all (bool, optional): Expand all containers. Defaults to False. margin (int, optional): Subtrace a margin from width to force containers to expand earlier. Defaults to 0. insert_line (bool, optional): Insert a new line if the output has multiple new lines. Defaults to False. NFr) indent_sizejustifyrPno_wraprRrSrTrUrVrZ insert_line_object highlighterr,rrr-rPr.rrRrSrTrUrVrZrr1c ||_|xs t|_||_||_||_||_||_||_| |_ | |_ | |_ | |_ | |_ yN)rr%rrrrPrrRrSrTrUrVrZr)rurrrrrPrrRrSrTrUrVrZrs r8__init__zPretty.__init__sk" &;/*;&29 4<  *$$"$ &r:c #Kt|j|j|jz |j|j |j |j|j}tj||jxs |j|jxs |jt|j|jd}|r|j|n"tt!|jdd}|j"r)|j$s|j'|jd}|j(rd|vrd |yw) N max_widthrrSrTrUrVpretty)rrPrstylez.__repr__ returned empty stringz dim italic)rz repr.indentr^r[) pretty_reprrrrZrrSrTrUrVr) from_ansirrPr!rrr6rR ascii_onlywith_indent_guidesr)rurOoptions pretty_str pretty_texts r8__rich_console__zPretty.__rich_console__'s$! LL''$++5((nn nn LL3GOO]]6g&6&6dllGOO<     [ ) %&&EF"    g&8&8%88  9K    3HsEEc t|j|j|j|j|j |j |j}|r td|jDnd}t||S)Nrc32K|]}t|ywrr#.0ras r8 z*Pretty.__rich_measure__..WsC4Cr) rrrrrSrTrUrVmax splitlinesr()rurOrr text_widths r8__rich_measure__zPretty.__rich_measure__Jsw! LL''((nn HRCC:+@+@+BC CWX :z22r:r)rOr*rr+r1r/)rOr*rr+r1r() rwrxry__doc__rrintrzrrrr:r8rcrcs,48' -1/3"'#$($(#' !''/0'  ' /* '+,'$''SM'SM'C='''' !'>! !+;! !F3 3+;3 3r:rcrcDd|jddd|jdfS)Nz defaultdict(z, {})z, {}))default_factoryrs r8_get_braces_for_defaultdictr\s5 w..16 w..19 r:z array[Any]cDd|jddd|jdfS)Nzarray(z, [])))typecoders r8_get_braces_for_arrayrds0W%%( ,dfW=M=Mrir:cy)N)z Counter({rz Counter()rrs r8rrlrr:cy)N)zdeque([rzdeque()rrs r8rrmrr:cyN){}z{}rrs r8rrnrr:cyrrrs r8rrorr:cy)N)z frozenset({rz frozenset()rrs r8rrprr:cyN)[]z[]rrs r8rrqrr:cyrrrs r8rrrrr:cy)N)rrzset()rrs r8rrsrr:cy)N)(r()rrs r8rrtrr:cy)N)zmappingproxy({rzmappingproxy({})rrs r8rrurr:_BRACESct|txs&t|xst|dxs t |xr t | S)z3Check if an object may be expanded by pretty print. __rich_repr__)r_ _CONTAINERSr hasattrr9r r7s r8 is_expandabler{sO k*   C )  3    cl  r:c eZdZUdZdZeed<dZeed<dZeed<dZ eed<dZ eed<dZ e ed <dZ e ed <dZe ed <d Zeeded <dZeed<dZeed<deefdZdedede fdZdefdZ ddedede defdZy )Nodez4A node in a repr tree. May be atomic or a container.r[key_repr value_repr open_brace close_braceemptyFlastis_tuple is_namedtupleNchildrenz: key_separatorz, separatorr1c#^K|jr|j|j|jr|jy|j|jr|j|j rN|j sBt|jdk(r*|jdjEd{dnD|jD]5}|jEd{|jr(|j7|jy|jyy7l7Bw)zGenerate tokens for this node.Nrr,) rrrrrrrlen iter_tokensrrrr)ruchilds r8rzNode.iter_tokenss ==-- $$ $ ??// ! ]] &}}oo%==););DMM@RVW@W#}}Q/;;===I!%1#(#4#4#666$zz"&..01&&&jj '>7s*B:D-<D)=+D-(D+)D-:0D-+D- start_lengthrSc\|}|jD]}|t|z }||kDsyy)a*Check the length fits within a limit. Args: start_length (int): Starting length of the line (indent, prefix, suffix). max_length (int): Maximum length. Returns: bool: True if the node can be rendered within max length, otherwise False. FT)rr$)rurrS total_lengthtokens r8 check_lengthzNode.check_lengths?$ %%' E HUO +Lj( r:cDdj|j}|SNr[)joinr)ru repr_texts r8__str__z Node.__str__sGGD,,./ r:rrrVc(t|dg}d}|t|kr[||}|jr6|js*|s|j |s|j ||||dz|dz }|t|kr[dj d|D}|S)alRender the node to a pretty repr. Args: max_width (int, optional): Maximum width of the repr. Defaults to 80. indent_size (int, optional): Size of indents. Defaults to 4. expand_all (bool, optional): Expand all levels. Defaults to False. Returns: str: A repr string of the original object. T)nodeis_rootrrr^c32K|]}t|ywr)strrs r8rzNode.render..s94SY9r)_Liner expandableexpandedrexpandr)rurrrVlinesline_norarepr_strs r8renderz Node.rendersD$/0E ">Dt}}T%6%6y%A37;;{3KE'GaK0 qLG E "999599r:)PrF)rwrxryrrrr{rrrrrrzrrrrrrrrrrrrrrr:r8rrs>HcJJKE3OD$HdM4'+HhtF|$+M3Is!Xc]!,#$" MR03EI r:rceZdZUdZdZeded<dZeed<dZ ee ed<dZ e ed<dZ e ed <dZe ed <dZeed <dZeed <ed efdZded efdZded edfdZd e fdZy)rzA line in repr output.NparentFrrr[textsuffix whitespacerrr1c`t|jduxr|jjS)z"Check if the line may be expanded.N)rzrrrus r8rz_Line.expandables'DIIT)@dii.@.@AAr:rSct|jt|jzt|jz}|j J|j j ||S)z4Check this line fits within a given number of cells.)rrr$rrrr)rurSrs r8rz_Line.check_lengthsZ  8DII#6 6$++9N N yy$$$yy%%lJ??r:rc #lK|j}|J|j}|jsJ|jr4t |j|j |j |}nt |j |}|jd|zz}|jxrt|jdk(}t|jD].\}}|rdn |j} t |||| |xr| } | 0t |j||j|jyw)z6Expand this line by adding children on their own line.N)rr rr)rrrrr)rrrr)rrrrrrrrrr rrrr) rurrrnew_linechild_whitespace tuple_of_onerrrras r8rz _Line.expands(yy__ }}} ==" t'9'9&:4??:KL%H #JOOH??S;->>}}@T]]);q)@ $T]]3 KD%+I+ .,. DJ !!!;;   sD2D4c|jr*|j|j|jxsdS|j|j|jxsd|jj Sr)rrrrrrers r8rz _Line.__str__si 99oo&tyyk$))/r1BC C??#DII;tyyB.? @R@R@T?UV r:)rwrxryrrrr{rrzrrrrrrrrpropertyrrrrrrrr:r8rrs $FHW $GTD(4.D#NFCJHdD$ BDBB@s@t@ # (7*; Br:rc t|dd}t|txrt|tS#t$rYywxYw)aXChecks if an object is most likely a namedtuple. It is possible to craft an object that passes this check and isn't a namedtuple, but there is only a minuscule chance of this happening unintentionally. Args: obj (Any): The object to test Returns: bool: True if the object is a namedtuple. False otherwise. _fieldsNF)getattrrCrituple)r0r s r8_is_namedtuplersDi. c5 ! ?j&?? s 1 ==c  dtdtffd t j jd dtdt dt dtf fd |d}|S) a`Traverse object and generate a tree. Args: _object (Any): Object to be traversed. max_length (int, optional): Maximum length of containers before abbreviating, or None for no abbreviation. Defaults to None. max_string (int, optional): Maximum length of string before truncating, or None to disable truncating. Defaults to None. max_depth (int, optional): Maximum depth of data structures, or None for no maximum. Defaults to None. Returns: Node: The root of a tree structure which can be used to render a pretty repr. r0r1c>t|ttfr(t|kDrt|z }|dd|}|S t |}|S#t $r}dt|d}Yd}~|Sd}~wwxYw)z0Get repr string for an object, but catch errors.N+z )r_bytesrrrtrC)r0 truncatedobj_reprerrorrTs r8to_reprztraverse..to_reprFs  " ucl3C:%C:-Ikz*-Qyk:H   :9 :)#e*q9 :s A A3A..A3rootdepthc P"t}|)vr tdSt}$duxr|$k\}dtdtt tt ttfffd} td}d}|s( td rtsj}|7'|tjd d} t||} jj} | rg} | j } |r#| rtd | d }nt| d }n| rtd | dd| |d}nt| dd| |}t#| D]a\}}t%|t&r0|\}}#||dz}||_||_d|_| |F#||dz}||_| |cnt| rd | dn| dg|}&|nt/rA|s>'|g} | j } t1""r|r$tjjd }ntjjdd| |}dtt ttt2t4tgtfff"fd }t#|D]Q\}\}}}|rtt||}n #||dz}||_||_d|_| |Sn%tjjdg|}&|nt7r t%ts|st9r'|g} | j } |r$tjjd }ntjjdd| |jjd}t#dt;DD]M\}}#t|j<|dz}|j<|_||_d|_| |O&|nt?rtAr'|jj} |rt| d }ng} | j } t| dd| | d}t#jCjED]2\}\}}#||dz}||_||_d|_| |4&|nt%tFrtFD]}t%|s|}n'|tI|\}}}|rt|d|}n[|jJtjJk7rt(|}n$rg} t||| |}| j } tM}|dz }t%tNrjtQjE}% tS|%}tU|D]4\} \}}#||dz}(||_| |k(|_| |6nKtQ}!% tS|!%}!tU|!D]$\} }#||dz}| |k(|_| |&%-|%kDr(| td|%z dnt|g| }&|nt(|}t%t&|_+t?|_,|S#t$rd}YwxYw#t$rYwxYw)!zWalk the object depth first.z...)rN rich_argsr1c3K|D]h}t|trRt|dk(r|\}}}||k(r-||f4t|dk(r |\}}||fNt|dk(s]|de|jyw)Nrr)r_rr)rargkeyrdefaults r8iter_rich_argsz3traverse.._traverse..iter_rich_argsfs #C/3x1}.1+UG"e+$!5j(SQ%( U!5j(SQ!!f I s AA1"A1,awehoi234_wdfjwljet234_234wdfoijsdfmmnxpi492Frangularz(...)rr)rrrrrrr)rrrrr)r=r)rrrc3KD]X}|js t|j}|j|t|jr |jndfZy#t$r}|j|dfYd}~{d}~wwxYww)z$Iterate over attr fields and values.N)rtr namecallablerC)attrrNr attr_fieldsr0s r8 iter_attrsz/traverse.._traverse..iter_attrss%0 &D#yy !&,3C,CE )- (-5=dii5H d+&%& &(1!C+/99eT*B$B!Cs-B A"5B " B+B<B BB )rrrrrc3:K|]}|js|ywr)rt)rfields r8rz.traverse.._traverse..s-#ejjE-s)rrrr)rrz... +T)rrr)-idrr6rrrrrrrCr rr list __class__rwappendr r_rrrrr9r<rrr rDr r)rrM_asdictitemsrrr>r_MAPPING_CONTAINERSiterr enumeraterr)*r0rrobj_idobj_typereached_max_depthr#fake_attributesrich_repr_resultr%args class_namerr3rrr r!r child_noder-r)rN repr_callabler/container_typerrr num_itemslast_item_index iter_itemsindex iter_valuesr, _traverserUrS pop_visited push_visitedr visited_idss*` @r8rHztraverse.._traverseZslC [ 5) )9%T1Hey6H c huS%S/=Q7R.S   $%CO 6: 30'*'8'8':$  '  c//EBG'789D//J!$#:,d/CD#*U/CD#)*:,a'8(+%-!%&)   $*4Q'7(+%-!%   &/t_ / c+C7),JC)25 )JJ.2JO25J/7:J4":.)23eai)HJ.2JO":. /4;:,a0JU+::tUM()-]5=Q9R)SJ)25 )JJ*. .2 +36 0z*+"%--"8"8!9s-C *J U *S 'FG""d3i&8&88ws|$?) +%  "H "+a-#C)<=!%ciik!2J!-%+J %C /8/D++|U%.uEAI%F .5cl +*/?*B z* + #'s)K!-&,[*&E (1+(>+ u%.uEAI%F */?*B z*+)i*.D4U9z3I2J+KRVWX%"4@  73zBrokenRepr.__repr__s E#r:Nrwrxryrr>rr:r8rWrWs $c $r:rW) NamedTuplecFeZdZUeed<eed<eed<eed<eeed<y)StockKeepingUnitr) descriptionpricecategoryreviewsN)rwrxryrr{floatrrr:r8r\r\s!   cr:r\fooz Hello World!gZd;Y@gʡE3t@gcA>rrrrrb>rrrcrumble)applerhubarbbuttersugarflour)riorangepearkumquatrpXduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurian)FTNzSparkling British Spring WaterzCarbonated spring waterg?waterz its amazing!z its terrible!)rcbarrcounteratomic namedtupleBroken)rb)rRrTceZdZdefdZy)Thingr1cy)NzHello World!rrs r8r>zThing.__repr__s/r:NrYrr:r8rzrzs 0c 0r:rz)NrRFFNNNF)NNN)orl collectionsrArGosrrrrrrrr r r r itertoolsr typesrtypingrrrrrrrrrrrr rich.reprrr+r4rr3 ImportErrorr[r_loopr _pickr!abcr"cellsr$rr%jupyterr&r'measurer(rr)rOr*r+r,r-r.r/rzr9r<objectrDrvrErMrrrfr6r_rrcrr_Environdict frozensetr1rLrrr{keysrr6rrrrrOrrrrwrWrZr\ddatar3r}rbrzrr:r8rs GG77"    %t,J(4 666 @#@(+H"I@ Ft"+K**+>C)f)),$(!) $ $#+& +& i +&+&  +&  +&  +& +&}+&+& 39+&\ !&tU49-='=!> $(!) $ $#MG i MGMG MG MG  MG  MG}MGMG MG`e3\e3PS#X)>5cSVCWT<TE#sC-4HT KKC , = 7 * . C * . , +R>dHcUE#sC-$8899 :GLLN# R[[*:HEst QQ Qh @@ @F@@@*!% $# e e e e} e  eV  $ $#% %% %  %  %}%% %V$( $ $#" "i " "  "  "}"" "J z$$ ": CAAeH      &  #" 9NO    && , %   _ -  ,? DB Kt &Tb 9:00 &/{IJs- MMM