PY3: use six.BytesIO and six.moves.cStringIO