Workaround for Unicode display on Py2.7, fix #67

This commit is contained in:
Ram Rachum 2019-05-02 09:36:21 +03:00
parent 59d3a9d178
commit b8dec67a4f
4 changed files with 14 additions and 4 deletions

View file

@ -7,7 +7,7 @@ import collections
__VersionInfo = collections.namedtuple('VersionInfo',
('major', 'minor', 'micro'))
__version__ = '0.0.24'
__version__ = '0.0.25'
__version_info__ = __VersionInfo(*(map(int, __version__.split('.'))))
del collections, __VersionInfo # Avoid polluting the namespace

View file

@ -14,7 +14,11 @@ def get_write_and_truncate_functions(output):
if output is None:
def write(s):
stderr = sys.stderr
stderr.write(s)
try:
stderr.write(s)
except UnicodeEncodeError:
# God damn Python 2
stderr.write(utils.shitcode(s))
truncate = None
elif isinstance(output, (pycompat.PathLike, str)):
def write(s):

View file

@ -251,8 +251,8 @@ class Tracer:
# #
### Finished dealing with misplaced function definition. ##############
self.write('{indent}{now_string} {event:9} '
'{line_no:4} {source_line}'.format(**locals()))
self.write(u'{indent}{now_string} {event:9} '
u'{line_no:4} {source_line}'.format(**locals()))
if event == 'return':
return_value_repr = get_shortish_repr(arg)

View file

@ -36,3 +36,9 @@ file_reading_errors = (
OSError,
ValueError # IronPython weirdness.
)
def shitcode(s):
return ''.join(
(c if (0 < ord(c) < 256) else '?') for c in s
)