From 88e42bab6d95eb0d1d1224c4f69caafdc03a69aa Mon Sep 17 00:00:00 2001 From: Shadab Zafar Date: Sat, 7 May 2016 23:45:03 +0530 Subject: Py3: inner_repr and escape_unprintables --- pathod/utils.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'pathod/utils.py') 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 -- cgit v1.2.3 From 22e4bc1938b74b0d0bfda7cab41b54070bcd7fb9 Mon Sep 17 00:00:00 2001 From: Shadab Zafar Date: Sun, 8 May 2016 16:20:27 +0530 Subject: Py3: Handle bytes case in inner_repr --- pathod/utils.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'pathod/utils.py') diff --git a/pathod/utils.py b/pathod/utils.py index 2f9de83d..b14535ca 100644 --- a/pathod/utils.py +++ b/pathod/utils.py @@ -60,7 +60,8 @@ 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): + if (six.PY2 and isinstance(s, unicode)) or \ + (six.PY3 and isinstance(s, bytes)): return repr(s)[2:-1] else: return repr(s)[1:-1] -- cgit v1.2.3 From daaa672d3974dfda9bfdad9c89b27e5e6237992c Mon Sep 17 00:00:00 2001 From: Shadab Zafar Date: Wed, 11 May 2016 02:09:42 +0530 Subject: Remove Py3 specific check --- pathod/utils.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'pathod/utils.py') diff --git a/pathod/utils.py b/pathod/utils.py index b14535ca..0cc77ab2 100644 --- a/pathod/utils.py +++ b/pathod/utils.py @@ -60,8 +60,7 @@ 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 \ - (six.PY3 and isinstance(s, bytes)): + if (six.PY2 and isinstance(s, unicode)) or isinstance(s, bytes): return repr(s)[2:-1] else: return repr(s)[1:-1] -- cgit v1.2.3 From 1bbb178b6a0ebd534b6b9f78299118496de6b92a Mon Sep 17 00:00:00 2001 From: Shadab Zafar Date: Wed, 25 May 2016 16:42:46 +0530 Subject: Remove inner_repr, fixup escape_unprintables --- pathod/utils.py | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) (limited to 'pathod/utils.py') 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 -- cgit v1.2.3