Hi,
there is bug in error_reporting.py module when warning stream is used. If is used cStringIO.StringIO in python 2.x it works fine, but if is used io.BytesIO, which replace StringIO from python 2.x it crash on bad encoding in write method.
My patch fix this bug.
Here is testing code:
from docutils.core import publish_parts
from io import BytesIO
from cStringIO import StringIO
source = """
Header title
----------
"""
err_stream = StringIO()
parts = publish_parts(source=source,
writer_name='html',
settings_overrides={
'warning_stream': err_stream,
})
err_stream.seek(0)
print('errors: \n%s' % err_stream.read().decode('utf-8'))
err_stream = BytesIO()
parts = publish_parts(source=source,
writer_name='html',
settings_overrides={
'warning_stream': err_stream,
})
err_stream.seek(0)
print('errors: \n%s' % err_stream.read().decode('utf-8'))
Thank you for the bug report.
With revision 7932 Docutils now supports instances of io.BytesIO (and other stream objects expecting byte strings) in ErrorOutput instances.