diff options
author | Shadab Zafar <dufferzafar0@gmail.com> | 2016-05-25 16:42:46 +0530 |
---|---|---|
committer | Shadab Zafar <dufferzafar0@gmail.com> | 2016-05-26 23:07:37 +0530 |
commit | 1bbb178b6a0ebd534b6b9f78299118496de6b92a (patch) | |
tree | e7e955a2e177ba313c489566118e4f1c8b25bbe7 | |
parent | 1699592f092b5f616ef1aa33b611ec6dabe7b255 (diff) | |
download | mitmproxy-1bbb178b6a0ebd534b6b9f78299118496de6b92a.tar.gz mitmproxy-1bbb178b6a0ebd534b6b9f78299118496de6b92a.tar.bz2 mitmproxy-1bbb178b6a0ebd534b6b9f78299118496de6b92a.zip |
Remove inner_repr, fixup escape_unprintables
-rw-r--r-- | pathod/utils.py | 22 | ||||
-rw-r--r-- | test/pathod/test_utils.py | 12 |
2 files changed, 8 insertions, 26 deletions
diff --git a/pathod/utils.py b/pathod/utils.py index 0cc77ab2..8c6d6290 100644 --- a/pathod/utils.py +++ b/pathod/utils.py @@ -2,7 +2,7 @@ import os import sys import netlib.utils -import six +from netlib.utils import bytes_to_escaped_str SIZE_UNITS = dict( @@ -55,27 +55,13 @@ def xrepr(s): return repr(s)[1:-1] -def inner_repr(s): - """ - Returns the inner portion of a string or unicode repr (i.e. without the - quotes) - """ - if (six.PY2 and isinstance(s, unicode)) or isinstance(s, bytes): - return repr(s)[2:-1] - else: - return repr(s)[1:-1] - - def escape_unprintables(s): """ Like inner_repr, but preserves line breaks. """ - s = s.replace("\r\n", "PATHOD_MARKER_RN") - s = s.replace("\n", "PATHOD_MARKER_N") - if six.PY2: - s = inner_repr(s) - else: - s = s.encode('unicode_escape').decode('ascii') + s = s.replace(b"\r\n", b"PATHOD_MARKER_RN") + s = s.replace(b"\n", b"PATHOD_MARKER_N") + s = bytes_to_escaped_str(s) s = s.replace("PATHOD_MARKER_RN", "\n") s = s.replace("PATHOD_MARKER_N", "\n") return s diff --git a/test/pathod/test_utils.py b/test/pathod/test_utils.py index 4e891ad9..32ba3bdf 100644 --- a/test/pathod/test_utils.py +++ b/test/pathod/test_utils.py @@ -1,6 +1,8 @@ from pathod import utils import tutils +import six + def test_membool(): m = utils.MemBool() @@ -27,14 +29,8 @@ def test_data_path(): tutils.raises(ValueError, utils.data.path, "nonexistent") -def test_inner_repr(): - assert utils.inner_repr("\x66") == "\x66" - assert utils.inner_repr(u"foo") == "foo" - assert utils.inner_repr(b"foo") == "foo" - - def test_escape_unprintables(): s = "".join([chr(i) for i in range(255)]) - e = utils.escape_unprintables(s) + e = utils.escape_unprintables(six.b(s)) assert e.encode('ascii') - assert not "PATHOD_MARKER" in e + assert "PATHOD_MARKER" not in e |