3 \fL@sddlZddddddgZdZGd ddZdd dZdd dZd dZejdejZ ejdejZ ddZ dddZ e dkree ddS)N TextWrapperwrapfilldedentindentshortenz c @seZdZiZedZxeD]Zeeee<qWdZdZ de j eZ de ddZ e jdee e e d e jZ[[ [ e jd e Z[ e jd Zd%dddddZddZddZddZddZddZdd Zd!d"Zd#d$ZdS)&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) ) ))ZwpltZwsZnwsz(%s+)z[a-z][\.\!\?][\"\']?\ZFTFz [...]) max_lines placeholderc  CsL||_||_||_||_||_||_||_||_| |_| |_ | |_ | |_ dS)N) widthinitial_indentsubsequent_indent expand_tabsreplace_whitespacefix_sentence_endingsbreak_long_wordsdrop_whitespacebreak_on_hyphenstabsizerr) selfrrrrrrrrrrrrr /usr/lib64/python3.6/textwrap.py__init__sszTextWrapper.__init__cCs(|jr|j|j}|jr$|j|j}|S)N)r expandtabsrr translateunicode_whitespace_trans)rtextrrr_munge_whitespaces   zTextWrapper._munge_whitespacecCs6|jdkr|jj|}n |jj|}dd|D}|S)NTcSsg|] }|r|qSrr).0crrr sz&TextWrapper._split..)r wordsep_resplitwordsep_simple_re)rr!chunksrrr_splits   zTextWrapper._splitcCs`d}|jj}xN|t|dkrZ||ddkrP|||rPd||d<|d7}q|d7}qWdS)Nrr rz )sentence_end_researchlen)rr)iZ patsearchrrr_fix_sentence_endingss   z!TextWrapper._fix_sentence_endingscCs^|dkrd}n||}|jrH|j|dd||d|d|d<n|sZ|j|jdS)Nr r1r1)rappendpop)rZreversed_chunkscur_linecur_lenrZ space_leftrrr_handle_long_words zTextWrapper._handle_long_wordc Csg}|jdkrtd|j|jdk rb|jdkr8|j}n|j}t|t|jj|jkrbtd|jx&|rg}d}|r|j}n|j}|jt|}|j r|dj dkr|r|d=x:|rt|d}|||kr|j |j ||7}qPqW|r.t|d |kr.|j ||||ttt|}|j rd|rd|d j dkrd|t|d 8}|d =|rn|jdkst|d|jks| s|j rt|dkr|dj r||kr|j |dj|qnx|r<|d j r"|t|j|kr"|j |j|j |dj|P|t|d8}|d=qW|rz|dj}t|t|j|jkrz||j|d<P|j ||jjPqnW|S)Nrzinvalid width %r (must be > 0)r z#placeholder too large for max widthr r1r1r1r1r1r1r1r1r1r1r1r1)r ValueErrorrrrr.rlstripreverserstripr2r3r6summapjoinrstrip) rr)linesrr4r5rlZ prev_linerrr _wrap_chunkssp              zTextWrapper._wrap_chunkscCs|j|}|j|S)N)r"r*)rr!rrr _split_chunksPs zTextWrapper._split_chunkscCs$|j|}|jr|j||j|S)N)rBrr0rA)rr!r)rrrrVs  zTextWrapper.wrapcCsdj|j|S)N )r=r)rr!rrrrdszTextWrapper.fill) r r r TTFTTTr )__name__ __module__ __qualname__r ordZuspace _whitespacexZ word_punctZletterreescapeZ whitespaceZ nowhitespacecompileVERBOSEr&r(r,rr"r*r0r6rArBrrrrrrrsH1   !gr cKstfd|i|}|j|S)Nr)rr)r!rkwargswrrrrps cKstfd|i|}|j|S)Nr)rr)r!rrNrOrrrr}s cKs,tf|dd|}|jdj|jjS)Nr )rrr)rrr=r:r')r!rrNrOrrrrs z^[ ]+$z(^[ ]*)(?:[^ ])cCsd}tjd|}tj|}x||D]t}|dkr2|}q |j|r>q |j|rN|}q xDtt||D]"\}\}}||kr^|d|}Pq^W|dt|}q Wdr|rx|jdD]}qW|rt jd|d|}|S)Nr rrCz(?m)^) _whitespace_only_resub_leading_whitespace_refindall startswith enumeratezipr.r'rJ)r!Zmarginindentsrr/rIylinerrrrs*      cs,dkrddfdd}dj|S)NcSs|jS)N)r:)rYrrr predicateszindent..predicatec3s.x(jdD]}|r |n|Vq WdS)NT) splitlines)rY)rZprefixr!rrprefixed_linesszindent..prefixed_linesr )r=)r!r\rZr]r)rZr\r!rrs__main__z Hello there. This is indented.)r )r )N)rJ__all__rHrrrrrL MULTILINErPrRrrrDprintrrrrsa 5