comparison cutils/util/digest.py @ 164:a813094ae4f5

Move PY2 from cutils.util.constants into cutils.util
author Franz Glasner <fzglas.hg@dom66.de>
date Thu, 09 Jan 2025 13:48:57 +0100
parents 1e5127028254
children 0f4febf646f5
comparison
equal deleted inserted replaced
163:fa7dd54e9715 164:a813094ae4f5
17 import mmap 17 import mmap
18 except ImportError: 18 except ImportError:
19 mmap = None 19 mmap = None
20 import stat 20 import stat
21 21
22 from . import PY2
22 from . import constants 23 from . import constants
23 24
24 25
25 def compute_digest_file(hashobj, path, use_mmap=None): 26 def compute_digest_file(hashobj, path, use_mmap=None):
26 """Compute the digest for a file with a filename of an open fd. 27 """Compute the digest for a file with a filename of an open fd.
77 if mmap is None or not use_mmap: 78 if mmap is None or not use_mmap:
78 # No mmap available or wanted -> use traditional low-level file IO 79 # No mmap available or wanted -> use traditional low-level file IO
79 fadvise = getattr(os, "posix_fadvise", None) 80 fadvise = getattr(os, "posix_fadvise", None)
80 if fadvise: 81 if fadvise:
81 fadvise(fd, 0, 0, os.POSIX_FADV_SEQUENTIAL) 82 fadvise(fd, 0, 0, os.POSIX_FADV_SEQUENTIAL)
82 if not constants.PY2: 83 if not PY2:
83 fileobj = io.FileIO(fd, mode="r", closefd=False) 84 fileobj = io.FileIO(fd, mode="r", closefd=False)
84 buf = bytearray(constants.READ_CHUNK_SIZE) 85 buf = bytearray(constants.READ_CHUNK_SIZE)
85 with memoryview(buf) as full_view: 86 with memoryview(buf) as full_view:
86 while True: 87 while True:
87 try: 88 try: