comparison cutils/util/walk.py @ 343:b3931b511ed0

Also encode TAB characters specially for output in digest files. Because with the new tabular output style we have the TAB character as column separator.
author Franz Glasner <fzglas.hg@dom66.de>
date Tue, 01 Apr 2025 12:15:05 +0200
parents 48430941c18c
children 0a58948df713
comparison
equal deleted inserted replaced
342:4a8026cbcecf 343:b3931b511ed0
149 # with it 149 # with it
150 # 150 #
151 if isinstance(what, bytes): 151 if isinstance(what, bytes):
152 s = (what.replace(b'\\', b"\\x5c") 152 s = (what.replace(b'\\', b"\\x5c")
153 .replace(b'\n', b"\\x0a") 153 .replace(b'\n', b"\\x0a")
154 .replace(b'\r', b"\\x0d")) 154 .replace(b'\r', b"\\x0d")
155 .replace(b'\t', b"\\x09"))
155 else: 156 else:
156 s = (what.replace(u'\\', u"\\x5c") 157 s = (what.replace(u'\\', u"\\x5c")
157 .replace(u'\n', u"\\x0a") 158 .replace(u'\n', u"\\x0a")
158 .replace(u'\r', u"\\x0d")) 159 .replace(u'\r', u"\\x0d")
160 .replace(u'\t', u"\\x09"))
159 if PY2: 161 if PY2:
160 if isinstance(s, bytes): 162 if isinstance(s, bytes):
161 return s 163 return s
162 else: 164 else:
163 return s.encode(_FSENCODING, "backslashreplace") 165 return s.encode(_FSENCODING, "backslashreplace")
256 # with it 258 # with it
257 # 259 #
258 if isinstance(what, bytes): 260 if isinstance(what, bytes):
259 s = (what.replace(b'\\', b"\\x5c") 261 s = (what.replace(b'\\', b"\\x5c")
260 .replace(b'\n', b"\\x0a") 262 .replace(b'\n', b"\\x0a")
261 .replace(b'\r', b"\\x0d")) 263 .replace(b'\r', b"\\x0d")
264 .replace(b'\t', b"\\x09"))
262 else: 265 else:
263 s = (what.replace(u'\\', u"\\x5c") 266 s = (what.replace(u'\\', u"\\x5c")
264 .replace(u'\n', u"\\x0a") 267 .replace(u'\n', u"\\x0a")
265 .replace(u'\r', u"\\x0d")) 268 .replace(u'\r', u"\\x0d")
269 .replace(u'\t', u"\\x09"))
266 if PY2: 270 if PY2:
267 if isinstance(s, bytes): 271 if isinstance(s, bytes):
268 try: 272 try:
269 return (s.decode(_FSENCODING, "strict") 273 return (s.decode(_FSENCODING, "strict")
270 .encode("utf-8", "strict")) 274 .encode("utf-8", "strict"))