From 86173182799a92562570026cfdbbcbbbc6d70924 Mon Sep 17 00:00:00 2001 From: Sebastien Luttringer <sebastien.luttringer@smartjog.com> Date: Thu, 8 Dec 2011 20:00:22 +0100 Subject: [PATCH] fix bug of color substituion a bug occur with string like "#l##c#R#R#". This is due to order of processing colors. Now use re.sub --- installsystems/printer.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/installsystems/printer.py b/installsystems/printer.py index 0b7eceb..2398de1 100644 --- a/installsystems/printer.py +++ b/installsystems/printer.py @@ -8,6 +8,7 @@ Install Systems Printer module import sys import os +import re import installsystems NOCOLOR = False @@ -48,11 +49,8 @@ def out(message="", fd=sys.stdout, endl=os.linesep, flush=True): Print message colorised in fd ended by endl ''' # color subsitution - for c in COLOR: - if not fd.isatty() or NOCOLOR: - message = message.replace("#%s#" % c, "") - else: - message = message.replace("#%s#" % c, COLOR[c]) + color_pattern = "#(%s)#" % "|".join(COLOR) + message = re.sub(color_pattern, lambda obj: COLOR[obj.group(1)], message) # convert unicode into str before write # this can cause issue on python 2.6 if type(message) == unicode: -- GitLab