Fix IPython.utils.capture for Python 3