2025-02-07 00:47:33 +01:00
|
|
|
# -*- 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
|
|
|
|
|
2025-02-07 00:48:48 +01:00
|
|
|
supported_formats = ("tsv",)
|
2025-02-07 00:47:33 +01:00
|
|
|
preprocessors = (override_missing_value, bytes_to_string, convert_to_string)
|
|
|
|
|
2025-02-07 00:48:48 +01:00
|
|
|
|
2025-02-07 00:47:33 +01:00
|
|
|
def adapter(data, headers, **kwargs):
|
|
|
|
"""Wrap the formatting inside a function for TabularOutputFormatter."""
|
|
|
|
for row in chain((headers,), data):
|
2025-02-07 00:48:48 +01:00
|
|
|
yield "\t".join((replace(r, (("\n", r"\n"), ("\t", r"\t"))) for r in row))
|