Esempio n. 1
0
def preformatted_text(source: str) -> str:
    """Renders preformatted text box"""
    environ.abort_thread()

    if not source:
        return ''

    source = render_utils.html_escape(source)

    return '<pre class="preformatted-textbox">{text}</pre>'.format(
        text=str(textwrap.dedent(source)))
Esempio n. 2
0
def preformatted_text(source: str) -> str:
    """Renders preformatted text box"""
    environ.abort_thread()

    if not source:
        return ''

    source = render_utils.html_escape(source)

    return '<pre class="preformatted-textbox">{text}</pre>'.format(
        text=str(textwrap.dedent(source))
    )
Esempio n. 3
0
def status(
        data: dict,
        values: bool = True,
        types: bool = True
) -> str:
    """

    :param data:
    :param values:
    :param types:
    :return:
    """
    environ.abort_thread()

    out = []
    keys = list(data.keys())
    keys.sort()

    for key in keys:
        value = data[key]
        value_type = getattr(
            value,
            '__class__',
            {'__name__': 'Unknown'}
        ).__name__

        if hasattr(value, 'head'):
            try:
                value = value.head(5)
            except Exception:
                pass
        elif isinstance(value, dict):
            temp_value = []
            for k, v in value.items():
                temp_value.append('{}: {}'.format(k, v))
            value = '\n'.join(temp_value)
        elif isinstance(value, (list, tuple)):
            value = '\n'.join(['{}'.format(v) for v in value])

        value = '<pre>{}</pre>'.format(
            render_utils.html_escape('{}'.format(value))[:600]
        )

        out.append(templating.render_template(
            'status-variable.template.html',
            name=key,
            values=values,
            types=types,
            type=value_type,
            value=value
        ))

    return ''.join(out)
Esempio n. 4
0
def text(value: str) -> str:
    """

    :param value:
    :return:
    """
    environ.abort_thread()

    value = render_utils.html_escape(value)
    lines = str(value).strip().split('\n')
    paragraph_separator = '</p><p class="plaintextbox">'

    # Convert empty lines into paragraph separators
    for index, line in enumerate(lines):
        lines[index] = line.strip() or paragraph_separator

    return '<p class="plaintextbox">{text}</p>'.format(text=' '.join(lines))
Esempio n. 5
0
def text(value: str) -> str:
    """

    :param value:
    :return:
    """
    environ.abort_thread()

    value = render_utils.html_escape(value)
    lines = str(value).strip().split('\n')
    paragraph_separator = '</p><p class="plaintextbox">'

    # Convert empty lines into paragraph separators
    for index, line in enumerate(lines):
        lines[index] = line.strip() or paragraph_separator

    return '<p class="plaintextbox">{text}</p>'.format(text=' '.join(lines))
Esempio n. 6
0
def status(data: dict, values: bool = True, types: bool = True) -> str:
    """

    :param data:
    :param values:
    :param types:
    :return:
    """
    environ.abort_thread()

    out = []
    keys = list(data.keys())
    keys.sort()

    for key in keys:
        value = data[key]
        value_type = getattr(value, '__class__', {
            '__name__': 'Unknown'
        }).__name__

        if hasattr(value, 'head'):
            try:
                value = value.head(5)
            except Exception:
                pass
        elif isinstance(value, dict):
            temp_value = []
            for k, v in value.items():
                temp_value.append('{}: {}'.format(k, v))
            value = '\n'.join(temp_value)
        elif isinstance(value, (list, tuple)):
            value = '\n'.join(['{}'.format(v) for v in value])

        value = '<pre>{}</pre>'.format(
            render_utils.html_escape('{}'.format(value))[:600])

        out.append(
            templating.render_template('status-variable.template.html',
                                       name=key,
                                       values=values,
                                       types=types,
                                       type=value_type,
                                       value=value))

    return ''.join(out)
Esempio n. 7
0
def text(value: str) -> str:
    """

    :param value:
    :return:
    """

    environ.abort_thread()

    value = render_utils.html_escape(value)
    lines = str(value).strip().split('\n')

    for index, line in enumerate(lines):
        l = line.strip()
        if len(l) < 1:
            l = '</p><p class="plaintextbox">'
        lines[index] = l

    return '<p class="plaintextbox">{text}</p>'.format(text=' '.join(lines))