diff options
author | Shadab Zafar <dufferzafar0@gmail.com> | 2016-05-07 23:45:03 +0530 |
---|---|---|
committer | Shadab Zafar <dufferzafar0@gmail.com> | 2016-05-26 23:07:37 +0530 |
commit | 88e42bab6d95eb0d1d1224c4f69caafdc03a69aa (patch) | |
tree | 4bb8dc152ba805304deee8e0f0ed0cba8e7d604e /pathod/utils.py | |
parent | f3932b27dafbf040c60556de7c5739148ffd67a6 (diff) | |
download | mitmproxy-88e42bab6d95eb0d1d1224c4f69caafdc03a69aa.tar.gz mitmproxy-88e42bab6d95eb0d1d1224c4f69caafdc03a69aa.tar.bz2 mitmproxy-88e42bab6d95eb0d1d1224c4f69caafdc03a69aa.zip |
Py3: inner_repr and escape_unprintables
Diffstat (limited to 'pathod/utils.py')
-rw-r--r-- | pathod/utils.py | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/pathod/utils.py b/pathod/utils.py index d1e2dd00..2f9de83d 100644 --- a/pathod/utils.py +++ b/pathod/utils.py @@ -2,6 +2,8 @@ import os import sys import netlib.utils +import six + SIZE_UNITS = dict( b=1024 ** 0, @@ -58,7 +60,7 @@ def inner_repr(s): Returns the inner portion of a string or unicode repr (i.e. without the quotes) """ - if isinstance(s, unicode): + if six.PY2 and isinstance(s, unicode): return repr(s)[2:-1] else: return repr(s)[1:-1] @@ -70,7 +72,10 @@ def escape_unprintables(s): """ s = s.replace("\r\n", "PATHOD_MARKER_RN") s = s.replace("\n", "PATHOD_MARKER_N") - s = inner_repr(s) + if six.PY2: + s = inner_repr(s) + else: + s = s.encode('unicode_escape').decode('ascii') s = s.replace("PATHOD_MARKER_RN", "\n") s = s.replace("PATHOD_MARKER_N", "\n") return s |