From 3da2c9ef51fa0b9a27fed2733c066e93cf39ac37 Mon Sep 17 00:00:00 2001 From: arthur-zzz Date: Wed, 24 Nov 2021 10:43:58 +0000 Subject: [PATCH 1/2] Fix format_table --- core/text.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/core/text.py b/core/text.py index d741387c33..4f450e37cb 100644 --- a/core/text.py +++ b/core/text.py @@ -1,7 +1,7 @@ # --------------------------------------------------------------------- # Various text-processing utilities # --------------------------------------------------------------------- -# Copyright (C) 2007-2020 The NOC Project +# Copyright (C) 2007-2021 The NOC Project # See LICENSE for details # --------------------------------------------------------------------- @@ -12,6 +12,9 @@ from itertools import zip_longest # Third-party modules from typing import List, Union, Iterable +# NOC modules +from noc.core.comp import smart_text + rx_header_start = re.compile(r"^\s*[-=]+[\s\+]+[-=]+") rx_col = re.compile(r"^([\s\+]*)([\-]+|[=]+)") @@ -530,7 +533,7 @@ def format_table(widths, data, sep=" ", hsep=" "): # Calculate column widths widths = list(widths) for row in data: - widths = [max(x, len(y)) for x, y in zip(widths, row)] + widths = [max(x, len(smart_text(y, errors="replace"))) for x, y in zip(widths, row)] # Build print mask mask = sep.join("%%-%ds" % w for w in widths) out = [ -- GitLab From cf164eb6576139835959cf1aaaa23ef4dd4c02f0 Mon Sep 17 00:00:00 2001 From: arthur-zzz Date: Wed, 24 Nov 2021 13:44:04 +0000 Subject: [PATCH 2/2] just use str --- core/text.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/core/text.py b/core/text.py index 4f450e37cb..522a1edf97 100644 --- a/core/text.py +++ b/core/text.py @@ -12,9 +12,6 @@ from itertools import zip_longest # Third-party modules from typing import List, Union, Iterable -# NOC modules -from noc.core.comp import smart_text - rx_header_start = re.compile(r"^\s*[-=]+[\s\+]+[-=]+") rx_col = re.compile(r"^([\s\+]*)([\-]+|[=]+)") @@ -533,7 +530,7 @@ def format_table(widths, data, sep=" ", hsep=" "): # Calculate column widths widths = list(widths) for row in data: - widths = [max(x, len(smart_text(y, errors="replace"))) for x, y in zip(widths, row)] + widths = [max(x, len(str(y))) for x, y in zip(widths, row)] # Build print mask mask = sep.join("%%-%ds" % w for w in widths) out = [ -- GitLab