Fixed issue with repr encoding (fixes davidhalter/jedi-vim#94)

This commit is contained in:
Danilo Bargen
2013-02-14 21:10:06 +01:00
parent 3ab2b0a244
commit ea9a667425
4 changed files with 10 additions and 6 deletions

View File

@@ -182,3 +182,8 @@ try:
except ImportError: except ImportError:
# python 2.5 # python 2.5
import simplejson as json import simplejson as json
try:
encoding = sys.stdout.encoding
except AttributeError:
encoding = 'ascii'

View File

@@ -68,7 +68,7 @@ backtracking algorithm.
.. todo:: nonlocal statement, needed or can be ignored? (py3k) .. todo:: nonlocal statement, needed or can be ignored? (py3k)
""" """
from _compatibility import next, hasattr, is_py3k, unicode from _compatibility import next, hasattr, is_py3k, unicode, utf8
import sys import sys
import itertools import itertools

View File

@@ -25,7 +25,7 @@ import re
import tokenize import tokenize
from _compatibility import next, literal_eval, cleandoc, Python3Method, \ from _compatibility import next, literal_eval, cleandoc, Python3Method, \
property property, encoding
import common import common
import debug import debug
@@ -92,9 +92,8 @@ class Simple(Base):
self._end_pos = value self._end_pos = value
def __repr__(self): def __repr__(self):
code = self.get_code().replace('\n', ' ') code = self.get_code().replace('\n', ' ').encode(encoding, 'replace')
return "<%s: %s@%s>" % \ return '<%s: %s@%s>' % (type(self).__name__, code, self.start_pos[0])
(type(self).__name__, code, self.start_pos[0])
class Scope(Simple): class Scope(Simple):

View File

@@ -265,7 +265,7 @@ class TestRegression(TestBase):
completions1 = self.complete(s1) completions1 = self.complete(s1)
assert 'strip' in [c.word for c in completions1] assert 'strip' in [c.word for c in completions1]
s2 = utf8('#-*- coding: utf-8 -*-\nclass Person():\n name = "é"\n\nPerson().name.') s2 = utf8('#-*- coding: utf-8 -*-\nclass Person():\n name = "é"\n\nPerson().name.')
completions = self.complete(s2) completions2 = self.complete(s2)
assert 'strip' in [c.word for c in completions2] assert 'strip' in [c.word for c in completions2]
def test_os_nowait(self): def test_os_nowait(self):