³ò ¡l‡Jc@sídZdZddkZddkZyeefWn%ej oddf\ZZnXdddgZd Zdfd „ƒYZ d d „Z d d „Z ei dei ƒZei dei ƒZd„ZedjoedƒGHndS(sText wrapping and filling. s8$Id: textwrap.py 46863 2006-06-11 19:42:51Z tim.peters $iÿÿÿÿNiit TextWrappertwraptfills c BsâeZdZeiedeeƒƒ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". ( Rt expandtabsR t isinstancetstrt translatetwhitespace_transtunicodetunicode_whitespace_trans(R ttext((s/sys/lib/python/textwrap.pyt_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(t wordsep_retsplittfiltertNone(R Rtchunks((s/sys/lib/python/textwrap.pyt_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(tsentence_end_retlentsearch(R Rtitpat((s/sys/lib/python/textwrap.pyt_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ÿÿÿÿR( Rt ValueErrortreverseRRRtstripR$R%R*tjoin(R RtlinesR'R(tindentRtl((s/sys/lib/python/textwrap.pyt _wrap_chunksÀs4        #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. (RRR R"R2(R RR((s/sys/lib/python/textwrap.pyR 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 (R.R(R R((s/sys/lib/python/textwrap.pyRs(t__name__t __module__t__doc__tstringt maketranst _whitespaceRRRtordtuspacetmaptxtretcompileRt lowercaseRtTruetFalseR RRR"R*R2RR(((s/sys/lib/python/textwrap.pyR s2"         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. R(RR(RRtkwargstw((s/sys/lib/python/textwrap.pyR$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. R(RR(RRRBRC((s/sys/lib/python/textwrap.pyR1s s^[ ]+$s(^[ ]*)(?:[^ ])cCsd}tid|ƒ}ti|ƒ}xZ|D]R}|djo |}q.|i|ƒoq.|i|ƒo |}q.d}Pq.WdoQ|oJxG|idƒD]2}| p$|i|ƒptd||f‚q¢Wn|otid|d|ƒ}n|S(s9Remove any common leading whitespace from every line in `text`. This can be used to make triple-quoted strings line up with the left edge of the display, while still presenting them in the source code in indented form. Note that tabs and spaces are both treated as whitespace, but they are not equal: the lines " hello" and " hello" are considered to have no common leading whitespace. (This behaviour is new in Python 2.5; older versions of this module incorrectly expanded tabs before searching for common leading whitespace.) Ris sline = %r, margin = %rs(?m)^N( Rt_whitespace_only_retsubt_leading_whitespace_retfindallt startswithRtAssertionErrorR=(RtmargintindentsR0tline((s/sys/lib/python/textwrap.pytdedentCs*   t__main__s Hello there. This is indented.(R5t __revision__R6R=R@RAt NameErrort__all__R8RRRR>t MULTILINERDRFRMR3(((s/sys/lib/python/textwrap.pyss" ÿ  0