From 6ae2ca6901d5c5448de0edb14b824363fd728459 Mon Sep 17 00:00:00 2001 From: Griatch Date: Thu, 21 Aug 2014 09:13:53 +0200 Subject: [PATCH] Moved escape mechanism to a central location in serversessionhandler. --- src/utils/ansi.py | 10 +++++++--- src/utils/utils.py | 6 +++++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/utils/ansi.py b/src/utils/ansi.py index 3355f41cca..07d0549081 100644 --- a/src/utils/ansi.py +++ b/src/utils/ansi.py @@ -189,9 +189,6 @@ class ANSIParser(object): if not string: return '' - # remove hard-coded strings - string = self.strip_raw_codes(string) - # check cached parsings global _PARSE_CACHE cachekey = "%s-%s-%s" % (string, strip_ansi, xterm256) @@ -337,6 +334,13 @@ def parse_ansi(string, strip_ansi=False, parser=ANSI_PARSER, xterm256=False): return parser.parse_ansi(string, strip_ansi=strip_ansi, xterm256=xterm256) +def strip_raw_ansi(string, parser=ANSI_PARSER): + """ + Remove raw ansi codes from string + """ + return parser.strip_raw_codes(string) + + def raw(string): """ Escapes a string into a form which won't be colorized by the ansi parser. diff --git a/src/utils/utils.py b/src/utils/utils.py index dec72beab1..c18f99d575 100644 --- a/src/utils/utils.py +++ b/src/utils/utils.py @@ -1096,9 +1096,13 @@ class lazy_property(object): obj.__dict__[self.__name__] = value return value +_STRIP_ANSI = None _RE_CONTROL_CHAR = re.compile('[%s]' % re.escape(''.join([unichr(c) for c in range(0,32) + range(127,160)]))) def escape_control_sequences(string): """ remove non-print text sequences from string. """ - return _RE_CONTROL_CHAR.sub('', string) + global _STRIP_ANSI + if not _STRIP_ANSI: + from src.utils.ansi import strip_raw_ansi as _STRIP_ANSI + return _RE_CONTROL_CHAR.sub('', _STRIP_ANSI(string))