Qf^^ dZddlZddlZddlZddlZddlZ ddl m Z gdZ ddddddZdddddd Zdd d Zd Zd ZdZGddZdZGddZeeeeeeeedhZdZ dZ!y)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 PrettyPrinterppFTcompact sort_dictsunderscore_numbersc Jt|||||||}|j|y)zAPretty-print a Python object to a stream [default is sys.stdout].)streamindentwidthdepthr r rN)r r) objectrrrrr r rprinters -/opt/alt/python312/lib64/python3.12/pprint.pyrr0s-fEJ-/G NN6cBt||||||j|S)z @@GPr)r c&t|g|d|i|y)zPretty-print a Python objectr N)r)rr argskwargss rr r @s 6:D:Z:6:rc@tj|idddS)z=Version of repr() which can handle recursive data structures.Nrr _safe_reprrs rrrD ? % %fb$ :1 ==rc@tj|idddS)z4Determine if saferepr(object) is readable by eval().Nrrrs rrrHr rc@tj|idddS)z8Determine if object requires a recursive representation.Nrrrs rrrLr rc"eZdZdZdgZdZdZy) _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||_yN)r')selfr's r__init__z_safe_key.__init__\s rc" |j|jkS#t$rjtt|jt |jftt|jt |jfkcYSwxYwr))r' TypeErrorstrtypeid)r*others r__lt__z_safe_key.__lt___sm ;88eii' ' ;dhh("TXX,7eii)2eii=9: ; ;sA0B BN)__name__ __module__ __qualname____doc__ __slots__r+r2rrr&r&PsI;rr&c:t|dt|dfS)z&Helper function for comparing 2-tuplesrr")r&)ts r _safe_tupler;fs QqT?IadO ++rceZdZd#dddddZdZdZdZd Zd Zd Z iZ d Z e e e j<d Zee ej j<dZee ej<dZee ej<dZee ej<ee ej<dZee ej<dZee ej<dZee ej<dZee ej@j<dZ!e!e ejDj<dZ#dZ$dZ%dZ&dZ'dZ(e(e ejRj<dZ*e*e ejVj<dZ,e,e ejZj<dZ.e.e ej^j<dZ0e0e ejbj<d Z2e2e ejfj<d!Z4e4e ejjj<d"Z6y)$r NFTr c2t|}t|}|dkr td||dkr td|s td||_||_||_|||_nt j|_t||_ ||_ ||_ y)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. underscore_numbers If true, digit groups are separated with underscores. 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*rrrrr r rs rr+zPrettyPrinter.__init__ks8VE  A:23 3  !01 112 2 !'  !DL;;DLW  %#5 rc|j<|j||jddid|jjdyy)Nr )rC_formatwriter*rs rrzPrettyPrinter.pprints= << # LLq!R ; LL  t $ $rcbt}|j||ddid|jSNr) _StringIOrLgetvalue)r*rsios rrzPrettyPrinter.pformats+k VS!QA.||~rc0|j|idddS)Nrr$formatrNs rrzPrettyPrinter.isrecursives{{62q!,Q//rc@|j|idd\}}}|xr| SrPrU)r*rsreadable recursives rrzPrettyPrinter.isreadables*!%VRA!>8Y) M)rc t|}||vr)|jt|d|_d|_y|j |||}|j |z |z } t|| kDr|jjt|jd} | d||<| |||||||dz||=ytj|rt|tsp|jj rZt#|jdrDd|jj$j&vr"d||<|j)||||||dz||=y|j|y)NTFr" __wrapped__ __create_fn__)r0rM _recursion _recursive _readable_reprrBlen _dispatchgetr/__repr__ _dataclasses is_dataclass isinstance__dataclass_params__reprhasattrr\r5_pprint_dataclass) r*rrr allowancecontextlevelobjidrep max_widthps rrLzPrettyPrinter._formatsA6  G  LLF+ ,"DO"DN jj%0KK&(94 s8i ""4<#8#8$?A}!"$ 7EAINEN++F3 .--22&//=9!V__%@%@%M%MM!"&&vvvy'SX[\S\]EN Srcp|jj}|t|dzz }tj|Dcgc]1}|j s|j t||j f3} }|j|dz|j| ||||||jdycc}w)Nr"()) __class__r3rbrffieldsrjnamegetattrrM_format_namespace_items) r*rrrrmrnrocls_namefitemss rrlzPrettyPrinter._pprint_dataclasss##,,#h-!## c rc|jd|j|j||dz|dz|||jdy)Nz mappingproxy( r"rv)rMrLcopyrs r_pprint_mappingproxyz"PrettyPrinter._pprint_mappingproxyesA _% V[[]FFRKQe % Src8t|tjurd}n|jj}|t |dzz }|j j}|j|dz|j|||||||jdy)N namespacer"rurv) r/_typesSimpleNamespacerwr3rb__dict__r~rMr{) r*rrrrmrnror|r~s r_pprint_simplenamespacez%PrettyPrinter._pprint_simplenamespacems <611 1#H''00H#h-!##%%' X^$ $$UFFIwPUV Src J|j}||jz }dd|zz}t|dz } t|D]d\} \} } | | k(} |j | ||}|||d|j | ||t|zdz| r|nd||| r]||fy)N, rr": r$)rMrArbrrarL)r*r~rrrmrnrorMdelimnl last_indexrrentlastrqs rrz PrettyPrinter._format_dict_items|s $(((#,&Z!^ &u-MAzS ?D**S'51C #J $K LLffs3x&7!&;&* % )g.rc 2|j}dd|zz}t|dz } t|D]g\} \} } | | k(} || |dt| |vr |dn)|j | ||t| zdz| r|nd||| r`||iy)Nrrr"=...)rMrbrr0rL)r*r~rrrmrnrorMrrrrrrs rr{z%PrettyPrinter._format_namespace_itemss #,&Z!^ &u-MAzS ?D #J #J#w'!e  S&&3s8*;a*?*.YA$e-g.rcd|j}||jz }|jdkDr||jdz dzdd|zz}d} |j|z dzx} } t|} t | } d}|s| } t | } |j rI|j|||}t|dz}| |kr| } | r|} | |k\r| |z} || d} ||e|| |} |j||||r|nd|||syy#t $rYywxYw#t $rd}| |z} | |z} YwxYw) Nr"rrrFTr$, ) rMrArBiternext StopIterationrGrarbrL)r*r~rrrmrnrorMrrrrritnext_entrrrqws rrzPrettyPrinter._format_itemssn $(((  ! !A % 4))A-4 5#,& KK&0144 %[ BxHC #8 }}jjgu5HqL19%E 'A:QJE%L E#J %LE LLff&* % )/   ! #Y& " #s$- D? D DDD/.D/c|j||j|j|\}}}|sd|_|rd|_|S)NFT)rVrr@r`r_)r*rrnrorjrYrZs rrazPrettyPrinter._reprsD$(KK 04 U%D!h "DN "DO rc*|j||||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*rrn maxlevelsros rrVzPrettyPrinter.formats vw 5AArcxt|s|jt|y|j|j||}|j }|t|j dzz }|j|j d|dd|z|j||||dz|||jdy)Nr"rurrrv)rbrMrjradefault_factoryrwr3r) r*rrrrmrnrordfrs r_pprint_default_dictz"PrettyPrinter._pprint_default_dicts6{ LLf & jj//%@#cll#a'' S\\3f EF &&&)a-%P Srct|s|jt|y|j}|j|jdz|j dkDr!|j|j dz dz|j }|j|||t|jzdz|dz|||jdy)Nrr"rr$r)rbrMrjrwr3rA most_commonr) r*rrrrmrnrorr~s r_pprint_counterzPrettyPrinter._pprint_counters6{ LLf &  S\\D()  ! !A % LL$0014; <""$ v &S\\): :Q > A ' 0  Trc t|js|jt|y|j}|j|j dz|t|j dzz }t |jD]x\}} |t|jdz k(r+|j| |||dz|||jdL|j| ||d|||jdd|zzzy)Nrur"rvrr)rbmapsrMrjrwr3rrL) r*rrrrmrnrorrms r_pprint_chain_mapzPrettyPrinter._pprint_chain_maps6;; LLf &  S\\C'(#cll#a''fkk*DAqC $q(( Q A wN S! Q7EB US6\12 +rct|s|jt|y|j}|j|jdz|t|jdzz }|jd|j +|j ||||dz|||jdy|j |||d|||j|j ||}|jdd|zd|d y) Nrur"rr$z])z], rzmaxlen=rv)rbrMrjrwr3maxlenrra) r*rrrrmrnrorrmls r _pprint_dequezPrettyPrinter._pprint_deques6{ LLf &  S\\C'(#cll#a'' S ==   vvvy1}& / LL    vvvq& /**V]]GU;C LLsV|SA Brc J|j|j|||||dz yNr"rLdatars r_pprint_user_dictzPrettyPrinter._pprint_user_dict  V[[&&)WeaiPrc J|j|j|||||dz yrrrs r_pprint_user_listzPrettyPrinter._pprint_user_list rrc J|j|j|||||dz yrrrs r_pprint_user_stringz!PrettyPrinter._pprint_user_string%rrcjt|}|tvrt|ddfSt|dd}t |t r3|t j ur!|jr|dddfSt|ddfSt |tr |tj ur|syt|}|r ||k\rdd||vfS||vrt|ddfSd||<d}d} g} | j} |dz }|jr t|jt} n|j} | D]S\} }|j!| |||\}}}|j!||||\}}}| |d ||xr|xr|}|s|sRd} U||=d d j#| z|| fSt |t$r|t$j us"t |t&r|t&j urt |t$r|sy d }nt)|dk(rd}n|syd}t|}|r||k\r |dzd||vfS||vrt|ddfSd||<d}d} g} | j} |dz }|D]+}|j!||||\}}}| ||sd}|s*d} -||=|d j#| z|| fSt|}||xr|j+d dfS)NTFre_d)z{}TFz{...}r"rrz{%s}r)z[]TFz[%s]z(%s,))z()TFz(%s)r<)r/_builtin_scalarsrjrz issubclassr>rerIdictr0r^rrHrr~r;rVjoinrtuplerb startswith)r*rrnrrorrrprYrZ componentsrr~kvkrepr kreadablekrecurvrepr vreadablevrecurrVoorepr oreadableorecurrqs rrzPrettyPrinter._safe_repr*s6l " "<u, , CT * c3 A$5'' tU22F|T500 c4 Q$--%7(vJEUi/u'777!&)5$66GENHIJ&&F QJEv||~;? 1+/;;w 5,2(y&+/;;w 5,2(y&5%01#? ?iV $IDIIj118YF F sD !a4==&8 sE "qENN':#t$,V! ,vJEUi/~uew.>>>!&)5$66GENHIJ&&F QJE+/;;w 5,2(y&u  $H $IDIIj118YF F6lS4!44u<)r/r3r0rs rr^r^~sF|$$bj 23rc# Kd}t|dzdz}tdt|dD]D}|||dz}||z}||k(r||z}tt||kDr|r t||}C|}F|rt|yyw)Nrrr)rbrangerj)rrrmrrrrrs rrrsG v;! a D 1c&k1 %a1~dN 9 Y E tI % '7m#GG&7msBB)Nr"r N)r"r N)"r6 collectionsr  dataclassesrfrsysrDtypesriorrQ__all__rrr rrrr&r;r r r.rr floatcomplexrFr/rr^rr8rrr"s4#" $ "TePduP"';>>>;;,,O=O=bc5)UG"DJ013 r