Ñò Ñ5ŽHc @s²dZddkZddkZddddddd d d g Zd d ed„Zdd d„Zed„Zed„Z d„Z d„Z d„Z dd„Z ded„ZdS(seFunctions that output text (not HTML). Helpers for filtering, formatting, and transforming strings. iÿÿÿÿNttruncatetexcerpttpluraltchop_attlchoptrchoptserieststrip_leading_whitespacetwrap_paragraphsis...cCsÙ|pdSt|ƒ|jo|S|t|ƒ}|p || |S|}x.|djo ||iƒ o|d8}qQWx-|djo||iƒo|d8}q‚W|djo || |S||d |S(syTruncate ``text`` with replacement characters. ``length`` The maximum length of ``text`` before replacement ``indicator`` If ``text`` exceeds the ``length``, this string will replace the end of the string ``whole_word`` If true, shorten the string further to avoid breaking a word in the middle. A word is defined as any string not containing whitespace. If the entire text before the break is a single word, it will have to be broken. Example:: >>> truncate('Once upon a time in a world far far away', 14) 'Once upon a...' tii(tlentisspace(ttexttlengtht indicatort whole_wordt short_lengthti((s3/usr/lib/python2.6/site-packages/webhelpers/text.pyRs"   idcCsÛ| p| o|Stid|ti|ƒ|ftiƒ}|i|ƒ}|pdS|idƒ}|idƒdjo||}n|idƒt|ƒjo||}nt |dƒo t t ƒS|SdS(soExtract an excerpt from the ``text``, or '' if the phrase isn't found. ``phrase`` Phrase to excerpt from ``text`` ``radius`` How many surrounding characters to include ``excerpt_string`` Characters surrounding entire excerpt Example:: >>> excerpt("hello my world", "my", 3) '...lo my wo...' s(.{0,%s}%s.{0,%s})R s\1iit__html__N( tretcompiletescapetItsearchtexpandtstarttendR thasattrtliteraltexcertp(R tphrasetradiustexcerpt_stringtpattmatchR((s3/usr/lib/python2.6/site-packages/webhelpers/text.pyR>s cCs;|djo |}n|}|od||fS|SdS(s¶Return the singular or plural form of a word, according to the number. Usage: >>> plural(2, "ox", "oxen") '2 oxen' >>> plural(2, "ox", "oxen", False) 'oxen' is%s %sN((tntsingularRt with_numbertform((s3/usr/lib/python2.6/site-packages/webhelpers/text.pyRbs  cCsC|i|ƒ}|djo|S|o||t|ƒ S|| S(sTruncate string ``s`` at the first occurence of ``sub``. If ``inclusive`` is true, truncate just after ``sub`` rather than at it. >>> chop_at("plutocratic brats", "rat") 'plutoc' >>> chop_at("plutocratic brats", "rat", True) 'plutocrat' iÿÿÿÿ(tfindR (tstsubt inclusivetpos((s3/usr/lib/python2.6/site-packages/webhelpers/text.pyRts  cCs(|i|ƒo|t|ƒ}n|S(s‚Chop ``sub`` off the front of ``s`` if present. >>> lchop("##This is a comment.##", "##") 'This is a comment.##' (t startswithR (R(R)((s3/usr/lib/python2.6/site-packages/webhelpers/text.pyR…scCs)|i|ƒo|t|ƒ }n|S(s€Chop ``sub`` off the end of ``s`` if present. >>> rchop("##This is a comment.##", "##") '##This is a comment.' (tendswithR (R(R)((s3/usr/lib/python2.6/site-packages/webhelpers/text.pyRscCs=g}|itƒD]}||iƒq~}di|ƒS(s²Strip the leading whitespace in all lines in ``s``. This deletes *all* leading whitespace. ``textwrap.dedent`` deletes only the whitespace common to all lines. R (t splitlinestTruetlstriptjoin(R(t_[1]txtret((s3/usr/lib/python2.6/site-packages/webhelpers/text.pyR™s0iHc Cs4t|tiƒo |}ntid|ƒ}g}|itƒ}t|ƒ}d}d}xÈ||joºt||ƒ|jo"|i||ƒ|d7}q_n|d}x.||jo ||iƒ o|d7}q²Wdi |||!ƒ}|i |ƒd}|i|ƒ|}d}q_Wdi |ƒS(s(Wrap all paragraphs in a text string to the specified width. ``width`` may also be a ``textwrap.TextWrapper`` instance, in which case it will be used to do the wrapping. This provides a way to set other options besides the width, and is more efficient when wrapping many texts. twidthiiR s N( t isinstancettextwrapt TextWrapperR.R/R tNonetappendR R1tfill( R R5twrappertresulttlinest lines_lenRRt paragraph((s3/usr/lib/python2.6/site-packages/webhelpers/text.pyR¢s0       tandcCsœt|ƒ}t|ƒ}|djodS|djo |dS|djo t}ndi|d ƒ}|d}|odpd}d||||fS( sMFormat a series for use in English text. Examples: >>> series(["A", "B", "C"]) 'A, B, and C' >>> series(["A", "B", "C"], "or") 'A, B, or C' >>> series(["A", "B", "C"], strict_commas=False) 'A, B and C' >>> series(["A", "B"]) 'A and B' >>> series(["A"]) 'A' >>> series([]) '' iR iis, iÿÿÿÿt,s %s%s %s %s(tlistR tFalseR1(titemst conjunctiont strict_commasR tnonlasttlasttcomma((s3/usr/lib/python2.6/site-packages/webhelpers/text.pyRÄs        (t__doc__RR7t__all__RDRRR/RRRRRRR(((s3/usr/lib/python2.6/site-packages/webhelpers/text.pyts(   )$   "