mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Fix #3024, refs #3037: In Python3, application.Sphinx._log crushed when the log message cannot be encoded into console encoding.
This commit is contained in:
parent
794e0801f8
commit
6ae67f9f38
2
CHANGES
2
CHANGES
@ -8,6 +8,8 @@ Bugs fixed
|
|||||||
* #1843: Fix documentation of descriptor classes that have a custom metaclass.
|
* #1843: Fix documentation of descriptor classes that have a custom metaclass.
|
||||||
Thanks to Erik Bray.
|
Thanks to Erik Bray.
|
||||||
* #3190: util.split_docinfo fails to parse multi-line field bodies
|
* #3190: util.split_docinfo fails to parse multi-line field bodies
|
||||||
|
* #3024, #3037: In Python3, application.Sphinx._log crushed when the log message cannot
|
||||||
|
be encoded into console encoding.
|
||||||
|
|
||||||
Release 1.4.9 (released Nov 23, 2016)
|
Release 1.4.9 (released Nov 23, 2016)
|
||||||
=====================================
|
=====================================
|
||||||
|
@ -322,7 +322,9 @@ class Sphinx(object):
|
|||||||
wfile.write(message)
|
wfile.write(message)
|
||||||
except UnicodeEncodeError:
|
except UnicodeEncodeError:
|
||||||
encoding = getattr(wfile, 'encoding', 'ascii') or 'ascii'
|
encoding = getattr(wfile, 'encoding', 'ascii') or 'ascii'
|
||||||
wfile.write(message.encode(encoding, 'replace'))
|
# wfile.write accept only str, not bytes.So, we encode and replace
|
||||||
|
# non-encodable characters, then decode them.
|
||||||
|
wfile.write(message.encode(encoding, 'replace').decode(encoding))
|
||||||
if not nonl:
|
if not nonl:
|
||||||
wfile.write('\n')
|
wfile.write('\n')
|
||||||
if hasattr(wfile, 'flush'):
|
if hasattr(wfile, 'flush'):
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
:copyright: Copyright 2007-2016 by the Sphinx team, see AUTHORS.
|
:copyright: Copyright 2007-2016 by the Sphinx team, see AUTHORS.
|
||||||
:license: BSD, see LICENSE for details.
|
:license: BSD, see LICENSE for details.
|
||||||
"""
|
"""
|
||||||
|
import codecs
|
||||||
|
|
||||||
from docutils import nodes
|
from docutils import nodes
|
||||||
|
|
||||||
@ -49,21 +50,40 @@ def test_emit_with_nonascii_name_node(app, status, warning):
|
|||||||
|
|
||||||
@with_app()
|
@with_app()
|
||||||
def test_output(app, status, warning):
|
def test_output(app, status, warning):
|
||||||
|
# info with newline
|
||||||
status.truncate(0) # __init__ writes to status
|
status.truncate(0) # __init__ writes to status
|
||||||
status.seek(0)
|
status.seek(0)
|
||||||
app.info("Nothing here...")
|
app.info("Nothing here...")
|
||||||
assert status.getvalue() == "Nothing here...\n"
|
assert status.getvalue() == "Nothing here...\n"
|
||||||
|
# info without newline
|
||||||
status.truncate(0)
|
status.truncate(0)
|
||||||
status.seek(0)
|
status.seek(0)
|
||||||
app.info("Nothing here...", True)
|
app.info("Nothing here...", True)
|
||||||
assert status.getvalue() == "Nothing here..."
|
assert status.getvalue() == "Nothing here..."
|
||||||
|
|
||||||
|
# warning
|
||||||
old_count = app._warncount
|
old_count = app._warncount
|
||||||
app.warn("Bad news!")
|
app.warn("Bad news!")
|
||||||
assert warning.getvalue() == "WARNING: Bad news!\n"
|
assert warning.getvalue() == "WARNING: Bad news!\n"
|
||||||
assert app._warncount == old_count + 1
|
assert app._warncount == old_count + 1
|
||||||
|
|
||||||
|
|
||||||
|
@with_app()
|
||||||
|
def test_output_with_unencodable_char(app, status, warning):
|
||||||
|
|
||||||
|
class StreamWriter(codecs.StreamWriter):
|
||||||
|
def write(self, object):
|
||||||
|
self.stream.write(object.encode('cp1252').decode('cp1252'))
|
||||||
|
|
||||||
|
app._status = StreamWriter(status)
|
||||||
|
|
||||||
|
# info with UnicodeEncodeError
|
||||||
|
status.truncate(0)
|
||||||
|
status.seek(0)
|
||||||
|
app.info(u"unicode \u206d...")
|
||||||
|
assert status.getvalue() == "unicode ?...\n"
|
||||||
|
|
||||||
|
|
||||||
@with_app()
|
@with_app()
|
||||||
def test_extensions(app, status, warning):
|
def test_extensions(app, status, warning):
|
||||||
app.setup_extension('shutil')
|
app.setup_extension('shutil')
|
||||||
|
Loading…
Reference in New Issue
Block a user