closes #123892 by adding errors=replace when encoding unicode strings

authorSylvain Th?nault <sylvain.thenault@logilab.fr>
changesetff86ccc61d36
branchdefault
phasepublic
hiddenno
parent revision#b87851e4b8ff fix NameError
child revision#e3df6d94fca1 consistent product naming: Pylint
files modified by this revision
ChangeLog
reporters/__init__.py
# HG changeset patch
# User Sylvain Thénault <sylvain.thenault@logilab.fr>
# Date 1365783653 -7200
# Fri Apr 12 18:20:53 2013 +0200
# Node ID ff86ccc61d36280c35049a68bbce294891458dae
# Parent b87851e4b8ff4913c87ff28bd46c770e921cd307
closes #123892 by adding errors=replace when encoding unicode strings

diff --git a/ChangeLog b/ChangeLog
@@ -20,10 +20,13 @@
1      * #123285: apply pragmas for warnings attached to lines to physical source
2        code lines
3 
4      * #123259: do not emit E0105 for yield expressions inside lambdas
5 
6 +    * #123892: don't crash when attempting to show source code line that can't
7 +      be encoded with the current locale settings
8 +
9      * Simplify checks for dangerous default values by unifying tests for all
10        different mutable compound literals.
11 
12      * Improve the description for E1124[redundant-keyword-arg]
13 
diff --git a/reporters/__init__.py b/reporters/__init__.py
@@ -80,11 +80,14 @@
14              if not isinstance(string, unicode):
15                  return string
16              encoding = (getattr(self.out, 'encoding', None) or
17                          locale.getdefaultlocale()[1] or
18                          sys.getdefaultencoding())
19 -            return string.encode(encoding)
20 +            # errors=replace, we don't want to crash when attempting to show
21 +            # source code line that can't be encoded with the current locale
22 +            # settings
23 +            return string.encode(encoding, 'replace')
24          self.encode = encode
25 
26      def writeln(self, string=''):
27          """write a line in the output buffer"""
28          print >> self.out, self.encode(string)