예제 #1
0
 def test_wrap(self):
     '''Test that text wrapping works'''
     tools.eq_(display.wrap(self.u_mixed), [self.u_mixed])
     tools.eq_(display.wrap(self.u_paragraph), self.u_paragraph_out)
     tools.eq_(display.wrap(self.utf8_paragraph), self.u_paragraph_out)
     tools.eq_(display.wrap(self.u_mixed_para), self.u_mixed_para_out)
     tools.eq_(display.wrap(self.u_mixed_para, width=57,
         initial_indent='    ', subsequent_indent='----'),
         self.u_mixed_para_57_initial_subsequent_out)
예제 #2
0
 def test_wrap(self):
     '''Test that text wrapping works'''
     tools.eq_(display.wrap(self.u_mixed), [self.u_mixed])
     tools.eq_(display.wrap(self.u_paragraph), self.u_paragraph_out)
     tools.eq_(display.wrap(self.utf8_paragraph), self.u_paragraph_out)
     tools.eq_(display.wrap(self.u_mixed_para), self.u_mixed_para_out)
     tools.eq_(display.wrap(self.u_mixed_para, width=57,
         initial_indent='    ', subsequent_indent='----'),
         self.u_mixed_para_57_initial_subsequent_out)
예제 #3
0
def wrap_text(text, width):
    """
    Wrap text paragraphs to the given character width while preserving newlines.
    """
    out = []
    for paragraph in text.splitlines():
        # Wrap returns an empty list when paragraph is a newline. In order to
        # preserve newlines we substitute a list containing an empty string.
        lines = wrap(paragraph, width=width) or ['']
        out.extend(lines)
    return out
예제 #4
0
파일: helpers.py 프로젝트: Ferada/rtv
def wrap_text(text, width):
    """
    Wrap text paragraphs to the given character width while preserving newlines.
    """
    out = []
    for paragraph in text.splitlines():
        # Wrap returns an empty list when paragraph is a newline. In order to
        # preserve newlines we substitute a list containing an empty string.
        lines = wrap(paragraph, width=width) or ['']
        out.extend(lines)
    return out
예제 #5
0
def utf8_text_wrap(text, width=70, initial_indent='', subsequent_indent=''):
    '''**Deprecated** Similar to :func:`textwrap.wrap` but understands
    :term:`utf-8` data and doesn't screw up lists/blocks/etc

    Use :func:`kitchen.text.display.wrap` instead
    '''
    warnings.warn('kitchen.text.utf8.utf8_text_wrap is deprecated.  Use'
        ' kitchen.text.display.wrap instead',
        DeprecationWarning, stacklevel=2)

    as_bytes = not isunicodestring(text)

    text = to_unicode(text)
    lines = wrap(text, width=width, initial_indent=initial_indent,
            subsequent_indent=subsequent_indent)
    if as_bytes:
        lines = [to_bytes(m) for m in lines]

    return lines
예제 #6
0
def utf8_text_wrap(text, width=70, initial_indent='', subsequent_indent=''):
    '''Deprecated.

    Use :func:`~kitchen.text.display.wrap` instead
    '''
    warnings.warn(_('kitchen.text.utf8.utf8_text_wrap is deprecated.  Use'
                    ' kitchen.text.display.wrap instead'),
                  DeprecationWarning,
                  stacklevel=2)

    as_bytes = not isinstance(text, unicode)

    text = to_unicode(text)
    lines = wrap(text,
                 width=width,
                 initial_indent=initial_indent,
                 subsequent_indent=subsequent_indent)
    if as_bytes:
        lines = [to_bytes(m) for m in lines]

    return lines