Ñò
Ñ5ŽHc @ s² d Z d d k Z d d k Z d d d d d d d d
d g Z d d
e d „ Z d d
d „ Z e d „ Z e d „ Z d „ Z
d „ Z d „ Z d d „ Z
d e d „ Z d S( se Functions that output text (not HTML).
Helpers for filtering, formatting, and transforming strings.
iÿÿÿÿNt truncatet excerptt pluralt chop_att lchopt rchopt seriest strip_leading_whitespacet wrap_paragraphsi s ...c C sÙ | p d St | ƒ | j o | S| t | ƒ } | p
| | | S| } x. | d j o | | i ƒ o | d 8} qQ Wx- | d j o | | i ƒ o | d 8} q‚ W| d j o
| | | S| | d | S( sy Truncate ``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...'
t i i ( t lent isspace( t textt lengtht indicatort
whole_wordt short_lengtht i( ( s3 /usr/lib/python2.6/site-packages/webhelpers/text.pyR s"
id c C sÛ | p | o | St i d | t i | ƒ | f t i ƒ } | i | ƒ } | p d S| i d ƒ } | i d ƒ d j o | | } n | i d ƒ t | ƒ j o | | } n t | d ƒ o t
t ƒ S| Sd S( so Extract 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 \1i i t __html__N( t ret compilet escapet It searcht expandt startt endR
t hasattrt literalt excertp( R t phraset radiust excerpt_stringt patt matchR ( ( s3 /usr/lib/python2.6/site-packages/webhelpers/text.pyR > s c C s; | d j o
| } n | } | o d | | f S| Sd S( 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'
i s %s %sN( ( t nt singularR t with_numbert form( ( s3 /usr/lib/python2.6/site-packages/webhelpers/text.pyR b s
c C sC | i | ƒ } | d j o | S| o | | t | ƒ S| | S( s Truncate 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ÿÿÿÿ( t findR
( t st subt inclusivet pos( ( s3 /usr/lib/python2.6/site-packages/webhelpers/text.pyR t s
c C s( | 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 … s c C s) | i | ƒ o | t | ƒ } n | S( s€ Chop ``sub`` off the end of ``s`` if present.
>>> rchop("##This is a comment.##", "##")
'##This is a comment.'
( t endswithR
( R( R) ( ( s3 /usr/lib/python2.6/site-packages/webhelpers/text.pyR s c C s= g } | i t ƒ D] } | | i ƒ q ~ } d i | ƒ 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
splitlinest Truet lstript join( R( t _[1]t xt ret( ( s3 /usr/lib/python2.6/site-packages/webhelpers/text.pyR ™ s 0iH c C s4 t | t i ƒ o
| } n t i d | ƒ } g } | i t ƒ } t | ƒ } d } d } xÈ | | j oº t | | ƒ | j o" | i | | ƒ | d 7} q_ n | d } x. | | j o | | i ƒ o | d 7} q² Wd i | | | !ƒ } | i
| ƒ d } | i | ƒ | } d } q_ Wd i | ƒ 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.
t widthi i R s
N( t
isinstancet textwrapt TextWrapperR. R/ R
t Nonet appendR R1 t fill( R R5 t wrappert resultt linest lines_lenR R t paragraph( ( s3 /usr/lib/python2.6/site-packages/webhelpers/text.pyR ¢ s0
t andc C sœ t | ƒ } t | ƒ } | d j o d S| d j o | d S| d j o
t } n d i | d ƒ } | d } | o d p d } d | | | | f S( sM Format 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([])
''
i R i i s , iÿÿÿÿt ,s
%s%s %s %s( t listR
t FalseR1 ( t itemst conjunctiont
strict_commasR
t nonlastt lastt comma( ( s3 /usr/lib/python2.6/site-packages/webhelpers/text.pyR Ä s
( t __doc__R R7 t __all__RD R R R/ R R R R R R R ( ( ( s3 /usr/lib/python2.6/site-packages/webhelpers/text.pyt