summaryrefslogtreecommitdiffstats
path: root/cli_helpers/tabular_output/tsv_output_adapter.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2021-01-30 08:13:47 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2021-02-07 10:48:06 +0000
commit57bc0d56d7e741e1e99d96f14e7ab93232440a16 (patch)
tree0d4631d7416ba98b7a414dc825419afd5b177be0 /cli_helpers/tabular_output/tsv_output_adapter.py
parentInitial commit. (diff)
downloadcli-helpers-57bc0d56d7e741e1e99d96f14e7ab93232440a16.tar.xz
cli-helpers-57bc0d56d7e741e1e99d96f14e7ab93232440a16.zip
Adding upstream version 2.1.0.upstream/2.1.0
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.py16
1 files changed, 16 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..5cdc585
--- /dev/null
+++ b/cli_helpers/tabular_output/tsv_output_adapter.py
@@ -0,0 +1,16 @@
+# -*- 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))