Merge pull request #467 from Kelketek/master
Fixes some issues with ANSIString.
This commit is contained in:
commit
0d7002d6df
1 changed files with 6 additions and 4 deletions
|
|
@ -356,6 +356,8 @@ class ANSIString(unicode):
|
||||||
decode strings, as escapes can only be respected once.
|
decode strings, as escapes can only be respected once.
|
||||||
"""
|
"""
|
||||||
string = args[0]
|
string = args[0]
|
||||||
|
if not isinstance(string, basestring):
|
||||||
|
string = str(string)
|
||||||
args = args[1:]
|
args = args[1:]
|
||||||
parser = kwargs.get('parser', ANSI_PARSER)
|
parser = kwargs.get('parser', ANSI_PARSER)
|
||||||
decoded = kwargs.get('decoded', False) or hasattr(string, 'raw_string')
|
decoded = kwargs.get('decoded', False) or hasattr(string, 'raw_string')
|
||||||
|
|
@ -370,8 +372,8 @@ class ANSIString(unicode):
|
||||||
self.parser = kwargs.pop('parser', ANSI_PARSER)
|
self.parser = kwargs.pop('parser', ANSI_PARSER)
|
||||||
super(ANSIString, self).__init__(*args, **kwargs)
|
super(ANSIString, self).__init__(*args, **kwargs)
|
||||||
self.raw_string = unicode(self)
|
self.raw_string = unicode(self)
|
||||||
self.clean_string = self.parser.parse_ansi(
|
self.clean_string = unicode(self.parser.parse_ansi(
|
||||||
self.raw_string, strip_ansi=True)
|
self.raw_string, strip_ansi=True))
|
||||||
self._code_indexes, self._char_indexes = self._get_indexes()
|
self._code_indexes, self._char_indexes = self._get_indexes()
|
||||||
|
|
||||||
def __len__(self):
|
def __len__(self):
|
||||||
|
|
@ -554,14 +556,14 @@ def _transform(func_name):
|
||||||
with the resulting string.
|
with the resulting string.
|
||||||
"""
|
"""
|
||||||
def wrapped(self, *args, **kwargs):
|
def wrapped(self, *args, **kwargs):
|
||||||
replacement_string = _query_super(func_name)(*args, **kwargs)
|
replacement_string = _query_super(func_name)(self, *args, **kwargs)
|
||||||
to_string = []
|
to_string = []
|
||||||
for index in range(0, len(self.raw_string)):
|
for index in range(0, len(self.raw_string)):
|
||||||
if index in self._code_indexes:
|
if index in self._code_indexes:
|
||||||
to_string.append(self.raw_string[index])
|
to_string.append(self.raw_string[index])
|
||||||
elif index in self._char_indexes:
|
elif index in self._char_indexes:
|
||||||
to_string.append(replacement_string[index])
|
to_string.append(replacement_string[index])
|
||||||
return ANSIString(''.join(to_string), decoded=True)
|
return ANSIString(''.join(to_string), decoded=True)
|
||||||
return wrapped
|
return wrapped
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue