aboutsummaryrefslogtreecommitdiffstats
path: root/netlib
diff options
context:
space:
mode:
authorMaximilian Hils <git@maximilianhils.com>2016-07-29 19:54:44 -0700
committerMaximilian Hils <git@maximilianhils.com>2016-07-29 19:54:44 -0700
commit453436367103dd9deb693da5b5ebb18c2c2c86ce (patch)
tree4edd57812419e4d7c8f41045c43d52f27b783265 /netlib
parent63f64cd66086f302f53456f29f60b1e28c8ee178 (diff)
downloadmitmproxy-453436367103dd9deb693da5b5ebb18c2c2c86ce.tar.gz
mitmproxy-453436367103dd9deb693da5b5ebb18c2c2c86ce.tar.bz2
mitmproxy-453436367103dd9deb693da5b5ebb18c2c2c86ce.zip
add escape_single_quotes=False arg to bytes_to_escaped_str
Diffstat (limited to 'netlib')
-rw-r--r--netlib/strutils.py4
1 files changed, 3 insertions, 1 deletions
diff --git a/netlib/strutils.py b/netlib/strutils.py
index 8f27ebb7..4a46b6b1 100644
--- a/netlib/strutils.py
+++ b/netlib/strutils.py
@@ -69,7 +69,7 @@ def escape_control_characters(text, keep_spacing=True):
return text.translate(trans)
-def bytes_to_escaped_str(data, keep_spacing=False):
+def bytes_to_escaped_str(data, keep_spacing=False, escape_single_quotes=False):
"""
Take bytes and return a safe string that can be displayed to the user.
@@ -86,6 +86,8 @@ def bytes_to_escaped_str(data, keep_spacing=False):
# We always insert a double-quote here so that we get a single-quoted string back
# https://stackoverflow.com/questions/29019340/why-does-python-use-different-quotes-for-representing-strings-depending-on-their
ret = repr(b'"' + data).lstrip("b")[2:-1]
+ if not escape_single_quotes:
+ ret = re.sub(r"(?<!\\)(\\\\)*\\'", lambda m: (m.group(1) or "") + "'", ret)
if keep_spacing:
ret = re.sub(
r"(?<!\\)(\\\\)*\\([nrt])",