B
    u9a';                 @   s   d dl Z d dlZejdedd dZG dd dZG dd dZG d	d
 d
ZG dd deZG dd deZ	dddZ
edkre
  dS )    Nz"the formatter module is deprecated   )
stacklevelc               @   s   e Zd Zd'ddZdd Zdd Zdd	 Zd(d
dZdd Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zd d! Zd)d#d$Zd*d%d&ZdS )+NullFormatterNc             C   s   |d krt  }|| _d S )N)
NullWriterwriter)selfr    r   /usr/lib/python3.7/formatter.py__init__)   s    zNullFormatter.__init__c             C   s   d S )Nr   )r   	blankliner   r   r	   end_paragraph-       zNullFormatter.end_paragraphc             C   s   d S )Nr   )r   r   r   r	   add_line_break.   r   zNullFormatter.add_line_breakc             O   s   d S )Nr   )r   argskwr   r   r	   add_hor_rule/   r   zNullFormatter.add_hor_rulec             C   s   d S )Nr   )r   formatcounterr   r   r   r	   add_label_data0   r   zNullFormatter.add_label_datac             C   s   d S )Nr   )r   datar   r   r	   add_flowing_data1   r   zNullFormatter.add_flowing_datac             C   s   d S )Nr   )r   r   r   r   r	   add_literal_data2   r   zNullFormatter.add_literal_datac             C   s   d S )Nr   )r   r   r   r	   flush_softspace3   r   zNullFormatter.flush_softspacec             C   s   d S )Nr   )r   alignr   r   r	   push_alignment4   r   zNullFormatter.push_alignmentc             C   s   d S )Nr   )r   r   r   r	   pop_alignment5   r   zNullFormatter.pop_alignmentc             C   s   d S )Nr   )r   xr   r   r	   	push_font6   r   zNullFormatter.push_fontc             C   s   d S )Nr   )r   r   r   r	   pop_font7   r   zNullFormatter.pop_fontc             C   s   d S )Nr   )r   marginr   r   r	   push_margin8   r   zNullFormatter.push_marginc             C   s   d S )Nr   )r   r   r   r	   
pop_margin9   r   zNullFormatter.pop_marginc             C   s   d S )Nr   )r   spacingr   r   r	   set_spacing:   r   zNullFormatter.set_spacingc             G   s   d S )Nr   )r   stylesr   r   r	   
push_style;   r   zNullFormatter.push_style   c             C   s   d S )Nr   )r   nr   r   r	   	pop_style<   r   zNullFormatter.pop_stylec             C   s   d S )Nr   )r   flagr   r   r	   assert_line_data=   r   zNullFormatter.assert_line_data)N)N)r&   )r&   )__name__
__module____qualname__r
   r   r   r   r   r   r   r   r   r   r   r   r    r!   r#   r%   r(   r*   r   r   r   r	   r      s$   


r   c               @   s   e Zd Zdd Zdd Zdd Zdd Zd-d
dZdd Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zd d! Zd"d# Zd$d% Zd&d' Zd.d)d*Zd/d+d,Zd	S )0AbstractFormatterc             C   sR   || _ d | _g | _g | _g | _d | _g | _d| _d| _d| _	d| _
d| _d| _d S )Nr&   r   )r   r   align_stack
font_stackmargin_stackr"   style_stacknospace	softspacepara_endparskip
hard_break
have_label)r   r   r   r   r	   r
   N   s    zAbstractFormatter.__init__c             C   s`   | j s| j  d| _| j|k rD| jsD| j|| j  || _d| _d | _  | _| _d| _d S )Nr   r&   )	r7   r   send_line_breakr8   r6   send_paragraphr3   r5   r4   )r   r   r   r   r	   r   ]   s    
zAbstractFormatter.end_paragraphc             C   s8   | j s"| js"| j  d | _| _d | _ | _d| _d S )Nr   r&   )r7   r5   r   r9   r8   r6   r3   r4   )r   r   r   r	   r   h   s
    
z AbstractFormatter.add_line_breakc             O   sF   | j s| j  | jj|| d | _ | _d | _ | _ | _| _d S )Nr&   r   )	r7   r   r9   send_hor_ruler3   r8   r5   r4   r6   )r   r   r   r   r   r	   r   o   s
    
zAbstractFormatter.add_hor_ruleNc             C   s   | j s| js| j  | js0| j|r*dp,d t|trP| j| 	|| n| j| d | _
 | _  | _| _d | _| _d S )Nr&   r   )r8   r7   r   r9   r5   r:   
isinstancestrsend_label_dataformat_counterr3   r4   r6   )r   r   r   r   r   r   r	   r   v   s    

z AbstractFormatter.add_label_datac             C   sx   d}xn|D ]f}|dkr$|d|  }q
|dkrF|dkrp||  || }q
|dkrh|dkrp|| || }q
|| }q
W |S )N 1z%dZaAr   ZiI)format_letterformat_roman)r   r   r   labelcr   r   r	   r?      s    
z AbstractFormatter.format_counterc             C   s@   d}x6|dkr:t |d d\}}tt|| }|| }qW |S )Nr@   r   r&      )divmodchrord)r   caser   rD   r   sr   r   r	   rB      s    
zAbstractFormatter.format_letterc       	      C   s   ddddg}dddg}d\}}x|d	krt |d
\}}|dkrX|| ||d   | }nT|dkrv|| ||  | }n6|dkr|| }|d }nd}||| |  }|| }|d }q W |dkr| S |S )Nir   rE   mvld)r@   r   r   
   	   r&         r@   I)rG   upper)	r   rJ   r   ZonesZfivesrD   indexr   rK   r   r   r	   rC      s&    


zAbstractFormatter.format_romanc             C   s   |sd S |d d   }|dd    }d| }| jrD|sDd S |sN| jrv|sh| jsdd| _d| _d S | jsvd| }d | _ | _ | _ | _| _|| _| j	
| d S )Nr&    r   )isspacejoinsplitr3   r4   r6   r7   r5   r8   r   send_flowing_data)r   r   ZprespaceZ	postspacer   r   r	   r      s$     

z"AbstractFormatter.add_flowing_datac             C   sZ   |sd S | j r| jd |dd  dk| _d | _ | _ | _  | _| _| j| d S )NrY   rX   
r   )	r4   r   r]   r7   r3   r5   r6   r8   send_literal_data)r   r   r   r   r	   r      s     z"AbstractFormatter.add_literal_datac             C   s:   | j r6d | _ | _ | _ | _| _ d| _| jd d S )Nr   r&   rY   )r4   r7   r5   r6   r8   r3   r   r]   )r   r   r   r	   r      s    z!AbstractFormatter.flush_softspacec             C   s@   |r.|| j kr.| j| || _ | j| n| j| j  d S )N)r   r   new_alignmentr/   append)r   r   r   r   r	   r      s
    z AbstractFormatter.push_alignmentc             C   sH   | j r| j d= | j r2| j d  | _}| j| nd | _| jd  d S )NrX   )r/   r   r   r`   )r   r   r   r   r	   r      s    zAbstractFormatter.pop_alignmentc       
      C   s   |\}}}}| j r6d | _ | _| _ d| _| jd | jr~| jd \}}}}	|tkrZ|}|tkrf|}|tkrr|}|tkr~|	}||||f}| j| | j	| d S )Nr   r&   rY   rX   )
r4   r7   r5   r3   r   r]   r0   AS_ISra   new_font)
r   fontsizerL   bttZcsizeZcicbZcttr   r   r	   r      s$        zAbstractFormatter.push_fontc             C   s4   | j r| j d= | j r | j d }nd }| j| d S )NrX   )r0   r   rc   )r   rd   r   r   r	   r      s    zAbstractFormatter.pop_fontc             C   sB   | j | dd | j D }|s,|r,|d }| j|t| d S )Nc             S   s   g | ]}|r|qS r   r   ).0rM   r   r   r	   
<listcomp>  s    z1AbstractFormatter.push_margin.<locals>.<listcomp>rX   )r1   ra   r   
new_marginlen)r   r   fstackr   r   r	   r      s
    zAbstractFormatter.push_marginc             C   sF   | j r| j d= dd | j D }|r,|d }nd }| j|t| d S )NrX   c             S   s   g | ]}|r|qS r   r   )ri   rM   r   r   r	   rj     s    z0AbstractFormatter.pop_margin.<locals>.<listcomp>)r1   r   rk   rl   )r   rm   r   r   r   r	   r!   
  s    
zAbstractFormatter.pop_marginc             C   s   || _ | j| d S )N)r"   r   new_spacing)r   r"   r   r   r	   r#     s    zAbstractFormatter.set_spacingc             G   sZ   | j r*d | _ | _| _ d| _| jd x|D ]}| j| q0W | jt	| j d S )Nr   r&   rY   )
r4   r7   r5   r3   r   r]   r2   ra   
new_stylestuple)r   r$   Zstyler   r   r	   r%     s    
zAbstractFormatter.push_styler&   c             C   s$   | j | d = | jt| j  d S )N)r2   r   ro   rp   )r   r'   r   r   r	   r(   !  s    zAbstractFormatter.pop_stylec             C   s$   |  | _ | _d | _ | _| _d S )Nr   )r3   r7   r5   r6   r8   )r   r)   r   r   r	   r*   %  s    z"AbstractFormatter.assert_line_data)N)r&   )r&   )r+   r,   r-   r
   r   r   r   r   r?   rB   rC   r   r   r   r   r   r   r   r    r!   r#   r%   r(   r*   r   r   r   r	   r.   @   s*   
	
	
	
r.   c               @   st   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd ZdS )r   c             C   s   d S )Nr   )r   r   r   r	   r
   2  r   zNullWriter.__init__c             C   s   d S )Nr   )r   r   r   r	   flush3  r   zNullWriter.flushc             C   s   d S )Nr   )r   r   r   r   r	   r`   4  r   zNullWriter.new_alignmentc             C   s   d S )Nr   )r   rd   r   r   r	   rc   5  r   zNullWriter.new_fontc             C   s   d S )Nr   )r   r   levelr   r   r	   rk   6  r   zNullWriter.new_marginc             C   s   d S )Nr   )r   r"   r   r   r	   rn   7  r   zNullWriter.new_spacingc             C   s   d S )Nr   )r   r$   r   r   r	   ro   8  r   zNullWriter.new_stylesc             C   s   d S )Nr   )r   r   r   r   r	   r:   9  r   zNullWriter.send_paragraphc             C   s   d S )Nr   )r   r   r   r	   r9   :  r   zNullWriter.send_line_breakc             O   s   d S )Nr   )r   r   r   r   r   r	   r;   ;  r   zNullWriter.send_hor_rulec             C   s   d S )Nr   )r   r   r   r   r	   r>   <  r   zNullWriter.send_label_datac             C   s   d S )Nr   )r   r   r   r   r	   r]   =  r   zNullWriter.send_flowing_datac             C   s   d S )Nr   )r   r   r   r   r	   r_   >  r   zNullWriter.send_literal_dataN)r+   r,   r-   r
   rq   r`   rc   rk   rn   ro   r:   r9   r;   r>   r]   r_   r   r   r   r	   r   *  s   r   c               @   sd   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd Zdd ZdS )AbstractWriterc             C   s   t d|f  d S )Nznew_alignment(%r))print)r   r   r   r   r	   r`   I  s    zAbstractWriter.new_alignmentc             C   s   t d|f  d S )Nznew_font(%r))rt   )r   rd   r   r   r	   rc   L  s    zAbstractWriter.new_fontc             C   s   t d||f  d S )Nznew_margin(%r, %d))rt   )r   r   rr   r   r   r	   rk   O  s    zAbstractWriter.new_marginc             C   s   t d|f  d S )Nznew_spacing(%r))rt   )r   r"   r   r   r	   rn   R  s    zAbstractWriter.new_spacingc             C   s   t d|f  d S )Nznew_styles(%r))rt   )r   r$   r   r   r	   ro   U  s    zAbstractWriter.new_stylesc             C   s   t d|f  d S )Nzsend_paragraph(%r))rt   )r   r   r   r   r	   r:   X  s    zAbstractWriter.send_paragraphc             C   s   t d d S )Nzsend_line_break())rt   )r   r   r   r	   r9   [  s    zAbstractWriter.send_line_breakc             O   s   t d d S )Nzsend_hor_rule())rt   )r   r   r   r   r   r	   r;   ^  s    zAbstractWriter.send_hor_rulec             C   s   t d|f  d S )Nzsend_label_data(%r))rt   )r   r   r   r   r	   r>   a  s    zAbstractWriter.send_label_datac             C   s   t d|f  d S )Nzsend_flowing_data(%r))rt   )r   r   r   r   r	   r]   d  s    z AbstractWriter.send_flowing_datac             C   s   t d|f  d S )Nzsend_literal_data(%r))rt   )r   r   r   r   r	   r_   g  s    z AbstractWriter.send_literal_dataN)r+   r,   r-   r`   rc   rk   rn   ro   r:   r9   r;   r>   r]   r_   r   r   r   r	   rs   A  s   rs   c               @   sF   e Zd ZdddZdd Zdd Zd	d
 Zdd Zdd Zdd Z	dS )
DumbWriterNH   c             C   s(   |pt j| _|| _t|  |   d S )N)sysstdoutfilemaxcolr   r
   reset)r   ry   rz   r   r   r	   r
   t  s    
zDumbWriter.__init__c             C   s   d| _ d| _d S )Nr   )colatbreak)r   r   r   r	   r{   z  s    zDumbWriter.resetc             C   s    | j d|  d| _d| _d S )Nr^   r   )ry   writer|   r}   )r   r   r   r   r	   r:   ~  s    zDumbWriter.send_paragraphc             C   s   | j d d| _d| _d S )Nr^   r   )ry   r~   r|   r}   )r   r   r   r	   r9     s    zDumbWriter.send_line_breakc             O   s:   | j d | j d| j  | j d d| _d| _d S )Nr^   -r   )ry   r~   rz   r|   r}   )r   r   r   r   r   r	   r;     s
    zDumbWriter.send_hor_rulec             C   sV   | j | |d}|dkr4d| _||d d  }| }| jt| | _d| _d S )Nr^   r   r&   )ry   r~   rfindr|   
expandtabsrl   r}   )r   r   rL   r   r   r	   r_     s    
zDumbWriter.send_literal_datac             C   s   |sd S | j p|d  }| j}| j}| jj}xZ| D ]N}|rn|t| |kr^|d d}n|d |d }|| |t| }d}q8W || _|d  | _ d S )Nr   r^   rY   r&   rX   )r}   rZ   r|   rz   ry   r~   r\   rl   )r   r   r}   r|   rz   r~   Zwordr   r   r	   r]     s$     zDumbWriter.send_flowing_data)Nrv   )
r+   r,   r-   r
   r{   r:   r9   r;   r_   r]   r   r   r   r	   ru   k  s   	

ru   c             C   s   t  }t|}| d k	r t| }n$tjdd  r>ttjd }ntj}z0x*|D ]"}|dkrd|d qL|| qLW W d |tjk	r|  X |d d S )Nr&   r^   r   )	ru   r.   openrw   argvstdinr   r   close)ry   wffpliner   r   r	   test  s    



r   __main__)N)rw   warningswarnDeprecationWarningrb   r   r.   r   rs   ru   r   r+   r   r   r   r	   <module>   s   " k*C
