py3: rewrite stdout hack of doctest by using ui.pushbuffer()
We can't use pycompat.stdout here because the doctest runner replaces
sys.stdout with a string buffer.
py3: fix doctests in patch.py to be compatible with Python 3
We were lucky that parsepatch() could concatenate a character slice as if
it were a list of chunks.