diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-04 17:37:29 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-04 17:37:29 +0000 |
commit | de734e6e5777abb6f8f16f94166ecd3dbe179421 (patch) | |
tree | fff61580a08934083aab3043d228c2f484f6f844 /cli_helpers/tabular_output/tsv_output_adapter.py | |
parent | Initial commit. (diff) | |
download | cli-helpers-de734e6e5777abb6f8f16f94166ecd3dbe179421.tar.xz cli-helpers-de734e6e5777abb6f8f16f94166ecd3dbe179421.zip |
Adding upstream version 2.3.0.upstream/2.3.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'cli_helpers/tabular_output/tsv_output_adapter.py')
-rw-r--r-- | cli_helpers/tabular_output/tsv_output_adapter.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/cli_helpers/tabular_output/tsv_output_adapter.py b/cli_helpers/tabular_output/tsv_output_adapter.py new file mode 100644 index 0000000..75518b3 --- /dev/null +++ b/cli_helpers/tabular_output/tsv_output_adapter.py @@ -0,0 +1,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)) |