mirror of
https://github.com/cool-RR/PySnooper.git
synced 2026-07-19 09:23:48 +00:00
Workaround for Unicode display on Py2.7, fix #67
This commit is contained in:
parent
59d3a9d178
commit
b8dec67a4f
4 changed files with 14 additions and 4 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue