a
    zeK                     @   s   d dl Z g d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reed dS )    N)TextWrapperwrapfilldedentindentshortenz	
 c                
   @   s   e Zd Zi ZedZeD ]Zeeee< q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ltwsZnwsz(%s+)z[a-z][\.\!\?][\"\']?\ZF    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.9/textwrap.py__init__s   s    zTextWrapper.__init__c                 C   s(   | j r|| j}| jr$|| j}|S r   )r   
expandtabsr   r   	translateunicode_whitespace_transr   textr   r   r   _munge_whitespace   s
    zTextWrapper._munge_whitespacec                 C   s6   | j du r| j|}n| j|}dd |D }|S )NTc                 S   s   g | ]}|r|qS r   r   ).0cr   r   r   
<listcomp>       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}|t|d k rX||d  dkrN||| rNd||d < |d7 }q|d7 }q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 urb| jdkr8| j}n| j}t|t| j  | j krbtd|  |rg }d}|r| j}n| j}| j t| }| j	r|d 
 dkr|r|d= |rt|d }|| |kr||  ||7 }qqq|r&t|d |kr&| |||| ttt|}| j	r\|r\|d 
 dkr\|t|d 8 }|d= |rj| jd u st|d | jk s|r| j	rt|dkr|d 
 s||kr||d|  qj|r0|d 
 r|t| j |kr|| j ||d|  q|t|d 8 }|d= q|rn|d  }t|t| j | j krn|| j |d< q||| j   qqj|S )Nr   zinvalid width %r (must be > 0)r	   z#placeholder too large for max widthr6   r   )r   
ValueErrorr   r   r   r3   r   lstripreverser   stripr7   r8   r;   summapjoinrstrip)	r   r.   linesr   r9   r:   r   lZ	prev_liner   r   r   _wrap_chunks   s    



 


zTextWrapper._wrap_chunksc                 C   s   |  |}| |S r   )r%   r/   r#   r   r   r   _split_chunksP  s    
zTextWrapper._split_chunksc                 C   s$   |  |}| jr| | | |S r   )rG   r   r5   rF   r-   r   r   r   r   V  s    	

zTextWrapper.wrapc                 C   s   d | |S )N
)rB   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escape
whitespaceZnowhitespacecompileVERBOSEr*   r,   r1   r   r%   r/   r5   r;   rF   rG   r   r   r   r   r   r   r      sR   1
          !gr   r   c                 K   s   t f d|i|}|| S Nr   )r   r   r$   r   kwargswr   r   r   r   p  s    
r   c                 K   s   t f d|i|}|| S rT   )r   r   rU   r   r   r   r   }  s    	r   c                 K   s,   t f |dd|}|d|   S )Nr	   )r   r   r   )r   r   rB   r?   r+   rU   r   r   r   r     s    r   z^[ 	]+$z(^[ 	]*)(?:[^ 	
])c                 C   s   d }t d| } t| }|D ]b}|d u r0|}q||r<q||rL|}qtt||D ]$\}\}}||krZ|d | } qqZqdr|r| dD ]}q|rtd| d| } | S )Nr   r   rH   z(?m)^)	_whitespace_only_resub_leading_whitespace_refindall
startswith	enumeratezipr+   rO   )r$   Zmarginindentsr   r4   rN   yliner   r   r   r     s(    


r   c                    s,    d u rdd   fdd}d | S )Nc                 S   s   |   S r   )r?   ra   r   r   r   	predicate  s    zindent.<locals>.predicatec                  3   s*    dD ]}  | r|  n| V  q
d S )NT)
splitlinesrb   rc   prefixr$   r   r   prefixed_lines  s    zindent.<locals>.prefixed_linesr   )rB   )r$   rf   rc   rg   r   re   r   r     s    r   __main__z Hello there.
  This is indented.)r   )r   )N)rO   __all__rM   r   r   r   r   rR   	MULTILINErX   rZ   r   r   rI   printr   r   r   r   <module>   s     a

3
