1"""
2This module provides private data for the base implementation for the
3:module:`re2` library.
4
5WARNING: The *pathspec._backends.re2* package is not part of the public API. Its
6contents and structure are likely to change.
7"""
8from __future__ import annotations
9
10from dataclasses import (
11 dataclass)
12from typing import (
13 Union) # Replaced by `X | Y` in 3.10.
14
15try:
16 import re2
17except ModuleNotFoundError:
18 re2 = None
19 RE2_OPTIONS = None
20else:
21 RE2_OPTIONS = re2.Options()
22 RE2_OPTIONS.log_errors = False
23 RE2_OPTIONS.never_capture = True
24
25RE2_OPTIONS: re2.Options
26"""
27The re2 options to use:
28
29- `log_errors=False` disables logging to stderr.
30
31- `never_capture=True` disables capture groups because they effectively cannot
32 be utilized with :class:`re2.Set`.
33"""
34
35
36@dataclass(frozen=True)
37class Re2RegexDat(object):
38 """
39 The :class:`Re2RegexDat` class is used to store data related to a regular
40 expression.
41 """
42
43 # The slots argument is not supported until Python 3.10.
44 __slots__ = [
45 'include',
46 'index',
47 'is_dir_pattern',
48 ]
49
50 include: bool
51 """
52 *include* (:class:`bool`) is whether is whether the matched files should be
53 included (:data:`True`), or excluded (:data:`False`).
54 """
55
56 index: int
57 """
58 *index* (:class:`int`) is the pattern index.
59 """
60
61 is_dir_pattern: bool
62 """
63 *is_dir_pattern* (:class:`bool`) is whether the pattern is a directory
64 pattern for gitignore.
65 """
66
67
68@dataclass(frozen=True)
69class Re2RegexDebug(Re2RegexDat):
70 """
71 The :class:`Re2RegexDebug` class stores additional debug information related
72 to a regular expression.
73 """
74
75 # The slots argument is not supported until Python 3.10.
76 __slots__ = ['regex']
77
78 regex: Union[str, bytes]
79 """
80 *regex* (:class:`str` or :class:`bytes`) is the regular expression.
81 """