summaryrefslogtreecommitdiffstats
path: root/cli_helpers/tabular_output/tsv_output_adapter.py
blob: 75518b370f725f1316d36c1fec2f41b5b6e35177 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# -*- coding: utf-8 -*-
"""A tsv data output adapter"""

from __future__ import unicode_literals

from .preprocessors import bytes_to_string, override_missing_value, convert_to_string
from itertools import chain
from cli_helpers.utils import replace

supported_formats = ("tsv",)
preprocessors = (override_missing_value, bytes_to_string, convert_to_string)


def adapter(data, headers, **kwargs):
    """Wrap the formatting inside a function for TabularOutputFormatter."""
    for row in chain((headers,), data):
        yield "\t".join((replace(r, (("\n", r"\n"), ("\t", r"\t"))) for r in row))