comparison cutils/util/constants.py @ 117:e51f34ad6d71

Move constant definitions into new module cutils.util.constants
author Franz Glasner <fzglas.hg@dom66.de>
date Sun, 29 Dec 2024 17:39:00 +0100
parents
children dfe7bb0579e2
comparison
equal deleted inserted replaced
116:1856374bbd40 117:e51f34ad6d71
1 # -*- coding: utf-8 -*-
2 # :-
3 # :Copyright: (c) 2020-2022 Franz Glasner
4 # :License: BSD-3-Clause
5 # :-
6 r"""Common constants and compatibility definitions.
7
8 """
9
10 __all__ = ["PY2",
11 "PATH_TYPES",
12 "READ_CHUNK_SIZE",
13 "MAX_AUTO_MAP_SIZE",
14 "MAP_WINDOW_SIZE"
15 ]
16
17
18 import sys
19 try:
20 import pathlib
21 except ImportError:
22 pathlib = None
23
24
25 PY2 = sys.version_info[0] < 3
26
27 if PY2:
28 PATH_TYPES = (unicode, str) # noqa: F821 (undefined name 'unicode')
29 else:
30 if pathlib:
31 PATH_TYPES = (str, bytes, pathlib.Path)
32 else:
33 PATH_TYPES = (str, bytes)
34
35 READ_CHUNK_SIZE = 2 * 1024 * 1024 # like BUFSIZE_MAX on FreeBSD
36 MAX_AUTO_MAP_SIZE = 8 * 1024 * 1024
37 MAP_WINDOW_SIZE = MAX_AUTO_MAP_SIZE # do not totally trash memory on big files