diff --git a/memory_profiler.py b/memory_profiler.py index e03b313..3621324 100644 --- a/memory_profiler.py +++ b/memory_profiler.py @@ -48,13 +48,11 @@ if PY2: import __builtin__ as builtins + to_str = lambda x: x from future_builtins import filter else: import builtins - - - def unicode(x, *args): - return str(x) + to_str = lambda x: str(x) # .. get available packages .. try: @@ -778,7 +776,7 @@ def show_results(prof, stream=None, precision=1): mem = u'' inc = u'' tmp = template.format(lineno, mem, inc, all_lines[lineno - 1]) - stream.write(unicode(tmp, 'UTF-8')) + stream.write(to_str(tmp)) stream.write(u'\n\n') diff --git a/test/test_stream_unicode.py b/test/test_stream_unicode.py new file mode 100644 index 0000000..8c80d27 --- /dev/null +++ b/test/test_stream_unicode.py @@ -0,0 +1,14 @@ +# -*- coding: utf-8 -*- + +from memory_profiler import profile + +f = open('/dev/null', 'w') +@profile(stream=f) +def test_unicode(txt): + # test when unicode is present + txt = txt.replace (u"ی", u"ي") #Arabic Yah = ي + return txt + + +if __name__ == '__main__': + test_unicode (u"ایست")