diff --git a/IPython/nbconvert/writers/files.py b/IPython/nbconvert/writers/files.py index 35aca20..1e3e7d2 100644 --- a/IPython/nbconvert/writers/files.py +++ b/IPython/nbconvert/writers/files.py @@ -1,17 +1,7 @@ -""" -Contains writer for writing nbconvert output to filesystem. -""" -#----------------------------------------------------------------------------- -#Copyright (c) 2013, the IPython Development Team. -# -#Distributed under the terms of the Modified BSD License. -# -#The full license is in the file COPYING.txt, distributed with this software. -#----------------------------------------------------------------------------- +"""Contains writer for writing nbconvert output to filesystem.""" -#----------------------------------------------------------------------------- -# Imports -#----------------------------------------------------------------------------- +# Copyright (c) IPython Development Team. +# Distributed under the terms of the Modified BSD License. import io import os @@ -19,6 +9,7 @@ import glob from IPython.utils.traitlets import Unicode from IPython.utils.path import link_or_copy +from IPython.utils.py3compat import unicode_type from .base import WriterBase @@ -110,6 +101,11 @@ class FilesWriter(WriterBase): # Write conversion results. self.log.info("Writing %i bytes to %s", len(output), dest) - with io.open(dest, 'w', encoding='utf-8') as f: - f.write(output) + if isinstance(output, unicode_type): + with io.open(dest, 'w', encoding='utf-8') as f: + f.write(output) + else: + with io.open(dest, 'wb') as f: + f.write(output) + return dest