Mercurial > hgrepos > Python > apps > py-cutils
comparison cutils/util/walk.py @ 198:c1e875ba4bdc
Put the effective filesystem encoding into the treesum digest file using FSENCODING = <encoding>
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Thu, 16 Jan 2025 23:18:04 +0100 |
| parents | 0f4febf646f5 |
| children | b2aba84ca426 |
comparison
equal
deleted
inserted
replaced
| 197:48e2610978e5 | 198:c1e875ba4bdc |
|---|---|
| 8 """ | 8 """ |
| 9 | 9 |
| 10 from __future__ import print_function, absolute_import | 10 from __future__ import print_function, absolute_import |
| 11 | 11 |
| 12 | 12 |
| 13 __all__ = ["ScanDir"] | 13 __all__ = ["ScanDir", "getfsencoding"] |
| 14 | 14 |
| 15 | 15 |
| 16 import os | 16 import os |
| 17 try: | 17 try: |
| 18 from os import scandir | 18 from os import scandir |
| 19 except ImportError: | 19 except ImportError: |
| 20 try: | 20 try: |
| 21 from scandir import scandir | 21 from scandir import scandir |
| 22 except ImportError: | 22 except ImportError: |
| 23 scandir = None | 23 scandir = None |
| 24 import sys | |
| 24 | 25 |
| 25 from . import PY2 | 26 from . import PY2 |
| 27 | |
| 28 | |
| 29 _FSENCODING = sys.getfilesystemencoding() | |
| 26 | 30 |
| 27 | 31 |
| 28 class WalkDirEntry(object): | 32 class WalkDirEntry(object): |
| 29 | 33 |
| 30 """A :class:`os.DirEntry` alike to be used in :func:`walk` and for | 34 """A :class:`os.DirEntry` alike to be used in :func:`walk` and for |
| 39 self._name = name | 43 self._name = name |
| 40 if PY2: | 44 if PY2: |
| 41 assert isinstance(name, bytes) | 45 assert isinstance(name, bytes) |
| 42 self._fsname = name | 46 self._fsname = name |
| 43 else: | 47 else: |
| 48 self._name = name | |
| 44 self._fsname = os.fsencode(name) | 49 self._fsname = os.fsencode(name) |
| 45 self._path = None | 50 self._path = None |
| 46 self._fspath = None | 51 self._fspath = None |
| 47 self._is_symlink = self._is_dir = self._stat_result = None | 52 self._is_symlink = self._is_dir = self._stat_result = None |
| 48 | 53 |
| 207 def __enter__(self): | 212 def __enter__(self): |
| 208 return self | 213 return self |
| 209 | 214 |
| 210 def __exit__(self, *args, **kwds): | 215 def __exit__(self, *args, **kwds): |
| 211 pass | 216 pass |
| 217 | |
| 218 | |
| 219 def getfsencoding(): | |
| 220 """Return the stored _FSENCODING of this module""" | |
| 221 return _FSENCODING |
