This Page

mmf.utils.text

DocWrapper([width, initial_indent, ...]) Wrap text in a document, processing each paragraph individually.
trim(docstring) Docstring trimmer from PEP0257

Inheritance diagram for mmf.utils.text:

Inheritance diagram of mmf.utils.text

Provides a subclass of textwrap.TextWrapper that allows for multiple paragraphs. Based on http://code.activestate.com/recipes/358228/

class mmf.utils.text.DocWrapper(width=70, initial_indent='', subsequent_indent='', expand_tabs=True, replace_whitespace=True, fix_sentence_endings=False, break_long_words=True, drop_whitespace=True, break_on_hyphens=True)[source]

Bases: textwrap.TextWrapper

Wrap text in a document, processing each paragraph individually.

>>> DocWrapper(initial_indent='  ').fill("Hi")
'  Hi'
>>> a = '''This is an example of how to use a
...                        long multiline string to document a
...                        parameter.  This paragraph will be
...                        wrapped, but special formatting should
...                        be preserved if it is indented:
...                           1) A series of points
...                           2) Here is a longer point
...    
...                        You can use paragraphs too!  They will
...                        also be wrapped for you.'''
>>> print DocWrapper(width=66).fill(a)
This is an example of how to use a long multiline string to
document a parameter.  This paragraph will be wrapped, but special
formatting should be preserved if it is indented:
   1) A series of points
   2) Here is a longer point

You can use paragraphs too!  They will also be wrapped for you.
>>> b = ('''This is an example of a docstring which has some
...        formatting:
...            1) Here is an indented point w/o wrapping.
...            2) Another indented point.  This one is a''' + 
...     ''' very long line.  This should *not* be wrapped.
...     ''')
>>> print DocWrapper(width=66).fill(b) 
This is an example of a docstring which has some formatting:
    1) Here is an indented point w/o wrapping.
    2) Another indented point.  This one is a very long line.  This should *not* be wrapped.

Methods

fill((text : string) -> string) Reformat the single paragraph in ‘text’ to fit in lines of no
wrap(text) Override textwrap.TextWrapper to process ‘text’ properly when
wrap(text)[source]

Override textwrap.TextWrapper to process ‘text’ properly when multiple paragraphs present

mmf.utils.text.trim(docstring)[source]

Docstring trimmer from PEP0257

>>> trim('')
''