'Stolen from PyPy\'s pure Python string implementation, tweaked for
ANSIString.
PyPy is distributed under the MIT licence.
http://opensource.org/licenses/MIT'

def rsplit(self, by=None, maxsplit=(-1)):

    res = []
    end = len(self)
    drop_spaces = (by is None)
    if drop_spaces:
        by = '    '
    bylen = len(by)
    if (bylen == 0):
        raise ValueError('empty    separator')
    while (maxsplit != 0):
        next = self._clean_string.rfind(by, 0, end)
        if (next < 0):
            break
        res.append(self[(next + bylen):end])
        end = next
        maxsplit -= 1
    res.append(self[:end])
    res.reverse()
    if drop_spaces:
        return [part for part in res if (part != '')]
    return res
