U e5dK@sddlZddddddgZdZGd ddZdd dZdd dZd dZedejZ edejZ ddZ dddZ e dkree ddS)N TextWrapperwrapfilldedentindentshortenz c @seZdZiZedZeD]Zeeee<qdZdZ de eZ de ddZ e dee e e d e jZ[[ [ e d e Z[ e d 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||_||_||_||_||_||_||_||_| |_| |_ | |_ | |_ dSN) widthinitial_indentsubsequent_indent expand_tabsreplace_whitespacefix_sentence_endingsbreak_long_wordsdrop_whitespacebreak_on_hyphenstabsizerr) selfrrrrrrrrrrrrr /usr/lib64/python3.8/textwrap.py__init__sszTextWrapper.__init__cCs(|jr||j}|jr$||j}|Sr)r expandtabsrr translateunicode_whitespace_transrtextrrr_munge_whitespaces   zTextWrapper._munge_whitespacecCs6|jdkr|j|}n |j|}dd|D}|S)NTcSsg|] }|r|qSrr).0crrr sz&TextWrapper._split..)r wordsep_resplitwordsep_simple_rerr#chunksrrr_splits   zTextWrapper._splitcCs\d}|jj}|t|dkrX||ddkrN|||rNd||d<|d7}q |d7}q dS)Nrr rz )sentence_end_researchlen)rr,iZ patsearchrrr_fix_sentence_endingss   z!TextWrapper._fix_sentence_endingscCs^|dkrd}n||}|jrH||dd||d|d|d<n|sZ||dS)Nr )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|j|jkrbtd||rg}d}|r|j}n|j}|jt|}|j r|d dkr|r|d=|rt|d}|||kr| | ||7}qqq|r&t|d|kr&| ||||ttt|}|j r\|r\|d dkr\|t|d8}|d=|rj|jdkst|d|jks|r|j rt|dkr|d s||kr| |d|qj|r0|d r|t|j|kr| |j| |d|q|t|d8}|d=q|rn|d}t|t|j|jkrn||j|d<q| ||jqqj|S)Nrzinvalid width %r (must be > 0)r z#placeholder too large for max widthr4r )r ValueErrorrrrr1rlstripreverserstripr5r6r9summapjoinrstrip) rr,linesrr7r8rlZ prev_linerrr _wrap_chunkss              zTextWrapper._wrap_chunkscCs||}||Sr)r$r-r"rrr _split_chunksPs zTextWrapper._split_chunkscCs$||}|jr||||Sr)rErr3rDr+rrrrVs  zTextWrapper.wrapcCsd||S)N )r@rr"rrrrdszTextWrapper.fill) r r r TTFTTTr )__name__ __module__ __qualname__r!ordZuspace _whitespacexZ word_punctZletterreescapeZ whitespaceZ nowhitespacecompileVERBOSEr(r*r/rr$r-r3r9rDrErrrrrrrsT1   !gr cKstfd|i|}||SNr)rrr#rkwargswrrrrps cKstfd|i|}||SrQ)rrrRrrrr}s cKs,tf|dd|}|d|S)Nr )rrr)rrr@r=r)rRrrrrs z^[ ]+$z(^[ ]*)(?:[^ ])cCsd}td|}t|}|D]b}|dkr0|}q||r.predicatec3s*dD]}|r|n|Vq dS)NT) splitlinesr_r`prefixr#rrprefixed_linesszindent..prefixed_linesr )r@)r#rcr`rdrrbrrs__main__z Hello there. This is indented.)r )r )N)rM__all__rKrrrrrO MULTILINErUrWrrrGprintrrrrsa 3