Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
arthur-zzz
noc
Commits
3da2c9ef
Commit
3da2c9ef
authored
Nov 24, 2021
by
arthur-zzz
Browse files
Fix format_table
parent
af2c47ff
Pipeline
#34265
passed with stages
in 29 minutes and 21 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
core/text.py
View file @
3da2c9ef
# ---------------------------------------------------------------------
# ---------------------------------------------------------------------
# Various text-processing utilities
# Various text-processing utilities
# ---------------------------------------------------------------------
# ---------------------------------------------------------------------
# Copyright (C) 2007-202
0
The NOC Project
# Copyright (C) 2007-202
1
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
=
[
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment