From 42664b05103d0f4a7ed272301051d58d6e8f3737 Mon Sep 17 00:00:00 2001 From: imarom Date: Sun, 29 Jan 2017 17:49:53 +0200 Subject: code review - cont. Signed-off-by: imarom --- .../stl/trex_stl_lib/utils/text_opts.py | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'scripts/automation/trex_control_plane/stl/trex_stl_lib/utils') diff --git a/scripts/automation/trex_control_plane/stl/trex_stl_lib/utils/text_opts.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/utils/text_opts.py index 3ffd07e2..477d81a6 100644 --- a/scripts/automation/trex_control_plane/stl/trex_stl_lib/utils/text_opts.py +++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/utils/text_opts.py @@ -133,16 +133,12 @@ def underline(text): # apply attribute on each non-empty line def text_attribute(text, attribute): - if isinstance(text, str): - return "{start}{txt}{stop}".format(start=TEXT_CODES[attribute]['start'], - txt=text, - stop=TEXT_CODES[attribute]['end']) - elif isinstance(text, unicode): - return u"{start}{txt}{stop}".format(start=TEXT_CODES[attribute]['start'], - txt=text, - stop=TEXT_CODES[attribute]['end']) - else: - raise Exception("not a string") + return '\n'.join(['{start}{txt}{end}'.format( + start = TEXT_CODES[attribute]['start'], + txt = line, + end = TEXT_CODES[attribute]['end']) + if line else '' for line in ('%s' % text).split('\n')]) + FUNC_DICT = {'blue': blue, 'bold': bold, -- cgit 1.2.3-korg