Vc_ 0dZddlZddlZddlZddlZddlZ 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 \t|||||||}||dS)zAPretty-print a Python object to a stream [default is sys.stdout].)streamindentwidthdepthrrrN)r r) objectrrrrrrrprinters /usr/lib64/python3.11/pprint.pyrr0sCfEJ-///G NN6cRt|||||||S)z @ @ @@GPr)rc*t|g|Rd|i|dS)zPretty-print a Python objectrN)r)rrargskwargss rr r @s+ 6:D:::Z:6:::::rcVt|idddS)z=Version of repr() which can handle recursive data structures.Nrr _safe_reprrs rrrD% ?? % %fb$ : :1 ==rcVt|idddS)z4Determine if saferepr(object) is readable by eval().Nrr rr!s rrrHr"rcVt|idddS)z8Determine if object requires a recursive representation.Nrrr!s rrrLr"rc$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. objc||_dSN)r()selfr(s r__init__z_safe_key.__init__\s rc |j|jkS#t$rott|jt |jftt|jt |jfkcYSwxYwr*)r( TypeErrorstrtypeid)r+others r__lt__z_safe_key.__lt___s ;8ei' ' ; ; ;dh(("TX,,7ei))2ei==9: ; ; ; ;sA6B  B N)__name__ __module__ __qualname____doc__ __slots__r,r3rrr'r'PsEI;;;;;rr'cVt|dt|dfS)z&Helper function for comparing 2-tuplesrr )r')ts r _safe_tupler<fs! QqT??IadOO ++rceZdZd%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)&r r r NFTr c`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) int ValueError_depth_indent_per_level_width_stream_sysstdoutbool_compact _sort_dicts_underscore_numbers)r+rrrrrrrs rr,zPrettyPrinter.__init__ks2VE  A: 4233 3  2! 2011 1 3122 2 !'  '!DLL;DLW  %#5   rc|j;|||jddid|jddSdS)Nr )rD_formatwriter+rs rrzPrettyPrinter.pprintsP < % LLq!R ; ; ; L  t $ $ $ $ $ % %rczt}|||ddid|SNr) _StringIOrMgetvalue)r+rsios rrzPrettyPrinter.pformats5kk VS!QA...||~~rc>||idddS)Nrr%formatrOs rrzPrettyPrinter.isrecursives{{62q!,,Q//rcD||idd\}}}|o| SrQrV)r+rsreadable recursives rrzPrettyPrinter.isreadables-!%VRA!>!>8Y) M)rc t|}||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__ __create_fn__)r1rN _recursion _recursive _readable_reprrClen _dispatchgetr0__repr__ _dataclasses is_dataclass isinstance__dataclass_params__reprhasattrr]r6_pprint_dataclass) r+rrr allowancecontextlevelobjidrep max_widthps rrMzPrettyPrinter._formats6  G   LLF++ , , ,"DO"DN Fjj%00K&(94 s88i  ""4<<#8$??A !"$ 7EAINNNEN+F33  .. -2 &/=99  "V_%@%MM  "#&&vvvy'SX[\S\]]]EN Srcjj}|t|dzz }fdtjD}||dz||||||||ddS)Nr cVg|]%}|j |jt|jf&Sr9)rknamegetattr).0frs r z3PrettyPrinter._pprint_dataclass..s5bbbq[\[ab!&'&!&112bbbr()) __class__r4rcrgfieldsrN_format_namespace_items r+rrrrnrorpcls_nameitemss ` rrmzPrettyPrinter._pprint_dataclasss#,#h--!##bbbbL > > c rc|d||||dz|dz|||ddS)Nz mappingproxy( r r})rNrMcopyrs r_pprint_mappingproxyz"PrettyPrinter._pprint_mappingproxybs_ _%%% V[[]]FFRKQe % % % SrcDt|tjurd}n |jj}|t |dzz }|j}||dz| |||||||ddS)N namespacer r|r}) r0_typesSimpleNamespacer~r4rc__dict__rrNrrs r_pprint_simplenamespacez%PrettyPrinter._pprint_simplenamespacejs <<61 1 1#HH'0H#h--!##%%'' X^$$$ $$UFFIwPUVVV Src n|j}||jz }dd|zz}t|dz } t|D]y\} \} } | | k} || ||}|||d|| ||t|zdz| r|nd||| s ||zdS)N, rr : r%)rNrBrcrrbrM)r+rrrrnrorprNdelimnl last_indexrrentlastrrs rrz PrettyPrinter._format_dict_itemsys $((#,&ZZ!^ &u--  MAzS ?D**S'511C E#JJJ E$KKK LLffs3xx&7!&;&*1 % ) ) ) g  rc f|j}dd|zz}t|dz } t|D]\} \} } | | k} || |dt| |vr |dn1|| ||t| zdz| r|nd||| s ||dS)Nrrr =...)rNrcrr1rM)r+rrrrnrorprNrrrrrrs rrz%PrettyPrinter._format_namespace_itemss #,&ZZ!^ &u--  MAzS ?D E#JJJ E#JJJ#ww'! -e  S&&3s88*;a*?*.5YYA$e--- g  rc|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 rrrFTr%, ) rNrBrCiternext StopIterationrHrbrcrM)r+rrrrnrorprNrrrrsitnext_entrrrrws rrzPrettyPrinter._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-c||||j|\}}}|sd|_|rd|_|S)NFT)rWrrArar`)r+rrorprkrZr[s rrbzPrettyPrinter._reprsT$(KK 04 U%D%D!h  #"DN  #"DO rc2|||||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+rro maxlevelsrps rrWzPrettyPrinter.formats vw 5AAArct|s$|t|dS||j||}|j}|t|jdzz }||jd|dd|z|||||dz|||ddS)Nr r|rrr})rcrNrkrbdefault_factoryr~r4r) r+rrrrnrorprdfrs r_pprint_default_dictz"PrettyPrinter._pprint_default_dicts6{{  LLf & & & Fjj/%@@#cl##a'' S\\\333f EFFF &&&)a-%PPP Srct|s$|t|dS|j}||jdz|jdkr ||jdz dz|}||||t|jzdz|dz|||ddS)Nrr rr%r)rcrNrkr~r4rB most_commonr) r+rrrrnrorprrs r_pprint_counterzPrettyPrinter._pprint_counters6{{  LLf & & & F S\D()))  !A % = LL$014; < < <""$$ v &S\):): :Q > A ' 0 0 0  Trc ,t|js$|t|dS|j}||jdz|t|jdzz }t |jD]\}} |t|jdz kr3|| |||dz|||dS|| ||d|||dd|zzdS)Nr|r r}rr)rcmapsrNrkr~r4rrM) r+rrrrnrorprrms r_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 3rc2t|s$|t|dS|j}||jdz|t|jdzz }|d|j4|||||dz|||ddS||||d||||j||}|dd|zd|d dS) Nr|r rr%z])z], rzmaxlen=r})rcrNrkr~r4maxlenrrb) r+rrrrnrorprrmls r _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 rMdatars r_pprint_user_dictzPrettyPrinter._pprint_user_dict* V[&&)WeaiPPPPPrc J||j|||||dz dSrrrs r_pprint_user_listzPrettyPrinter._pprint_user_listrrc J||j|||||dz dSrrrs r_pprint_user_stringz!PrettyPrinter._pprint_user_string"rrct|}|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)NTFrf_d)z{}TFz{...}r rrz{%s}r)z[]TFz[%s]z(%s,))z()TFz(%s)r<)r0_builtin_scalarsrkrx issubclassr?rfrJdictr1r_rrIrrr<rWjoinrtuplerc startswith)r+rrorrprrrqrZr[ componentsrrkvkrepr kreadablekrecurvrepr vreadablevrecurrWoorepr oreadableorecurrrs rr zPrettyPrinter._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<)r0r4r1r!s rr_r_{s,F||$$$bjjjj 23rclddl}|ddddgdddfgd z}t}|}||iddd |}|||}t d ||z t d ||z dS) Nrstring)r r%r)iTz _safe_repr:zpformat:)timer perf_counterr rprint)rr$rtt1t2t3s r _perfcheckr*sKKK EVaVq\\:;fDA    BLLT1d+++    BIIf    B -b!!! *b2grc#NKd}t|dzdz}tdt|dD]W}|||dz}||z}||kr||z}tt||kr|rt|V|}U|}X|rt|VdSdS)Nrrr)rcrangerk)rrrnrrrrrs rrrsG v;;! a D 1c&kk1 % %   a1f~dN 9  Y E tI  % '  $7mm###GGGG7mmr__main__)Nr r N)r r Nr*)$r7 collectionsr dataclassesrgrsysrEtypesriorrR__all__rrr rrrr'r<r rr/rrfloatcomplexrGr0rr_r*rr4r9rrr6s4#""""""" $$$$$$ " " "TePduPPPPP"';;;;;>>>>>>>>>;;;;;;;;,,,,L=L=L=L=L=L=L=L=\9c5)UG"DDJJ011333    " zJLLLLLr