Merge pull request #458 from Kelketek/master
Made __radd__ work properly for ANSIString.
This commit is contained in:
commit
cf39c955a0
1 changed files with 9 additions and 3 deletions
|
|
@ -377,6 +377,12 @@ class ANSIString(unicode):
|
||||||
def __len__(self):
|
def __len__(self):
|
||||||
return len(self.clean_string)
|
return len(self.clean_string)
|
||||||
|
|
||||||
|
def __radd__(self, other):
|
||||||
|
if not isinstance(other, basestring):
|
||||||
|
return NotImplemented
|
||||||
|
return ANSIString(self.raw_string + getattr(
|
||||||
|
other, 'raw_string', other), decoded=True)
|
||||||
|
|
||||||
def __getslice__(self, i, j):
|
def __getslice__(self, i, j):
|
||||||
return self.__getitem__(slice(i, j))
|
return self.__getitem__(slice(i, j))
|
||||||
|
|
||||||
|
|
@ -528,7 +534,7 @@ def _on_raw(func_name):
|
||||||
except IndexError:
|
except IndexError:
|
||||||
pass
|
pass
|
||||||
result = _query_super(func_name)(self, *args, **kwargs)
|
result = _query_super(func_name)(self, *args, **kwargs)
|
||||||
if isinstance(result, unicode):
|
if isinstance(result, basestring):
|
||||||
return ANSIString(result, decoded=True)
|
return ANSIString(result, decoded=True)
|
||||||
return result
|
return result
|
||||||
return wrapped
|
return wrapped
|
||||||
|
|
@ -559,8 +565,8 @@ for func_name in [
|
||||||
'rfind', 'rindex']:
|
'rfind', 'rindex']:
|
||||||
setattr(ANSIString, func_name, _query_super(func_name))
|
setattr(ANSIString, func_name, _query_super(func_name))
|
||||||
for func_name in [
|
for func_name in [
|
||||||
'__mul__', '__mod__', '__add__', 'expandtabs',
|
'__mul__', '__mod__', '__add__', 'expandtabs', '__rmul__', 'join',
|
||||||
'__rmul__', 'join', 'decode', 'replace', 'format']:
|
'decode', 'replace', 'format']:
|
||||||
setattr(ANSIString, func_name, _on_raw(func_name))
|
setattr(ANSIString, func_name, _on_raw(func_name))
|
||||||
for func_name in [
|
for func_name in [
|
||||||
'capitalize', 'translate', 'lower', 'upper', 'swapcase']:
|
'capitalize', 'translate', 'lower', 'upper', 'swapcase']:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue