Encoding output if it's Unicode only for python2

This commit is contained in:
Aleskarova, Dinara 2017-04-24 11:58:11 +04:00
parent 1ae5e0afe6
commit 394f21a1f0

View file

@ -1,6 +1,7 @@
"""The base class and interface for all formatting plugins.""" """The base class and interface for all formatting plugins."""
from __future__ import print_function from __future__ import print_function
import sys
class BaseFormatter(object): class BaseFormatter(object):
"""Class defining the formatter interface. """Class defining the formatter interface.
@ -166,7 +167,7 @@ class BaseFormatter(object):
def _write(self, output): def _write(self, output):
"""Handle logic of whether to use an output file or print().""" """Handle logic of whether to use an output file or print()."""
if not isinstance(output, str): if sys.version_info < (3, 0) and isinstance(output, unicode):
output = output.encode('UTF-8') output = output.encode('UTF-8')
if self.output_fd is not None: if self.output_fd is not None:
self.output_fd.write(output + self.newline) self.output_fd.write(output + self.newline)