Commit 3da2c9ef authored by arthur-zzz's avatar arthur-zzz
Browse files

Fix format_table

parent af2c47ff
Pipeline #34265 passed with stages
in 29 minutes and 21 seconds
# --------------------------------------------------------------------- # ---------------------------------------------------------------------
# Various text-processing utilities # Various text-processing utilities
# --------------------------------------------------------------------- # ---------------------------------------------------------------------
# Copyright (C) 2007-2020 The NOC Project # Copyright (C) 2007-2021 The NOC Project
# See LICENSE for details # See LICENSE for details
# --------------------------------------------------------------------- # ---------------------------------------------------------------------
...@@ -12,6 +12,9 @@ from itertools import zip_longest ...@@ -12,6 +12,9 @@ from itertools import zip_longest
# Third-party modules # Third-party modules
from typing import List, Union, Iterable from typing import List, Union, Iterable
# NOC modules
from noc.core.comp import smart_text
rx_header_start = re.compile(r"^\s*[-=]+[\s\+]+[-=]+") rx_header_start = re.compile(r"^\s*[-=]+[\s\+]+[-=]+")
rx_col = re.compile(r"^([\s\+]*)([\-]+|[=]+)") rx_col = re.compile(r"^([\s\+]*)([\-]+|[=]+)")
...@@ -530,7 +533,7 @@ def format_table(widths, data, sep=" ", hsep=" "): ...@@ -530,7 +533,7 @@ def format_table(widths, data, sep=" ", hsep=" "):
# Calculate column widths # Calculate column widths
widths = list(widths) widths = list(widths)
for row in data: 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 # Build print mask
mask = sep.join("%%-%ds" % w for w in widths) mask = sep.join("%%-%ds" % w for w in widths)
out = [ out = [
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment