diff options
Diffstat (limited to 'libpathod')
-rw-r--r-- | libpathod/rparse.py | 2 | ||||
-rw-r--r-- | libpathod/utils.py | 16 |
2 files changed, 16 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 |