summaryrefslogtreecommitdiff
path: root/reporters
diff options
context:
space:
mode:
authorEmile Anclin <emile.anclin@logilab.fr>2010-10-21 14:49:23 +0200
committerEmile Anclin <emile.anclin@logilab.fr>2010-10-21 14:49:23 +0200
commitd365d7605dd42e87f42787916067faa45fb67922 (patch)
treed8706d90a9f23e8089e7d890ea1d453bebb76a30 /reporters
parent6eecca1d506d18bf080c1ffc8608b3dc4dcc9eb4 (diff)
downloadpylint-d365d7605dd42e87f42787916067faa45fb67922.tar.gz
close #48066: crash on redirecting non-ascii output
just apply patch at the tracker
Diffstat (limited to 'reporters')
-rw-r--r--reporters/__init__.py25
1 files changed, 14 insertions, 11 deletions
diff --git a/reporters/__init__.py b/reporters/__init__.py
index b0e1bd5..7156a52 100644
--- a/reporters/__init__.py
+++ b/reporters/__init__.py
@@ -16,7 +16,7 @@
http://www.logilab.fr/ -- mailto:contact@logilab.fr
"""
-import sys
+import sys, locale
CMPS = ['=', '-', '+']
@@ -36,32 +36,35 @@ class BaseReporter:
"""base class for reporters"""
extension = ''
-
+
def __init__(self, output=None):
self.linter = None
self.include_ids = None
self.section = 0
self.out = None
+ self.out_encoding = None
self.set_output(output)
-
+
def set_output(self, output=None):
"""set output stream"""
- if output is None:
- output = sys.stdout
- self.out = output
-
+ self.out = output or sys.stdout
+ self.out_encoding = (self.out.encoding or
+ locale.getdefaultlocale()[1] or
+ sys.getdefaultencoding())
+
def writeln(self, string=''):
"""write a line in the output buffer"""
- print >> self.out, string
-
+ print >> self.out, (isinstance(string, unicode) and
+ string.encode(self.out_encoding) or string)
+
def display_results(self, layout):
"""display results encapsulated in the layout tree"""
self.section = 0
if self.include_ids and hasattr(layout, 'report_id'):
layout.children[0].children[0].data += ' (%s)' % layout.report_id
self._display(layout)
-
+
def _display(self, layout):
"""display the layout"""
raise NotImplementedError()
-
+