summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoritsme <itsme@xs4all.nl>2021-07-07 18:25:48 +0200
committeritsme <itsme@xs4all.nl>2021-07-07 18:25:48 +0200
commit3de7b59f8073d1874ae14b23c0b191451f3db788 (patch)
tree53897c66d049cf7af576e9c43117b0ed00305e6d
parentae535cadc68bb1968fdf5b860e4ec8d194608852 (diff)
hexdump: added 'strescape' function
-rw-r--r--hexdump.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/hexdump.py b/hexdump.py
index aeb8c88..cbba3c9 100644
--- a/hexdump.py
+++ b/hexdump.py
@@ -32,3 +32,13 @@ def hexdump(ofs, data):
32 32
33def tohex(data): 33def tohex(data):
34 return b2a_hex(data).decode('ascii') 34 return b2a_hex(data).decode('ascii')
35
36def strescape(txt):
37 if type(txt)==bytes:
38 txt = txt.decode('cp1251')
39 txt = txt.replace("\\", "\\\\")
40 txt = txt.replace("\n", "\\n")
41 txt = txt.replace("\r", "\\r")
42 txt = txt.replace("\t", "\\t")
43 txt = txt.replace("\"", "\\\"")
44 return txt