Mercurial > hgrepos > Python > apps > py-cutils
comparison cutils/util/walk.py @ 368:7761a15b9736
treesum: Escape `\' using `\\' instead of `\x5c'.
Wished by sbro.
BUGS: Escaping should be controllable by a commandline option.
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Thu, 10 Apr 2025 11:58:36 +0200 |
| parents | b256ae4f4bc8 |
| children | 04d7945ff4ae |
comparison
equal
deleted
inserted
replaced
| 367:8a8a43e8369d | 368:7761a15b9736 |
|---|---|
| 218 # Prevent double encoding ... | 218 # Prevent double encoding ... |
| 219 # ... and hope that the current FS encoding is compatible | 219 # ... and hope that the current FS encoding is compatible |
| 220 # with it | 220 # with it |
| 221 # | 221 # |
| 222 if isinstance(what, bytes): | 222 if isinstance(what, bytes): |
| 223 s = (what.replace(b'\\', b"\\x5c") | 223 s = (what.replace(b'\\', b"\\\\") |
| 224 .replace(b'\n', b"\\x0a") | 224 .replace(b'\n', b"\\x0a") |
| 225 .replace(b'\r', b"\\x0d") | 225 .replace(b'\r', b"\\x0d") |
| 226 .replace(b'\t', b"\\x09")) | 226 .replace(b'\t', b"\\x09")) |
| 227 else: | 227 else: |
| 228 s = (what.replace(u'\\', u"\\x5c") | 228 s = (what.replace(u'\\', u"\\\\") |
| 229 .replace(u'\n', u"\\x0a") | 229 .replace(u'\n', u"\\x0a") |
| 230 .replace(u'\r', u"\\x0d") | 230 .replace(u'\r', u"\\x0d") |
| 231 .replace(u'\t', u"\\x09")) | 231 .replace(u'\t', u"\\x09")) |
| 232 if PY2: | 232 if PY2: |
| 233 if isinstance(s, bytes): | 233 if isinstance(s, bytes): |
| 327 # Prevent double encoding ... | 327 # Prevent double encoding ... |
| 328 # ... and hope that the current UTF-8 is compatible | 328 # ... and hope that the current UTF-8 is compatible |
| 329 # with it | 329 # with it |
| 330 # | 330 # |
| 331 if isinstance(what, bytes): | 331 if isinstance(what, bytes): |
| 332 s = (what.replace(b'\\', b"\\x5c") | 332 s = (what.replace(b'\\', b"\\\\") |
| 333 .replace(b'\n', b"\\x0a") | 333 .replace(b'\n', b"\\x0a") |
| 334 .replace(b'\r', b"\\x0d") | 334 .replace(b'\r', b"\\x0d") |
| 335 .replace(b'\t', b"\\x09")) | 335 .replace(b'\t', b"\\x09")) |
| 336 else: | 336 else: |
| 337 s = (what.replace(u'\\', u"\\x5c") | 337 s = (what.replace(u'\\', u"\\\\") |
| 338 .replace(u'\n', u"\\x0a") | 338 .replace(u'\n', u"\\x0a") |
| 339 .replace(u'\r', u"\\x0d") | 339 .replace(u'\r', u"\\x0d") |
| 340 .replace(u'\t', u"\\x09")) | 340 .replace(u'\t', u"\\x09")) |
| 341 if PY2: | 341 if PY2: |
| 342 if isinstance(s, bytes): | 342 if isinstance(s, bytes): |
