Debian Codegraph @

pathspec/_backends/hyperscan/_base.py

raw
1 """
2 This module provides private data for the base implementation for the
3 :module:`hyperscan` library.
4
5 WARNING: The *pathspec._backends.hyperscan* package is not part of the public
6 API. Its contents and structure are likely to change.
7 """
8 from __future__ import annotations
9
10 from dataclasses import (
11 dataclass)
12 from typing import (
13 Union) # Replaced by `X | Y` in 3.10.
14
15 try:
16 import hyperscan
17 except ModuleNotFoundError:
18 hyperscan = None # type: ignore[assignment]
19 HS_FLAGS = 0
20 else:
21 HS_FLAGS = hyperscan.HS_FLAG_SINGLEMATCH | hyperscan.HS_FLAG_UTF8
22
23 HS_FLAGS: int # type: ignore[no-redef]
24 """
25 The hyperscan flags to use:
26
27 - HS_FLAG_SINGLEMATCH is needed to ensure the partial patterns only match once.
28
29 - HS_FLAG_UTF8 is required to support unicode paths.
30 """
31
32
33 @dataclass(frozen=True)
34 class HyperscanExprDat(object):
35 """
36 The :class:`HyperscanExprDat` class is used to store data related to an
37 expression.
38 """
39
40 # The slots argument is not supported until Python 3.10.
41 __slots__ = [
42 'include',
43 'index',
44 'is_dir_pattern',
45 ]
46
47 include: bool
48 """
49 *include* (:class:`bool`) is whether is whether the matched files should be
50 included (:data:`True`), or excluded (:data:`False`).
51 """
52
53 index: int
54 """
55 *index* (:class:`int`) is the pattern index.
56 """
57
58 is_dir_pattern: bool
59 """
60 *is_dir_pattern* (:class:`bool`) is whether the pattern is a directory
61 pattern for gitignore.
62 """
63
64
65 @dataclass(frozen=True)
66 class HyperscanExprDebug(HyperscanExprDat):
67 """
68 The :class:`HyperscanExprDebug` class stores additional debug information
69 related to an expression.
70 """
71
72 # The slots argument is not supported until Python 3.10.
73 __slots__ = ['regex']
74
75 regex: Union[str, bytes]
76 """
77 *regex* (:class:`str` or :class:`bytes`) is the regular expression.
78 """