Mercurial > hgrepos > Python > apps > py-cutils
comparison cutils/util/walk.py @ 371:29a301ff2501
treesum: FIX: also check for TABs when trying to encode strictly
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Sat, 12 Apr 2025 09:05:48 +0200 |
| parents | 04d7945ff4ae |
| children | bfe1160fbfd3 |
comparison
equal
deleted
inserted
replaced
| 370:a766264ff5bb | 371:29a301ff2501 |
|---|---|
| 151 | 151 |
| 152 @property | 152 @property |
| 153 def fsname(self): | 153 def fsname(self): |
| 154 """The name as bytes for the filesystem. | 154 """The name as bytes for the filesystem. |
| 155 | 155 |
| 156 Also do not allow CR of LF in the name. | 156 Also do not allow TAB, CR or LF in the name. |
| 157 | 157 |
| 158 :rtype: bytes or None | 158 :rtype: bytes or None |
| 159 | 159 |
| 160 """ | 160 """ |
| 161 if PY2: | 161 if PY2: |
| 165 s = self._name.encode(_FSENCODING, "strict") | 165 s = self._name.encode(_FSENCODING, "strict") |
| 166 except UnicodeError: | 166 except UnicodeError: |
| 167 return None | 167 return None |
| 168 else: | 168 else: |
| 169 s = os.fsencode(self._name) | 169 s = os.fsencode(self._name) |
| 170 if (b'\n' in s) or (b'\r' in s) or (b'\\' in s): | 170 if (b'\n' in s) or (b'\r' in s) or (b'\t' in s) or (b'\\' in s): |
| 171 return None | 171 return None |
| 172 return s | 172 return s |
| 173 | 173 |
| 174 @property | 174 @property |
| 175 def fspath(self): | 175 def fspath(self): |
| 176 """Always bytes. | 176 """Always bytes. |
| 177 | 177 |
| 178 Also do not allow CR of LF in the path. | 178 Also do not allow TAB, CR or LF in the path. |
| 179 | 179 |
| 180 :rtype: bytes or None | 180 :rtype: bytes or None |
| 181 | 181 |
| 182 """ | 182 """ |
| 183 if PY2: | 183 if PY2: |
| 187 p = self._path.encode(_FSENCODING, "strict") | 187 p = self._path.encode(_FSENCODING, "strict") |
| 188 except UnicodeError: | 188 except UnicodeError: |
| 189 return None | 189 return None |
| 190 else: | 190 else: |
| 191 p = os.fsencode(self._path) | 191 p = os.fsencode(self._path) |
| 192 if (b'\n' in p) or (b'\r' in p) or (b'\\' in p): | 192 if (b'\n' in p) or (b'\r' in p) or (b'\t' in p) or (b'\\' in p): |
| 193 return None | 193 return None |
| 194 return p | 194 return p |
| 195 | 195 |
| 196 @property | 196 @property |
| 197 def alt_fsname(self): | 197 def alt_fsname(self): |
| 286 | 286 |
| 287 @property | 287 @property |
| 288 def u8name(self): | 288 def u8name(self): |
| 289 """`.uname` as UTF-8 or `None` (as strict as `uname`). | 289 """`.uname` as UTF-8 or `None` (as strict as `uname`). |
| 290 | 290 |
| 291 Also do not allow CR of LF in the name. | 291 Also do not allow TAB, CR or LF in the name. |
| 292 | 292 |
| 293 """ | 293 """ |
| 294 n = self.uname | 294 n = self.uname |
| 295 if n is None: | 295 if n is None: |
| 296 return None | 296 return None |
| 297 if (u'\n' in n) or (u'\r' in n) or (u'\\' in n): | 297 if (u'\n' in n) or (u'\r' in n) or (u'\t' in n) or (u'\\' in n): |
| 298 return None | 298 return None |
| 299 return n.encode("utf-8", "strict") | 299 return n.encode("utf-8", "strict") |
| 300 | 300 |
| 301 @property | 301 @property |
| 302 def u8path(self): | 302 def u8path(self): |
| 303 """`.upath` as UTF-8 or `None` (as strict as `upath`. | 303 """`.upath` as UTF-8 or `None` (as strict as `upath`. |
| 304 | 304 |
| 305 Also do not allow CR or LF in the path. | 305 Also do not allow TAB, CR or LF in the path. |
| 306 | 306 |
| 307 """ | 307 """ |
| 308 p = self.upath | 308 p = self.upath |
| 309 if p is None: | 309 if p is None: |
| 310 return None | 310 return None |
| 311 if (u'\n' in p) or (u'\r' in p) or (u'\\' in p): | 311 if (u'\n' in p) or (u'\r' in p) or (u'\t' in p) or (u'\\' in p): |
| 312 return None | 312 return None |
| 313 return p.encode("utf-8", "strict") | 313 return p.encode("utf-8", "strict") |
| 314 | 314 |
| 315 @property | 315 @property |
| 316 def alt_u8name(self): | 316 def alt_u8name(self): |
