B
    u9aQ              
   @   s   d dl Zd dlZd dlZd dlZd dlmZ	 ddddddgZ
d ddddZd!ddddZdd Zdd Zdd ZG dd dZdd ZG dd dZdd ZeeeeeeeeedhZdd Zd"ddZdd Z e!dkre  dS )#    N)StringIOpprintpformat
isreadableisrecursivesafereprPrettyPrinter   P   F)compactc            C   s    t |||||d}||  d S )N)streamindentwidthdepthr   )r   r   )objectr   r   r   r   r   Zprinter r   /usr/lib/python3.7/pprint.pyr   /   s    c            C   s   t ||||d| S )N)r   r   r   r   )r   r   )r   r   r   r   r   r   r   r   r   7   s    c             C   s   t | i d dd S )Nr   )
_safe_repr)r   r   r   r   r   <   s    c             C   s   t | i d dd S )Nr   r	   )r   )r   r   r   r   r   @   s    c             C   s   t | i d dd S )Nr      )r   )r   r   r   r   r   D   s    c               @   s"   e Zd ZdgZdd Zdd ZdS )	_safe_keyobjc             C   s
   || _ d S )N)r   )selfr   r   r   r   __init__T   s    z_safe_key.__init__c             C   sR   y| j |j k S  tk
rL   tt| j t| j ftt|j t|j fk S X d S )N)r   	TypeErrorstrtypeid)r   otherr   r   r   __lt__W   s
    z_safe_key.__lt__N)__name__
__module____qualname__	__slots__r   r   r   r   r   r   r   H   s   
r   c             C   s   t | d t | d fS )Nr   r	   )r   )tr   r   r   _safe_tuple^   s    r$   c               @   s  e Zd Zd:ddddZdd	 Zd
d Zdd Zdd Zdd Zi Z	dd Z
e
e	ej< dd Zee	ejj< dd Zee	ej< dd Zee	ej< dd Zee	ej< ee	ej< dd Zee	ej< dd Zee	ej< d d! Zee	ej< d"d# Zee	ejj< d$d% Z d&d' Z!d(d) Z"d*d+ Z#d,d- Z$e$e	ej%j< d.d/ Z&e&e	ej'j< d0d1 Z(e(e	ej)j< d2d3 Z*e*e	ej+j< d4d5 Z,e,e	ej-j< d6d7 Z.e.e	ej/j< d8d9 Z0e0e	ej1j< dS );r   r	   r
   NF)r   c            C   s|   t |}t |}|dk r td|d k	r8|dkr8td|sDtd|| _|| _|| _|d k	rf|| _ntj| _t|| _	d S )Nr   zindent must be >= 0zdepth must be > 0zwidth must be != 0)
int
ValueError_depth_indent_per_level_width_stream_sysstdoutbool_compact)r   r   r   r   r   r   r   r   r   r   c   s    zPrettyPrinter.__init__c             C   s&   |  || jddi d | jd d S )Nr   
)_formatr*   write)r   r   r   r   r   r      s    zPrettyPrinter.pprintc             C   s"   t  }| ||ddi d | S )Nr   )	_StringIOr0   getvalue)r   r   Zsior   r   r   r      s    zPrettyPrinter.pformatc             C   s   |  |i ddd S )Nr   r   )format)r   r   r   r   r   r      s    zPrettyPrinter.isrecursivec             C   s    |  |i dd\}}}|o| S )Nr   )r4   )r   r   sreadable	recursiver   r   r   r      s    zPrettyPrinter.isreadablec          	   C   s   t |}||kr.|t| d| _d| _d S | |||}| j| | }	t||	kr| j	t
|jd }
|
d k	rd||< |
| ||||||d  ||= d S t|trd||< | ||||||d  ||= d S || d S )NTFr	   )r   r1   
_recursion
_recursive	_readable_reprr)   len	_dispatchgetr   __repr__
isinstancedict_pprint_dict)r   r   r   r   	allowancecontextlevelobjidrep	max_widthpr   r   r   r0      s,    
zPrettyPrinter._formatc       
      C   sj   |j }|d | jdkr*|| jd d  t|}|r^t| td}	| |	|||d || |d d S )N{r	    )key})r1   r(   r<   sorteditemsr$   _format_dict_items)
r   r   r   r   rC   rD   rE   r1   lengthrO   r   r   r   rB      s    
zPrettyPrinter._pprint_dictc             C   sl   t |s|t| d S |j}||jd  | t| ||t |j d |d || |d d S )N(r	   ))r<   r1   repr	__class__r   r0   listrO   )r   r   r   r   rC   rD   rE   clsr   r   r   _pprint_ordered_dict   s    z"PrettyPrinter._pprint_ordered_dictc             C   s0   | d | ||||d || | d d S )N[r	   ])r1   _format_items)r   r   r   r   rC   rD   rE   r   r   r   _pprint_list   s    
zPrettyPrinter._pprint_listc             C   sH   | d t|dkrdnd}| ||||t| || | | d S )NrR   r	   z,)rS   )r1   r<   r[   )r   r   r   r   rC   rD   rE   endcharr   r   r   _pprint_tuple   s
    
zPrettyPrinter._pprint_tuplec       	      C   s   t |s|t| d S |j}|tkr8|d d}n&||jd  d}|t |jd 7 }t|td}| ||||t | || || d S )NrJ   rM   z({z})r	   )rL   )	r<   r1   rT   rU   setr   rN   r   r[   )	r   r   r   r   rC   rD   rE   typr]   r   r   r   _pprint_set   s    
zPrettyPrinter._pprint_setc             C   s  |j }t|s|t| d S g }|d}	|dkrD|d7 }|d7 }| j|  }
}xt|	D ]\}}t|}|t|	d kr|
|8 }
t||
kr|| q\td|}|	  |}d}xtt|D ]h\}}|| }|t|d kr|t|	d kr||8 }tt||kr&|r |t| |}q|}qW |r\|t| q\W t|dkr^|| d S |dkrp|d x8t|D ],\}}|dkr|dd|   || qzW |dkr|d	 d S )
NTr	   z\S*\s* rR   r   r/   rK   rS   )
r1   r<   rT   
splitlinesr)   	enumerateappendrefindallpop)r   r   r   r   rC   rD   rE   r1   ZchunkslinesZ
max_width1rH   ilinerG   partsZ
max_width2currentjpart	candidater   r   r   _pprint_str   sT    
 


zPrettyPrinter._pprint_strc             C   s   |j }t|dkr"|t| d S |dk}|rF|d7 }|d7 }|d d}	x:t|| j| |D ]$}
||	 ||
 |	s^dd|  }	q^W |r|d d S )N   r	   rR   rb   r/   rK   rS   )r1   r<   rT   _wrap_bytes_reprr)   )r   r   r   r   rC   rD   rE   r1   ZparensdelimrG   r   r   r   _pprint_bytes'  s"    zPrettyPrinter._pprint_bytesc          	   C   s>   |j }|d | t|||d |d ||d  |d d S )Nz
bytearray(
   r	   rS   )r1   ru   bytes)r   r   r   r   rC   rD   rE   r1   r   r   r   _pprint_bytearray<  s
    zPrettyPrinter._pprint_bytearrayc             C   s8   | d | | ||d |d || | d d S )Nzmappingproxy(   r	   rS   )r1   r0   copy)r   r   r   r   rC   rD   rE   r   r   r   _pprint_mappingproxyE  s    
z"PrettyPrinter._pprint_mappingproxyc          	   C   s   |j }|| j7 }dd|  }t|d }	xrt|D ]f\}
\}}|
|	k}| |||}|| |d | |||t| d |r|nd|| |s2|| q2W d S )Nz,
rK   r	   z: r   )r1   r(   r<   rd   r;   r0   )r   rO   r   r   rC   rD   rE   r1   delimnlZ
last_indexrj   rL   entlastrG   r   r   r   rP   M  s    

z PrettyPrinter._format_dict_itemsc             C   sN  |j }|| j7 }| jdkr,|| jd d  dd|  }d}	| j| d  }
}t|}yt|}W n tk
rv   d S X d}x|sH|}yt|}W n( tk
r   d}||8 }|
|8 }
Y nX | jr| |||}t|d }|
|k r|}
|	r|}	|
|kr|
|8 }
||	 d}	|| q~||	 |}	| 	||||r<|nd|| q~W d S )	Nr	   rK   z,
rb   FTr   z, )
r1   r(   r)   iternextStopIterationr.   r;   r<   r0   )r   rO   r   r   rC   rD   rE   r1   r|   rt   r   rH   itZnext_entr~   r}   rG   wr   r   r   r[   ^  sN    



zPrettyPrinter._format_itemsc             C   s4   |  || | j|\}}}|s&d| _|r0d| _|S )NFT)r4   rz   r'   r:   r9   )r   r   rD   rE   rT   r6   r7   r   r   r   r;     s    zPrettyPrinter._reprc             C   s   t ||||S )N)r   )r   r   rD   	maxlevelsrE   r   r   r   r4     s    zPrettyPrinter.formatc       	      C   s   t |s|t| d S | |j||}|j}|t |jd 7 }|d|j|d| f  | ||||d || |d d S )Nr	   z	%s(%s,
%srK   rS   )r<   r1   rT   r;   default_factoryrU   r   rB   )	r   r   r   r   rC   rD   rE   ZrdfrW   r   r   r   _pprint_default_dict  s    z"PrettyPrinter._pprint_default_dictc       	      C   s   t |s|t| d S |j}||jd  | jdkrN|| jd d  | }| |||t |j d |d || |d d S )Nz({r	   rK   r   z}))r<   r1   rT   rU   r   r(   most_commonrP   )	r   r   r   r   rC   rD   rE   rW   rO   r   r   r   _pprint_counter  s    
zPrettyPrinter._pprint_counterc       
   	   C   s   t |js|t| d S |j}||jd  |t |jd 7 }xrt|jD ]d\}}	|t |jd kr| |	|||d || |d qP| |	||d|| |dd|   qPW d S )NrR   r	   rS   z,
rK   )r<   mapsr1   rT   rU   r   rd   r0   )
r   r   r   r   rC   rD   rE   rW   rj   mr   r   r   _pprint_chain_map  s    
zPrettyPrinter._pprint_chain_mapc       	      C   s   t |s|t| d S |j}||jd  |t |jd 7 }|d |jd krz| ||||d || |d n:| |||d|| | |j||}|dd| |f  d S )NrR   r	   rY   r   z])z],
%smaxlen=%s)rK   )r<   r1   rT   rU   r   maxlenr[   r;   )	r   r   r   r   rC   rD   rE   rW   Zrmlr   r   r   _pprint_deque  s    

zPrettyPrinter._pprint_dequec          	   C   s   |  |j|||||d  d S )Nr	   )r0   data)r   r   r   r   rC   rD   rE   r   r   r   _pprint_user_dict  s    zPrettyPrinter._pprint_user_dictc          	   C   s   |  |j|||||d  d S )Nr	   )r0   r   )r   r   r   r   rC   rD   rE   r   r   r   _pprint_user_list  s    zPrettyPrinter._pprint_user_listc          	   C   s   |  |j|||||d  d S )Nr	   )r0   r   )r   r   r   r   rC   rD   rE   r   r   r   _pprint_user_string  s    z!PrettyPrinter._pprint_user_string)r	   r
   NN)2r   r    r!   r   r   r   r   r   r0   r=   rB   rA   r?   rX   _collectionsOrderedDictr\   rV   r^   tuplera   r_   	frozensetrq   r   ru   rw   rx   	bytearrayr{   _typesMappingProxyTyperP   r[   r;   r4   r   defaultdictr   Counterr   ChainMapr   dequer   UserDictr   UserListr   
UserStringr   r   r   r   r   b   sZ   &




1


)	c             C   s  t | }|tkrt| ddfS t|dd }t|tr:|tjkr:| sJdS t| }|rl||krldd||kfS ||krt| ddfS d||< d}d}g }	|	j	}
|d7 }t
}t|  td}xf|D ]^\}}|||||\}}}|||||\}}}|
d||f  |o|o|}|s|rd}qW ||= d	d
|	 ||fS t|trR|tjksjt|trf|tjkrft|tr| sdS d}n"t| dkrd}n| sdS d}t| }|r||kr|d d||kfS ||krt| ddfS d||< d}d}g }	|	j	}
|d7 }x>| D ]6}t
||||\}}}|
| |s<d}|rd}qW ||= |d
|	 ||fS t| }||o|d dfS )NTFr?   )z{}TFz{...}r	   )rL   z%s: %sz{%s}z, )z[]TFz[%s]z(%s,))z()TFz(%s)z...<)r   _builtin_scalarsrT   getattr
issubclassrA   r?   r   r8   re   r   rN   rO   r$   joinrV   r   r<   
startswith)r   rD   r   rE   r`   rrF   r6   r7   Z
componentsre   r   rO   kvZkreprZ	kreadableZkrecurZvreprZ	vreadableZvrecurr4   oZoreprZ	oreadableZorecurrG   r   r   r   r     s|    



r   c             C   s   dt | jt| f S )Nz<Recursion on %s with id=%s>)r   r   r   )r   r   r   r   r8   1  s    r8   c             C   s   dd l }| d kr,ddddgdddfgd	 } t }| }t| i d d | }||  | }td
||  td||  d S )Nr   string)r	   r      rr         )      i z_safe_repr:zpformat:)timer   Zperf_counterr   r   print)r   r   rI   Zt1Zt2Zt3r   r   r   
_perfcheck6  s    
r   c             c   s   d}t | d d }xhtdt | dD ]T}| ||d  }|| }||krR||8 }t t||krv|rpt|V  |}q&|}q&W |rt|V  d S )N    rr   r   )r<   rangerT   )r   r   rC   rm   r~   rj   ro   rp   r   r   r   rs   C  s    
rs   __main__)Nr	   r
   N)r	   r
   N)N)"collectionsr   rf   sysr+   typesr   ior   r2   __all__r   r   r   r   r   r   r$   r   r   r   r   rw   r   r%   floatcomplexr-   r   r   r8   r   rs   r   r   r   r   r   <module>%   s4   
   D
