aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libpathod/rparse.py2
-rw-r--r--libpathod/utils.py16
-rw-r--r--test/test_utils.py5
3 files changed, 21 insertions, 2 deletions
diff --git a/libpathod/rparse.py b/libpathod/rparse.py
index ab657974..ea12185b 100644
--- a/libpathod/rparse.py
+++ b/libpathod/rparse.py
@@ -22,7 +22,7 @@ class ParseException(Exception):
return "%s\n%s"%(self.s, " "*(self.col-1) + "^")
def __str__(self):
- return "%s at offset %s of %s"%(self.msg, self.col, repr(self.s))
+ return "%s at char %s"%(self.msg, self.col)
def actions_log(lst):
diff --git a/libpathod/utils.py b/libpathod/utils.py
index 1ee50b83..7a1e533f 100644
--- a/libpathod/utils.py
+++ b/libpathod/utils.py
@@ -45,10 +45,24 @@ 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 isinstance(s, unicode):
+ 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")
- s = repr(s)[1:-1]
+ s = inner_repr(s)
s = s.replace("PATHOD_MARKER_RN", "\n")
s = s.replace("PATHOD_MARKER_N", "\n")
return s
diff --git a/test/test_utils.py b/test/test_utils.py
index a8f513f8..0a48d87d 100644
--- a/test/test_utils.py
+++ b/test/test_utils.py
@@ -17,6 +17,11 @@ 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"
+
+
def test_escape_unprintables():
s = "".join([chr(i) for i in range(255)])
e = utils.escape_unprintables(s)