Mercurial > hgrepos > Python > apps > py-cutils
comparison cutils/util/walk.py @ 280:f3e0b479928c
treesum: FIX: Also check for that backslashes are nor in u8name or u8path and encode them
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Sun, 23 Feb 2025 10:01:09 +0100 |
| parents | f7850ff5cbe0 |
| children | 16507317e834 |
comparison
equal
deleted
inserted
replaced
| 279:44e62e36cad4 | 280:f3e0b479928c |
|---|---|
| 194 | 194 |
| 195 """ | 195 """ |
| 196 n = self.uname | 196 n = self.uname |
| 197 if n is None: | 197 if n is None: |
| 198 return None | 198 return None |
| 199 if (u'\n' in n) or (u'\r' in n): | 199 if (u'\n' in n) or (u'\r' in n) or (u'\\' in n): |
| 200 return None | 200 return None |
| 201 return n.encode("utf-8", "strict") | 201 return n.encode("utf-8", "strict") |
| 202 | 202 |
| 203 @property | 203 @property |
| 204 def u8path(self): | 204 def u8path(self): |
| 208 | 208 |
| 209 """ | 209 """ |
| 210 p = self.upath | 210 p = self.upath |
| 211 if p is None: | 211 if p is None: |
| 212 return None | 212 return None |
| 213 if (u'\n' in p) or (u'\r' in p): | 213 if (u'\n' in p) or (u'\r' in p) or (u'\\' in p): |
| 214 return None | 214 return None |
| 215 return p.encode("utf-8", "strict") | 215 return p.encode("utf-8", "strict") |
| 216 | 216 |
| 217 @property | 217 @property |
| 218 def alt_u8name(self): | 218 def alt_u8name(self): |
| 233 .encode("utf-8", "strict")) | 233 .encode("utf-8", "strict")) |
| 234 except UnicodeError: | 234 except UnicodeError: |
| 235 s = (WalkDirEntry.surrogate_decode(what) | 235 s = (WalkDirEntry.surrogate_decode(what) |
| 236 .encode("ascii", "backslashreplace")) | 236 .encode("ascii", "backslashreplace")) |
| 237 else: | 237 else: |
| 238 s = what.encode("ascii", "backslashreplace") | 238 s = what.encode("ascii", "backslashreplace") |
| 239 else: | 239 else: |
| 240 s = what.encode("utf-8", "backslashreplace") | 240 s = what.encode("utf-8", "backslashreplace") |
| 241 return s.replace(b'\n', b"\\x0a").replace(b'\r', b"\\x0d") | 241 return (s.replace(b'\\', b"\\x5c") |
| 242 .replace(b'\n', b"\\x0a") | |
| 243 .replace(b'\r', b"\\x0d")) | |
| 242 | 244 |
| 243 @property | 245 @property |
| 244 def is_symlink(self): | 246 def is_symlink(self): |
| 245 return self._is_symlink | 247 return self._is_symlink |
| 246 | 248 |
