a �DOg�W� @s�dZddlZddlZddlZddlZddlm Z gd�Z d&ddd �d d �Z d'ddd �d d �Z dd�dd�Zdd�Zdd�Zdd�ZGdd�d�Zdd�ZGdd�d�Zdd�Zeeeeeeeeed�h�Zdd �Z d(d!d"�Z!d#d$�Z"e#d%k�r�e!�dS))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)�pprint�pformat� isreadable� isrecursive�saferepr� PrettyPrinter�pp��PFT��compact� sort_dictscCs"t||||||d�}|�|�dS)zAPretty-print a Python object to a stream [default is sys.stdout].)�stream�indent�width�depthr rN)rr)�objectrrrrr rZprinter�r�/usr/lib64/python3.9/pprint.pyr/s �rcCst|||||d��|�S)zrr r NFTr cCs�t|�}t|�}|dkr td��|dur8|dkr8td��|sDtd��||_||_||_|durf||_ntj|_t|�|_ ||_ dS)a�Handle 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�_sys�stdout�bool�_compact� _sort_dicts)rrrrrr rrrrr hs  zPrettyPrinter.__init__cCs&|�||jddid�|j�d�dS)Nr� )�_formatr3�write�rrrrrr�szPrettyPrinter.pprintcCs"t�}|�||ddid�|��S�Nr)� _StringIOr:�getvalue)rr�siorrrr�szPrettyPrinter.pformatcCs|�|idd�dS)Nrr��formatr<rrrr�szPrettyPrinter.isrecursivecCs |�|idd�\}}}|o| Sr=rA)rr�s�readable� recursiverrrr�szPrettyPrinter.isreadablec Cs�t|�}||vr.|�t|��d|_d|_dS|�|||�}|j||} t|�| kr�|j� t |�j d�} | dur�d||<| |||||||d�||=dSt |t �r�d||<|�||||||d�||=dS|�|�dS)NTFr )r$r;� _recursion� _recursive� _readable�_reprr2�len� _dispatch�getr#�__repr__� isinstance�dict� _pprint_dict) rrrr� allowance�context�level�objid�rep� max_width�prrrr:�s.   �zPrettyPrinter._formatc Csz|j}|d�|jdkr*||jdd�t|�}|rn|jrNt|��td�} n|��} |�| |||d||�|d�dS)N�{r � ��key�})r;r1rJr8�sorted�itemsr-�_format_dict_items) rrrrrQrRrSr;�lengthr^rrrrP�s �zPrettyPrinter._pprint_dictcCslt|�s|�t|��dS|j}|�|jd�|�t|���||t|j�d|d||�|�d�dS)N�(r �))rJr;�repr� __class__r'r:�listr^)rrrrrQrRrS�clsrrr�_pprint_ordered_dict�s�z"PrettyPrinter._pprint_ordered_dictcCs0|�d�|�||||d||�|�d�dS)N�[r �])r;� _format_items�rrrrrQrRrSrrr� _pprint_list�s  �zPrettyPrinter._pprint_listcCsH|�d�t|�dkrdnd}|�||||t|�||�|�|�dS)Nrar z,)rb)r;rJrj)rrrrrQrRrS�endcharrrr� _pprint_tuple�s  �zPrettyPrinter._pprint_tuplec Cs�t|�s|�t|��dS|j}|tur8|�d�d}n&|�|jd�d}|t|j�d7}t|td�}|�||||t|�||�|�|�dS)NrXr\�({�})r rZ) rJr;rcrd�setr'r]rrj) rrrrrQrRrS�typrmrrr� _pprint_set�s  �zPrettyPrinter._pprint_setcCs�|j}t|�s|t|��dSg}|�d�} |dkrD|d7}|d7}|j|} } t| �D]�\} } t| �}| t| �dkr�| |8} t|�| kr�|�|�qZt�d| �}|� �| }d}t|�D]h\}}||}|t|�dkr�| t| �dkr�||8}tt|��|k�r"|�r|�t|��|}q�|}q�|rZ|�t|��qZt|�dk�rV||�dS|dk�rh|d�t|�D],\} }| dk�r�|dd|�||��qp|dk�r�|d �dS) NTr z\S*\s*�rarr9rYrb) r;rJrc� splitlinesr2� enumerate�append�re�findall�pop)rrrrrQrRrSr;�chunks�linesZ max_width1rV�i�linerU�partsZ max_width2�current�j�part� candidaterrr� _pprint_strsT          zPrettyPrinter._pprint_strc Cs�|j}t|�dkr"|t|��dS|dk}|rF|d7}|d7}|d�d} t||j||�D]$} || �|| �| s\dd|} q\|r�|d�dS)N�r rartr9rYrb)r;rJrc�_wrap_bytes_reprr2) rrrrrQrRrSr;Zparens�delimrUrrr� _pprint_bytes3s"  zPrettyPrinter._pprint_bytesc Cs>|j}|d�|�t|�||d|d||d�|d�dS)Nz bytearray(� r rb)r;r��bytes)rrrrrQrRrSr;rrr�_pprint_bytearrayHs �zPrettyPrinter._pprint_bytearraycCs8|�d�|�|��||d|d||�|�d�dS)Nz mappingproxy(� r rb)r;r:�copyrkrrr�_pprint_mappingproxyQs  �z"PrettyPrinter._pprint_mappingproxyc Cs�t|�tjurd}n|jj}|t|�d7}dd|}|j��} t| �d} |�|d�t | �D]^\} \} } |�| �|�d�| | k}|� | ||t| �d|r�|nd||�|sd|�|�qd|�d�dS)N� namespacer �, rYra�=rb) r#�_types�SimpleNamespacerdr'rJ�__dict__r^r;rvr:)rrrrrQrRrS�cls_name�delimnlr^� last_indexr}r[�ent�lastrrr�_pprint_simplenamespaceYs&      � z%PrettyPrinter._pprint_simplenamespacec Cs�|j}||j7}dd|}t|�d} t|�D]f\} \} } | | k} |�| ||�}||�|d�|�| ||t|�d| r�|nd||�| s0||�q0dS)Nr�rYr z: r)r;r1rJrvrIr:)rr^rrrQrRrSr;r�r�r}r[r�r�rUrrrr_ts    �z PrettyPrinter._format_dict_itemscCsH|j}||j7}|jdkr,||jdd�dd|}d} |j|d} } t|�} z t| �} WntyvYdS0d}|�sD| }z t| �} Wn&ty�d}| |8} | |8} Yn0|j�r|�|||�}t|�d}| |kr�| } | r�|} | |k�r| |8} || �d} ||�q||| �|} |� ||||�r8|nd||�q|dS) Nr rYr�rtFTr�, ) r;r1r2�iter�next� StopIterationr7rIrJr:)rr^rrrQrRrSr;r�r�rrV�itZnext_entr�r�rU�wrrrrj�sP           �zPrettyPrinter._format_itemscCs4|�||��|j|�\}}}|s&d|_|r0d|_|S)NFT)rBr�r0rHrG)rrrRrSrcrDrErrrrI�s � zPrettyPrinter._reprcCst|||||j�S)z�Format object for a specific context, returning a string and flags indicating whether the representation is 'readable' and whether the object represents a recursive construct. )rr8)rrrR� maxlevelsrSrrrrB�szPrettyPrinter.formatc Cs�t|�s|�t|��dS|�|j||�}|j}|t|j�d7}|�d|j|d|f�|�||||d||�|�d�dS)Nr z %s(%s, %srYrb)rJr;rcrI�default_factoryrdr'rP) rrrrrQrRrSZrdfrfrrr�_pprint_default_dict�sz"PrettyPrinter._pprint_default_dictc Cs�t|�s|�t|��dS|j}|�|jd�|jdkrN|�|jdd�|��}|�|||t|j�d|d||�|�d�dS)Nror rYrrp)rJr;rcrdr'r1� most_commonr_) rrrrrQrRrSrfr^rrr�_pprint_counter�s �zPrettyPrinter._pprint_counterc Cs�t|j�s|�t|��dS|j}|�|jd�|t|j�d7}t|j�D]d\}} |t|j�dkr�|�| |||d||�|�d�qN|�| ||d||�|�dd|�qNdS)Nrar rbr�rY)rJ�mapsr;rcrdr'rvr:) rrrrrQrRrSrfr}�mrrr�_pprint_chain_map�s  zPrettyPrinter._pprint_chain_mapc Cs�t|�s|�t|��dS|j}|�|jd�|t|j�d7}|�d�|jdurz|�||||d||�|�d�n:|�|||d||�|�|j||�}|�dd||f�dS)Nrar rhrz])z], %smaxlen=%s)rY)rJr;rcrdr'�maxlenrjrI) rrrrrQrRrSrfZrmlrrr� _pprint_deque�s"  �  �zPrettyPrinter._pprint_dequec Cs|�|j|||||d�dS�Nr �r:�datarkrrr�_pprint_user_dictszPrettyPrinter._pprint_user_dictc Cs|�|j|||||d�dSr�r�rkrrr�_pprint_user_listszPrettyPrinter._pprint_user_listc Cs|�|j|||||d�dSr�r�rkrrr�_pprint_user_string sz!PrettyPrinter._pprint_user_string)r r NN)4r'r(r)r rrrrr:rKrPrOrMrg� _collections� OrderedDictrlrern�tuplersrq� frozensetr�r"r�r�r�� bytearrayr�r��MappingProxyTyper�r�r_rjrIrBr�� defaultdictr��Counterr��ChainMapr��dequer��UserDictr��UserListr�� UserStringrrrrrgs`� +      1     )       rcCs�t|�}|tvrt|�ddfSt|dd�}t|t��rD|tju�rD|sJdSt|�}|rl||krldd||vfS||vr�t|�ddfSd||<d}d} g} | j } |d7}|r�t |� �t d�} n|� �} | D]b\} }t | ||||�\}}}t |||||�\}}}| d||f�|�o|�o|}|�s$|r�d} q�||=d d �| �|| fSt|t��r\|tju�stt|t��rn|tju�rnt|t��r�|�s�d Sd }n"t|�dk�r�d }n|�s�dSd}t|�}|�r�||k�r�|dd||vfS||v�r�t|�ddfSd||<d}d} g} | j } |d7}|D]8}t |||||�\}}}| |�|�sFd}|�rd} �q||=|d �| �|| fSt|�}||�o�|�d� dfS)NTFrM)z{}TFz{...}r rZz%s: %sz{%s}r�)z[]TFz[%s]z(%s,))z()TFz(%s)z...�<)r#�_builtin_scalarsrc�getattr� issubclassrOrMr$rFrwr]r^r-r�joinrer�rJ� startswith)rrRr�rSrrr�rrTrDrE� componentsrwr^�k�vZkreprZ kreadableZkrecurZvreprZ vreadableZvrecurrB�oZoreprZ oreadableZorecurrUrrrrs�    ��  rcCsdt|�jt|�fS)Nz)r#r'r$rrrrrFZs�rFcCs�ddl}|dur,ddddgddd�fgd }t�}|��}t|iddd �|��}|�|�|��}td ||�td ||�dS) Nr�string)r r�r���)��i��Tz _safe_repr:zpformat:)�timer� perf_counterrr�print)rr�rW�t1�t2Zt3rrr� _perfcheck_s r�ccs�d}t|�dd}tdt|�d�D]T}|||d�}||}||krP||8}tt|��|krt|rnt|�V|}q$|}q$|r�t|�VdS)N�r�r)rJ�rangerc)rrrQr�r�r}r�r�rrrr�ls r��__main__)Nr r N)r r N)N)$r*� collectionsr�rx�sysr4�typesr��iorr>�__all__rrr rrrrr-rrr�r"r�r�r.�float�complexr6r#r�rFr�r�r'rrrr� s> � � -F�