'Convert IPython prompts to python ones in a string.'

def __call__(self, ds):

    from . import globalipapp
    pyps1 = '>>>    '
    pyps2 = '...    '
    pyout = ''
    dnew = ds
    dnew = self.rps1.sub(pyps1, dnew)
    dnew = self.rps2.sub(pyps2, dnew)
    dnew = self.rout.sub(pyout, dnew)
    ip = globalipapp.get_ipython()
    out = []
    newline = out.append
    for line in dnew.splitlines():
        mps1 = self.rpyps1.match(line)
        if (mps1 is not None):
            (prompt, text) = mps1.groups()
            newline((prompt + ip.prefilter(text, False)))
            continue
        mps2 = self.rpyps2.match(line)
        if (mps2 is not None):
            (prompt, text) = mps2.groups()
            newline((prompt + ip.prefilter(text, True)))
            continue
        newline(line)
    newline('')
    return '\n'.join(out)
