From 3a7df1615f0c30420f3de6af20a4c519447b5d15 Mon Sep 17 00:00:00 2001 From: milde Date: Tue, 6 Nov 2012 13:49:27 +0000 Subject: [PATCH] Fix opening binary files under Py3k (thanks to Dominic Fitzpatrick). git-svn-id: https://docutils.svn.sourceforge.net/svnroot/docutils/trunk/docutils@7536 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- HISTORY.txt | 1 + docutils/io.py | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/HISTORY.txt b/HISTORY.txt index c114ec3d3..20730689c 100644 --- a/HISTORY.txt +++ b/HISTORY.txt @@ -33,6 +33,7 @@ Changes Since 0.9.1 - FileInput/FileOutput: no system-exit on IOError. The `handle_io_errors` option is ignored and will be removed in a future release. - Fix Py3k error writing to stdout with encoding differing from default. + - Fix opening binary files under Py3k (thanks to Dominic Fitzpatrick). * docutils/parsers/rst/directives/misc.py diff --git a/docutils/io.py b/docutils/io.py index b5d2be3a4..80dced637 100644 --- a/docutils/io.py +++ b/docutils/io.py @@ -297,7 +297,7 @@ class FileOutput(Output): mode = 'w' """The mode argument for `open()`.""" - # 'wb' for binary (e.g. OpenOffice) files. + # 'wb' for binary (e.g. OpenOffice) files (see also `BinaryFileOutput`). # (Do not use binary mode ('wb') for text files, as this prevents the # conversion of newlines to the system specific default.) @@ -346,7 +346,7 @@ class FileOutput(Output): def open(self): # Specify encoding in Python 3. - if sys.version_info >= (3,0): + if sys.version_info >= (3,0) and 'b' not in self.mode: kwargs = {'encoding': self.encoding, 'errors': self.error_handler} else: -- 2.11.4.GIT