Menu

#130 fix encoding for warning stream writing

None
closed-fixed
nobody
python3 (1)
5
2016-01-13
2016-01-12
Ondrej Tuma
No

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'))
1 Attachments

Discussion

  • Günter Milde

    Günter Milde - 2016-01-13
    • status: open --> closed-fixed
     
  • Günter Milde

    Günter Milde - 2016-01-13

    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.

     

Log in to post a comment.

MongoDB Logo MongoDB