diff options
| author | itsme <itsme@xs4all.nl> | 2021-07-07 18:25:48 +0200 |
|---|---|---|
| committer | itsme <itsme@xs4all.nl> | 2021-07-07 18:25:48 +0200 |
| commit | 3de7b59f8073d1874ae14b23c0b191451f3db788 (patch) | |
| tree | 53897c66d049cf7af576e9c43117b0ed00305e6d | |
| parent | ae535cadc68bb1968fdf5b860e4ec8d194608852 (diff) | |
hexdump: added 'strescape' function
| -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 | ||
