B
    u9a&L  ã               @   sŒ   d dl Z ddddddgZdZG d	d„ dƒZddd„Zddd„Zdd„ Ze  de j¡Z	e  de j¡Z
dd„ Zddd„Zedkrˆeedƒƒ dS )é    NÚTextWrapperÚwrapÚfillÚdedentÚindentÚshortenz	
 c            
   @   sæ   e Zd Zi ZedƒZxeD ]Zeeeeƒ< qW dZdZ	de
 e¡ Zdedd…  Ze
 dee	eed	œ e
j¡Z[[	[e
 d
e ¡Z[e
 d¡Zd%dd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S )&r   ú z[\w!"\'&.,?]z[^\d\W]z[%s]z[^é   Naº  
        ( # any whitespace
          %(ws)s+
        | # em-dash between words
          (?<=%(wp)s) -{2,} (?=\w)
        | # word, possibly hyphenated
          %(nws)s+? (?:
            # hyphenated word
              -(?: (?<=%(lt)s{2}-) | (?<=%(lt)s-%(lt)s-))
              (?= %(lt)s -? %(lt)s)
            | # end of word
              (?=%(ws)s|\Z)
            | # em-dash
              (?<=%(wp)s) (?=-{2,}\w)
            )
        ))ZwpÚltZwsZnwsz(%s+)z[a-z][\.\!\?][\"\']?\ZéF   Ú TFé   z [...])Ú	max_linesÚplaceholderc            C   sL   || _ || _|| _|| _|| _|| _|| _|| _|	| _|
| _	|| _
|| _d S )N)ÚwidthÚinitial_indentÚsubsequent_indentÚexpand_tabsÚreplace_whitespaceÚfix_sentence_endingsÚbreak_long_wordsÚdrop_whitespaceÚbreak_on_hyphensÚtabsizer   r   )Úselfr   r   r   r   r   r   r   r   r   r   r   r   © r   ú/usr/lib/python3.7/textwrap.pyÚ__init__s   s    zTextWrapper.__init__c             C   s(   | j r| | j¡}| jr$| | j¡}|S )N)r   Ú
expandtabsr   r   Ú	translateÚunicode_whitespace_trans)r   Útextr   r   r   Ú_munge_whitespace’   s
    zTextWrapper._munge_whitespacec             C   s6   | j dkr| j |¡}n| j |¡}dd„ |D ƒ}|S )NTc             S   s   g | ]}|r|‘qS r   r   )Ú.0Úcr   r   r   ú
<listcomp>³   s    z&TextWrapper._split.<locals>.<listcomp>)r   Ú
wordsep_reÚsplitÚwordsep_simple_re)r   r!   Úchunksr   r   r   Ú_split    s
    
zTextWrapper._splitc             C   s`   d}| j j}xN|t|ƒd k rZ||d  dkrP||| ƒrPd||d < |d7 }q|d7 }qW d S )Nr   r	   r   z  é   )Úsentence_end_reÚsearchÚlen)r   r)   ÚiZ	patsearchr   r   r   Ú_fix_sentence_endings¶   s    	
z!TextWrapper._fix_sentence_endingsc             C   s^   |dk rd}n|| }| j rH| |d d |… ¡ |d |d … |d< n|sZ| | ¡ ¡ d S )Nr	   éÿÿÿÿ)r   ÚappendÚpop)r   Zreversed_chunksÚcur_lineÚcur_lenr   Z
space_leftr   r   r   Ú_handle_long_wordÈ   s    
zTextWrapper._handle_long_wordc       	      C   s”  g }| j dkrtd| j  ƒ‚| jd k	rb| jdkr8| j}n| j}t|ƒt| j ¡ ƒ | j krbtdƒ‚| ¡  x"|rŽg }d}|rˆ| j}n| j}| j t|ƒ }| j	r¼|d  
¡ dkr¼|r¼|d= x:|röt|d ƒ}|| |krò| | ¡ ¡ ||7 }q¾P q¾W |r.t|d ƒ|kr.|  ||||¡ ttt|ƒƒ}| j	rd|rd|d  
¡ dkrd|t|d ƒ8 }|d= |rn| jd ks¼t|ƒd | jk s¼|r²| j	rÒt|ƒdkrÒ|d  
¡ sÒ||krÒ| |d |¡ ¡ qnx¶|r8|d  
¡ r|t| jƒ |kr| | j¡ | |d |¡ ¡ P |t|d ƒ8 }|d= qÔW |rv|d  ¡ }t|ƒt| jƒ | j krv|| j |d< P | || j ¡  ¡ P qnW |S )Nr   zinvalid width %r (must be > 0)r	   z#placeholder too large for max widthr1   r   )r   Ú
ValueErrorr   r   r   r.   r   ÚlstripÚreverser   Ústripr2   r3   r6   ÚsumÚmapÚjoinÚrstrip)	r   r)   Úlinesr   r4   r5   r   ÚlZ	prev_liner   r   r   Ú_wrap_chunksé   sp    




 
zTextWrapper._wrap_chunksc             C   s   |   |¡}|  |¡S )N)r"   r*   )r   r!   r   r   r   Ú_split_chunksP  s    
zTextWrapper._split_chunksc             C   s$   |   |¡}| jr|  |¡ |  |¡S )N)rB   r   r0   rA   )r   r!   r)   r   r   r   r   V  s    	

zTextWrapper.wrapc             C   s   d  |  |¡¡S )NÚ
)r=   r   )r   r!   r   r   r   r   d  s    zTextWrapper.fill)
r   r   r   TTFTTTr   )Ú__name__Ú
__module__Ú__qualname__r    ÚordZuspaceÚ_whitespaceÚxZ
word_punctZletterÚreÚescapeZ
whitespaceZnowhitespaceÚcompileÚVERBOSEr&   r(   r,   r   r"   r*   r0   r6   rA   rB   r   r   r   r   r   r   r      sH   1


         !gr   c             K   s   t f d|i|—Ž}| | ¡S )Nr   )r   r   )r!   r   ÚkwargsÚwr   r   r   r   p  s    
c             K   s   t f d|i|—Ž}| | ¡S )Nr   )r   r   )r!   r   rN   rO   r   r   r   r   }  s    	c             K   s,   t f |ddœ|—Ž}| d |  ¡  ¡ ¡¡S )Nr	   )r   r   r   )r   r   r=   r:   r'   )r!   r   rN   rO   r   r   r   r   ‰  s    z^[ 	]+$z(^[ 	]*)(?:[^ 	
])c             C   s¾   d }t  d| ¡} t | ¡}xl|D ]d}|d kr2|}q | |¡r>q | |¡rN|}q x4tt||ƒƒD ]"\}\}}||kr^|d |… }P q^W q W dr¤|r¤x|  d¡D ]}qœW |rºt d| d| ¡} | S )Nr   r   rC   z(?m)^)	Ú_whitespace_only_reÚsubÚ_leading_whitespace_reÚfindallÚ
startswithÚ	enumerateÚzipr'   rJ   )r!   ZmarginÚindentsr   r/   rI   ÚyÚliner   r   r   r   ž  s(    




c                s,   ˆ d krdd„ ‰ ‡ ‡‡fdd„}d  |ƒ ¡S )Nc             S   s   |   ¡ S )N)r:   )rY   r   r   r   Ú	predicateÚ  s    zindent.<locals>.predicatec              3   s.   x(ˆ  d¡D ]} ˆ | ƒr ˆ|  n| V  qW d S )NT)Ú
splitlines)rY   )rZ   Úprefixr!   r   r   Úprefixed_linesÝ  s    zindent.<locals>.prefixed_linesr   )r=   )r!   r\   rZ   r]   r   )rZ   r\   r!   r   r   Ñ  s    Ú__main__z Hello there.
  This is indented.)r   )r   )N)rJ   Ú__all__rH   r   r   r   r   rL   Ú	MULTILINErP   rR   r   r   rD   Úprintr   r   r   r   Ú<module>   s     a

3
