404

[ Avaa Bypassed ]




Upload:

Command:

botdev@18.119.116.139: ~ $
# Copyright (C) 2013  Lars Wirzenius
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.


'''Simplistic text re-formatter.

This module format text, paragraph by paragraph, so it is somewhat
nice-looking, with no line too long, and short lines joined. In
other words, like what the textwrap library does. However, it
extends textwrap by recognising bulleted lists.

'''


import textwrap


class Paragraph(object):

    def __init__(self):
        self._lines = []

    def append(self, line):
        self._lines.append(line)

    def _oneliner(self):
        return ' '.join(' '.join(x.split()) for x in self._lines)

    def fill(self, width):
        filled = textwrap.fill(self._oneliner(), width=width)
        return filled


class BulletPoint(Paragraph):

    def fill(self, width):
        text = self._oneliner()
        assert text.startswith('* ')
        filled = textwrap.fill(text[2:], width=width - 2)
        lines = ['  %s' % x for x in filled.splitlines(True)]
        lines[0] = '* %s' % lines[0][2:]
        return ''.join(lines)


class EmptyLine(Paragraph):

    def fill(self, width):
        return ''


class TextFormat(object):

    def __init__(self, width=78):
        self._width = width

    def format(self, text):
        '''Return input string, but formatted nicely.'''

        filled_paras = []
        for para in self._paragraphs(text):
            filled_paras.append(para.fill(self._width))
        filled = '\n'.join(filled_paras)
        if text and not filled.endswith('\n'):
            filled += '\n'
        return filled

    def _paragraphs(self, text):

        def is_empty(line):
            return line.strip() == ''

        def is_bullet(line):
            return line.startswith('* ')

        def is_continuation(line):
            return line.startswith(' ')

        current = None
        in_list = False
        for line in text.splitlines(True):
            if in_list and is_continuation(line):
                assert current is not None
                current.append(line)
            elif is_bullet(line):
                if current:
                    yield current
                    if not in_list:
                        yield EmptyLine()
                current = BulletPoint()
                current.append(line)
                in_list = True
            elif is_empty(line):
                if current:
                    yield current
                    yield EmptyLine()
                current = None
                in_list = False
            else:
                if in_list:
                    yield current
                    yield EmptyLine()
                    current = None

                if not current:
                    current = Paragraph()
                current.append(line)
                in_list = False

        if current:
            yield current

Filemanager

Name Type Size Permission Actions
__init__.py File 1.63 KB 0644
__init__.pyc File 1.36 KB 0644
app.py File 23.3 KB 0644
app.pyc File 24.72 KB 0644
app_tests.py File 11.56 KB 0644
app_tests.pyc File 21.51 KB 0644
fmt.py File 3.43 KB 0644
fmt.pyc File 4.29 KB 0644
fmt_tests.py File 2.06 KB 0644
fmt_tests.pyc File 2.72 KB 0644
genman.py File 6.82 KB 0644
genman.pyc File 6.37 KB 0644
hook.py File 2.39 KB 0644
hook.pyc File 2.52 KB 0644
hook_tests.py File 2.73 KB 0644
hook_tests.pyc File 3.67 KB 0644
hookmgr.py File 1.56 KB 0644
hookmgr.pyc File 1.64 KB 0644
hookmgr_tests.py File 2.05 KB 0644
hookmgr_tests.pyc File 2.71 KB 0644
plugin.py File 3.95 KB 0644
plugin.pyc File 4.48 KB 0644
plugin_tests.py File 1.96 KB 0644
plugin_tests.pyc File 3.06 KB 0644
pluginmgr.py File 5.54 KB 0644
pluginmgr.pyc File 5.88 KB 0644
pluginmgr_tests.py File 3.52 KB 0644
pluginmgr_tests.pyc File 5.89 KB 0644
runcmd.py File 11.38 KB 0644
runcmd.pyc File 8.82 KB 0644
runcmd_tests.py File 6.21 KB 0644
runcmd_tests.pyc File 8.76 KB 0644
settings.py File 29.27 KB 0644
settings.pyc File 31.88 KB 0644
settings_tests.py File 22.37 KB 0644
settings_tests.pyc File 31.32 KB 0644
util.py File 2.83 KB 0644
util.pyc File 2.5 KB 0644
version.py File 60 B 0644
version.pyc File 228 B 0644