From 2a744a4e53403b1fd47decc4d98594d452d30821 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Falc=C3=A3o?= Date: Wed, 11 Aug 2010 02:04:08 -0300 Subject: [PATCH] improving the #{up} regex --- couleur.py | 4 ++-- test_file_filter.py | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/couleur.py b/couleur.py index 90df1f4..8eda97d 100644 --- a/couleur.py +++ b/couleur.py @@ -57,9 +57,9 @@ def ignore_colors(string): up_count_regex = re.compile(ur'[#][{]up[}]') up_count = len(up_count_regex.findall(string)) or 1 - expression = u'^([#][{]up[}])+(?P.*\\n){%d}' % up_count + expression = u'^(?P.*)([#][{]up[}])+(.*\\n){%d}' % up_count up_supress_regex = re.compile(expression, re.MULTILINE) - string = up_supress_regex.sub('', string) + string = up_supress_regex.sub('\g', string) for attr in re.findall("[#][{]on[:](\w+)[}]", string): string = string.replace("#{on:%s}" % attr, "") diff --git a/test_file_filter.py b/test_file_filter.py index a041cb3..74d5815 100644 --- a/test_file_filter.py +++ b/test_file_filter.py @@ -109,8 +109,8 @@ def test_supress_up_when_ignoring_colors(): io = StringIO() couleur.proxy(io).enable() couleur.proxy(io).ignore() - io.write("#{up}but this is invisible\n") - assert_equals('', io.getvalue()) + io.write("This is visible#{up}but this is invisible\n") + assert_equals('This is visible', io.getvalue()) def test_supress_up_when_ignoring_colors_as_many_times_needed(): "file-like filter output: supress #{up} as many times as needed" @@ -118,9 +118,9 @@ def test_supress_up_when_ignoring_colors_as_many_times_needed(): io = StringIO() couleur.proxy(io).enable() couleur.proxy(io).ignore() - io.write("#{up}#{up}#{up}#{up}\n" \ + io.write("This is visible#{up}#{up}#{up}#{up}\n" \ " Line one supressed\n" \ " Line two supressed\n" \ " Line three supressed\n") - assert_equals('', io.getvalue()) + assert_equals('This is visible', io.getvalue())