diff options
| -rw-r--r-- | hexdump.py | 10 | 
1 files changed, 10 insertions, 0 deletions
| @@ -32,3 +32,13 @@ def hexdump(ofs, data): | |||
| 32 | 32 | ||
| 33 | def tohex(data): | 33 | def tohex(data): | 
| 34 | return b2a_hex(data).decode('ascii') | 34 | return b2a_hex(data).decode('ascii') | 
| 35 | |||
| 36 | def 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 | ||
