mò %U²Ic@s¡dZdZdkZdkZyeefWn%ej oddf\ZZnXdddgZdZdfd „ƒYZ d d „Z d d „Z d „Z dS(sText wrapping and filling. s8$Id: textwrap.py 39547 2005-09-15 17:21:59Z rhettinger $Niit TextWrappertwraptfills cBsâtZdZeiedeeƒƒZhZe dƒZ x!e e eƒD]Z e ee string Munge whitespace in text: expand tabs and convert all other whitespace characters to spaces. Eg. " foo bar baz" becomes " foo bar baz". N( RR ttextt expandtabsR t isinstancetstrt translatetwhitespace_transtunicodetunicode_whitespace_trans(RR((R t_munge_whitespacers  cCs%|ii|ƒ}td|ƒ}|S(s£_split(text : string) -> [string] Split the text to wrap into indivisible chunks. Chunks are not quite the same as words; see wrap_chunks() for full details. As an example, the text Look, goof-ball -- use the -b option! breaks into the following chunks: 'Look,', ' ', 'goof-', 'ball', ' ', '--', ' ', 'use', ' ', 'the', ' ', '-b', ' ', 'option!' N(Rt wordsep_retsplitRtchunkstfiltertNone(RRR((R t_splitƒs cCsd}|i}xk|t|ƒdjoS||ddjo0|i||ƒod||d<|d7}q|d7}qWdS(sf_fix_sentence_endings(chunks : [string]) Correct for sentence endings buried in 'chunks'. Eg. when the original text contains "... foo. Bar ...", munge_whitespace() and split() will convert that to [..., "foo.", " ", "Bar", ...] which has one too few spaces; this method simply changes the one space to two. iiRs iN(tiRtsentence_end_retpattlenRtsearch(RRRR ((R t_fix_sentence_endings’s )cCsjt||dƒ}|io+|i|d| ƒ|d||d [string] Wrap a sequence of text chunks and return a list of lines of length 'self.width' or less. (If 'break_long_words' is false, some lines may be longer than this.) Chunks correspond roughly to words and the whitespace between them: each chunk is indivisible (modulo 'break_long_words'), but a line break can come between any two chunks. Chunks should not have internal whitespace; ie. a chunk is either all whitespace or a "word". Whitespace chunks will be removed from the beginning and end of lines, but apart from that whitespace is preserved. isinvalid width %r (must be > 0)iÿÿÿÿRN(tlinesRRt ValueErrorRtreverseR'R%RtindentRR!tstriptlR(R*R+tjoin(RRR/R%R,R1R'R((R t _wrap_chunksÀs:      #cCsF|i|ƒ}|i|ƒ}|io|i|ƒn|i|ƒS(s^wrap(text : string) -> [string] Reformat the single paragraph in 'text' so it fits in lines of no more than 'self.width' columns, and return a list of wrapped lines. Tabs in 'text' are expanded with string.expandtabs(), and all other whitespace characters (including newline) are converted to space. N(RRRRRR R#R3(RRR((R R s  cCsdi|i|ƒƒS(sÞfill(text : string) -> string Reformat the single paragraph in 'text' to fit in lines of no more than 'self.width' columns, and return a new string containing the entire wrapped paragraph. s N(R2RRR(RR((R Rs(t__name__t __module__t__doc__tstringt maketranst _whitespaceR!RRtordtuspacetmaptxtretcompileRt lowercaseRtTruetFalseRRRR#R+R3RR(((R R s" "      I iFcKstd||}|i|ƒS(sÈWrap a single paragraph of text, returning a list of wrapped lines. Reformat the single paragraph in 'text' so it fits in lines of no more than 'width' columns, and return a list of wrapped lines. By default, tabs in 'text' are expanded with string.expandtabs(), and all other whitespace characters (including newline) are converted to space. See TextWrapper class for available keyword args to customize wrapping behaviour. RN(RRtkwargstwRR(RRRCRD((R R$s cKstd||}|i|ƒS(s–Fill a single paragraph of text, returning a new string. Reformat the single paragraph in 'text' to fit in lines of no more than 'width' columns, and return a new string containing the entire wrapped paragraph. As with wrap(), tabs are expanded and other whitespace characters converted to space. See TextWrapper class for available keyword args to customize wrapping behaviour. RN(RRRCRDRR(RRRCRD((R R1scCsÜ|iƒidƒ}d}xd|D]\}|iƒ}|pq"nt |ƒt |ƒ}|djo |}q"t ||ƒ}q"W|dj o@|djo3x0t t |ƒƒD]}||||| string Remove any whitespace than can be uniformly removed from the left of every line in `text`. This can be used e.g. to make triple-quoted strings line up with the left edge of screen/whatever, while still presenting it in the source code in indented form. For example: def test(): # end first line with \ to avoid the empty line! s = ''' hello world ''' print repr(s) # prints ' hello world ' print repr(dedent(s)) # prints 'hello world ' s iN(RRRR,RtmargintlinetlstriptcontentR!R/tmintrangeRR2(RR/RR,RHRFRE((R tdedent@s"   ( R6t __revision__R7R>RARBt NameErrort__all__R9RRRRK( RKRLRBR7RNRR>R9RRAR((R t?s ÿ