comparison cutils/util/walk.py @ 344:0a58948df713

Move the computation of the special tag string marker for special files into a property
author Franz Glasner <fzglas.hg@dom66.de>
date Tue, 01 Apr 2025 12:45:56 +0200
parents b3931b511ed0
children b256ae4f4bc8
comparison
equal deleted inserted replaced
343:b3931b511ed0 344:0a58948df713
11 11
12 12
13 __all__ = ["WalkDirEntry", "ScanDir", "getfsencoding"] 13 __all__ = ["WalkDirEntry", "ScanDir", "getfsencoding"]
14 14
15 15
16 import logging
16 import os 17 import os
17 try: 18 try:
18 from os import scandir 19 from os import scandir
19 except ImportError: 20 except ImportError:
20 try: 21 try:
27 from . import PY2 28 from . import PY2
28 29
29 30
30 _notset = object() 31 _notset = object()
31 32
33 _logger = logging.getLogger(__name__)
32 34
33 _FSENCODING = sys.getfilesystemencoding() 35 _FSENCODING = sys.getfilesystemencoding()
34 36
35 37
36 if PY2: 38 if PY2:
343 if self._stat_result is None: 345 if self._stat_result is None:
344 return False 346 return False
345 return not (self.is_reg or self.is_dir) 347 return not (self.is_reg or self.is_dir)
346 348
347 @property 349 @property
350 def special_tag(self):
351 """Return a special tag (string) for a special file"""
352 assert self.is_special
353 if self.is_chr:
354 return ':'
355 elif self.is_blk:
356 return ';'
357 elif self.is_fifo:
358 return '|'
359 elif self.is_socket:
360 return '='
361 elif self.is_door:
362 return '>'
363 elif self.is_whiteout:
364 return '%'
365 elif self.is_eventport:
366 return '+'
367 _logger.warning(
368 "unknown special file type: 0x%X",
369 stat.S_IFMT(self._stat_result.st_mode))
370 return '?'
371
372 @property
348 def stat(self): 373 def stat(self):
349 return self._stat_result 374 return self._stat_result
350 375
351 @property 376 @property
352 def stat_errno(self): 377 def stat_errno(self):