Merge pull request #467 from Kelketek/master

Fixes some issues with ANSIString.
This commit is contained in:
Griatch 2014-01-31 12:27:57 -08:00
commit 0d7002d6df

View file

@ -356,6 +356,8 @@ class ANSIString(unicode):
decode strings, as escapes can only be respected once.
"""
string = args[0]
if not isinstance(string, basestring):
string = str(string)
args = args[1:]
parser = kwargs.get('parser', ANSI_PARSER)
decoded = kwargs.get('decoded', False) or hasattr(string, 'raw_string')
@ -370,8 +372,8 @@ class ANSIString(unicode):
self.parser = kwargs.pop('parser', ANSI_PARSER)
super(ANSIString, self).__init__(*args, **kwargs)
self.raw_string = unicode(self)
self.clean_string = self.parser.parse_ansi(
self.raw_string, strip_ansi=True)
self.clean_string = unicode(self.parser.parse_ansi(
self.raw_string, strip_ansi=True))
self._code_indexes, self._char_indexes = self._get_indexes()
def __len__(self):
@ -554,14 +556,14 @@ def _transform(func_name):
with the resulting string.
"""
def wrapped(self, *args, **kwargs):
replacement_string = _query_super(func_name)(*args, **kwargs)
replacement_string = _query_super(func_name)(self, *args, **kwargs)
to_string = []
for index in range(0, len(self.raw_string)):
if index in self._code_indexes:
to_string.append(self.raw_string[index])
elif index in self._char_indexes:
to_string.append(replacement_string[index])
return ANSIString(''.join(to_string), decoded=True)
return ANSIString(''.join(to_string), decoded=True)
return wrapped