Vc_c s0dZddlZddlZddlZddlZddlZ ddl m Z gdZ ddddd d Zddddd d Zdd d ZdZdZdZGddZdZGddZeeeeeeeedhZdZ ddZ!dZ"e#dkr e!dSdS)a/Support to pretty-print lists, tuples, & dictionaries recursively. Very simple, but useful, especially in debugging data structures. Classes ------- PrettyPrinter() Handle pretty-printing operations onto a stream using a configured set of formatting parameters. Functions --------- pformat() Format a Python object into a pretty-printed representation. pprint() Pretty-print a Python object to a stream [default is sys.stdout]. saferepr() Generate a 'standard' repr()-like value, but protect against recursive data structures. N)StringIO)pprintpformat isreadable isrecursivesaferepr PrettyPrinterppPFTcompact sort_dictsunderscore_numbersc s\t|||||||}||dS)zAPretty-print a Python object to a stream [default is sys.stdout].)streamindentwidthdepthr r rN)rr) objectrrrrr r rZprinter /usr/lib64/python3.11/pprint.pyrr0sCfEJ-///G NN6csRt|||||||S)z @ @ @@GPr)r cs*t|g|Rd|i|dS)zPretty-print a Python objectr N)r)rr ZargsZkwargss rrr@s+ 6:D:::Z:6:::::rcsVt|idddS)z=Version of repr() which can handle recursive data structures.Nrr _safe_reprr rrrD% ?? % %fb$ : :1 ==rcVt|idddS)z4Determine if saferepr(object) is readable by eval().Nrr rrrrrrHrrcr)z8Determine if object requires a recursive representation.NrrrrrrrLrrcs$eZdZdZdgZdZdZdS) _safe_keyaUHelper function for key functions when sorting unorderable objects. The wrapped-object will fallback to a Py2.x style comparison for unorderable types (sorting first comparing the type name and then by the obj ids). Does not work recursively, so dict.items() must have _safe_key applied to both the key and the value. objcs||_dSN)r )selfr  r__init__z_safe_key.__init__\s rcs |j|jkS#t$rott|jt |jftt|jt |jfkcYSwxYwr!)r Z TypeErrorstrtypeid)r"Zotherr#r__lt__z_safe_key.__lt___s ;8ei' ' ; ; ;dh(("TX,,7ei))2ei==9: ; ; ; ;sA6B  B N)__name__ __module__ __qualname____doc__Z __slots__r$r(rrrrPsEI;;;;;rrcsVt|dt|dfS)z&Helper function for comparing 2-tuplesrr )r)Ztrr _safe_tupler.fs! QqT??IadOO ++rcseZdZd%dddddZdZd Zd Zd Zd Zd Z iZ dZ e e e j <dZee ejj <dZee ej <dZee ej <dZee ej <ee ej <dZee ej <dZee ej <dZee ej <dZee ej j <dZ!e!e ej"j <dZ#dZ$dZ%dZ&dZ'dZ(e(e ej)j <dZ*e*e ej+j <dZ,e,e ej-j <d Z.e.e ej/j <d!Z0e0e ej1j <d"Z2e2e ej3j <d#Z4e4e ej5j <d$Z6dS)&rr r NFTr cs`t|}t|}|dkrtd||dkrtd|std||_||_||_|||_nt j|_t||_ ||_ ||_ dS)aHandle pretty printing operations onto a stream using a set of configured parameters. indent Number of spaces to indent for each level of nesting. width Attempted maximum number of columns in the output. depth The maximum depth to print out nested structures. stream The desired output stream. If omitted (or false), the standard output stream available at construction will be used. compact If true, several items will be combined in one line. sort_dicts If true, dict keys are sorted. rzindent must be >= 0Nzdepth must be > 0zwidth must be != 0) intZ ValueError_depth_indent_per_level_width_stream_sysZstdoutbool_compact _sort_dicts_underscore_numbers)r"rrrrr r r rr$zPrettyPrinter.__init__ks2VE  A: 4233 3  2! 2011 1 3122 2 !'  '!DLL;DLW  %#5   rcs|j;|||jddid|jddSdS)Nr )r3_formatwriter"rr#rrzPrettyPrinter.pprintsP < % LLq!R ; ; ; L  t $ $ $ $ $ % %rcszt}|||ddid|SNr) _StringIOr;Zgetvalue)r"rZsios rrzPrettyPrinter.pformats5kk VS!QA...||~~rcs>||idddS)Nrrformatr=r#rrzPrettyPrinter.isrecursives{{62q!,,Q//rcsD||idd\}}}|o| Sr>r@)r"rZsreadable recursive rrzPrettyPrinter.isreadables-!%VRA!>!>8Y) M)rc st|}||vr2|t|d|_d|_dS||||}|j|z |z } t|| kr|j t|j d} | d||<| |||||||dz||=dStj |rpt|ts[|jjrOt#|j dr:d|j jjvr'd||<|||||||dz||=dS||dS)NTFr __wrapped__Z __create_fn__)r'r< _recursion _recursive _readable_reprr2len _dispatchZgetr&__repr__ _dataclassesZ is_dataclassZ isinstanceZ__dataclass_params__reprZhasattrrEr+_pprint_dataclass) r"rrr allowancecontextlevelobjidrep max_widthp rr;zPrettyPrinter._formats6  G   LLF++ , , ,"DO"DN Fjj%00K&(94 s88i  ""4<<#8$??A !"$ 7EAINNNEN+F33  .. -2 &/=99  "V_%@%MM  "#&&vvvy'SX[\S\]]]EN Srcsjj}|t|dzz }fdtjD}||dz||||||||ddS)Nr csVg|]%}|j |jt|jf&Sr-)rNZnamegetattr)Z.0Zfrs rz z3PrettyPrinter._pprint_dataclass..s5bbbq[\[ab!&'&!&112bbbr()) __class__r)rJrMZfieldsr<_format_namespace_items r"rrrrPrQrRZcls_nameitemss ` rrOzPrettyPrinter._pprint_dataclasss#,#h--!##bbbbL > > c rcs|d||||dz|dz|||ddS)Nz mappingproxy(i r rZ)r<r;copyrmrr_pprint_mappingproxyz"PrettyPrinter._pprint_mappingproxybs_ _%%% V[[]]FFRKQe % % % SrcsDt|tjurd}n |jj}|t |dzz }|j}||dz| |||||||ddS)NZ namespacer rYrZ) r&_typesSimpleNamespacer[r)rJZ__dict__r^r<r\r]rr_pprint_simplenamespacez%PrettyPrinter._pprint_simplenamespacejs <<61 1 1#HH'0H#h--!##%%'' X^$$$ $$UFFIwPUVVV Src sn|j}||jz }dd|zz}t|dz } t|D]y\} \} } | | k} || ||}|||d|| ||t|zdz| r|nd||| s ||zdS)N, r`r : r)r<r1rJrwrIr;)r"r^rrrPrQrRr<delimnl last_indexrzrbentlastrTs rrez PrettyPrinter._format_dict_itemsys $((#,&ZZ!^ &u--  MAzS ?D**S'511C E#JJJ E$KKK LLffs3xx&7!&;&*1 % ) ) ) g  rc sf|j}dd|zz}t|dz } t|D]\} \} } | | k} || |dt| |vr |dn1|| ||t| zdz| r|nd||| s ||dS)Nrr`r z=...)r<rJrwr'r;)r"r^rrrPrQrRr<rrrzrbrrs rr\z%PrettyPrinter._format_namespace_itemss #,&ZZ!^ &u--  MAzS ?D E#JJJ E#JJJ#ww'! -e  S&&3s88*;a*?*.5YYA$e--- g  rcs|j}||jz }|jdkr||jdz dzdd|zz}d} |j|z dzx} } t|} t | } n#t $rYdSwxYwd}|s| } t | } n#t $rd}| |z} | |z} YnwxYw|jrY||||}t|dz}| |kr| } | r|} | |kr| |z} || d} |||| |} | ||||r|nd|||dSdS) Nr r`rrvFTr, ) r<r1r2ZiterZnextZ StopIterationr6rIrJr;)r"r^rrrPrQrRr<rrrrUZitZnext_entrrrTZws rrlzPrettyPrinter._format_itemss $((  !A % 6 E4)A-4 5 5 5#,& K&0144 %[[ BxxHH    FF  )C #88  # # #Y& " #} jjgu55HHqL19(%E( 'A:QJEE%LLL EE#JJJ E%LLLE LLff&*1 % ) ) )/ ) ) ) ) )s$A,, A:9A:BB-,B-cs||||j|\}}}|sd|_|rd|_|S)NFT)rArr0rHrG)r"rrQrRrNrBrCrrrIzPrettyPrinter._reprsT$(KK 04 U%D%D!h  #"DN  #"DO rcs2|||||S)zFormat object for a specific context, returning a string and flags indicating whether the representation is 'readable' and whether the object represents a recursive construct. )r)r"rrQ maxlevelsrRrDrrAzPrettyPrinter.formats vw 5AAArcst|s$|t|dS||j||}|j}|t|jdzz }||jd|dd|z|||||dz|||ddS)Nr rYrr`rZ)rJr<rNrIZdefault_factoryr[r)rg) r"rrrrPrQrRZrdfrirr_pprint_default_dictz"PrettyPrinter._pprint_default_dicts6{{  LLf & & & Fjj/%@@#cl##a'' S\\\333f EFFF &&&)a-%PPP Srcst|s$|t|dS|j}||jdz|jdkr ||jdz dz|}||||t|jzdz|dz|||ddS)Nrqr r`rrr)rJr<rNr[r)r1Z most_commonre) r"rrrrPrQrRrir^rr_pprint_counterzPrettyPrinter._pprint_counters6{{  LLf & & & F S\D()))  !A % = LL$014; < < <""$$ v &S\):): :Q > A ' 0 0 0  Trc s,t|js$|t|dS|j}||jdz|t|jdzz }t |jD]\}} |t|jdz kr3|| |||dz|||dS|| ||d|||dd|zzdS)NrYr rZrr`)rJZmapsr<rNr[r)rwr;) r"rrrrPrQrRrirzZmrfr_pprint_chain_mapzPrettyPrinter._pprint_chain_maps6;  LLf & & & F S\C'(((#cl##a''fk** 3 3DAqC $$q(( 3 Q A wNNN S!!!! Q7EBBB US6\12222  3 3rcs2t|s$|t|dS|j}||jdz|t|jdzz }|d|j4|||||dz|||ddS||||d||||j||}|dd|zd|d dS) NrYr rkrz])z], r`zmaxlen=rZ)rJr<rNr[r)ZmaxlenrlrI) r"rrrrPrQrRriZrmlrr _pprint_dequezPrettyPrinter._pprint_deques,6{{  LLf & & & F S\C'(((#cl##a'' S = C   vvvy1}& / / / LL        vvvq& / / /**V]GU;;C LLLsV|||SSSA B B B B Brc J||j|||||dz dSNr r;Zdatarmrr_pprint_user_dictzPrettyPrinter._pprint_user_dict* V[&&)WeaiPPPPPrc rrrrmrr_pprint_user_listzPrettyPrinter._pprint_user_listrrc rrrrmrr_pprint_user_stringz!PrettyPrinter._pprint_user_string"rrcst|}|tvrt|ddfSt|dd}t |t r.|t jur |jr|dddfSt|ddfSt |tr|tjur |sdSt|}|r ||krdd||vfS||vrt|ddfSd||<d}d} g} | j } |dz }|j r)t|t} n|} | D]Y\} }|| |||\}}}|||||\}}}| |d ||o|o|}|s|rd} Z||=d d | z|| fSt |t$r|t$jus#t |t&r|t&jurt |t$r|sd Sd }nt)|dkrd}n|sdSd}t|}|r||kr |dzd||vfS||vrt|ddfSd||<d}d} g} | j } |dz }|D]1}|||||\}}}| ||sd}|rd} 2||=|d | z|| fSt|}||o|d dfS)NTFrLZ_d)z{}TFz{...}r rarz{%s}r)z[]TFz[%s]z(%s,))z()TFz(%s)rz<)r&_builtin_scalarsrNrXZ issubclassr/rLr8dictr'rFrxr7rdr^r.rAZjoinrhtuplerJZ startswith)r"rrQrrRrtZrrSrBrCZ componentsrxr^ZkZvZkreprZ kreadableZkrecurZvreprZ vreadableZvrecurrAZoZoreprZ oreadableZorecurrTs rrzPrettyPrinter._safe_repr's6ll " " -<<u, , CT * * c3   1A$5 1' 1 ~~tU22F||T500 c4  GQ$-%7 G )((vJJE 8Ui/ 8u'777 7!&))5$66GENHIJ&F QJE 'v||~~;???  % %1+/;;w 5,2,2(y&+/;;w 5,2,2(y&555%%0111#? ?i%V% $IDIIj1118YF F sD ! ! Ga4=&8 G sE " " G'(EN': G#t$$ -,,V!  -,,vJJE ?Ui/ ?~uew.>>> 7!&))5$66GENHIJ&F QJE % %+/;;w 5,2,2(y&u  %$H% $IDIIj1118YF F6llS4!4!44u<)r&r)r'rrrrFrF{s,F||$$$bjjjj 23rcslddl}|ddddgdddfgd z}t}|}||iddd |}|||}t d ||z t d ||z dS) NrZstring)r ririi)iiiTz _safe_repr:zpformat:)timerZ perf_counterrrZprint)rrrVZt1Zt2Zt3s r _perfcheckrsKKK EVaVq\\:;fDA    BLLT1d+++    BIIf    B -b!!! *b2grc#sNKd}t|dzdz}tdt|dD]W}|||dz}||z}||kr||z}tt||kr|rt|V|}U|}X|rt|VdSdS)Nrrr)rJZrangerN)rrrPr{rrzr|r}r9rrrsG v;;! a D 1c&kk1 % %   a1f~dN 9  Y E tI  % '  $7mm###GGGG7mmrZ__main__)Nr r N)r r Nr!)$r,Z collectionsrZ dataclassesrMryZsysr4ZtypesrZiorr?Z__all__rrrrrrrr.rrr%rrZfloatZcomplexr5r&rrFrrr)r-rrrs4#""""""" $$$$$$ " " "TePduPPPPP"';;;;;>>>>>>>>>;;;;;;;;,,,,L=L=L=L=L=L=L=L=\9c5)UG"DDJJ011333    " zJLLLLLr