1#!/usr/bin/env python3
2"""
3
4"""
5# Imports:
6from __future__ import annotations
7
8# ##-- stdlib imports
9import datetime
10import enum
11import functools as ftz
12import itertools as itz
13import logging as logmod
14import re
15import time
16import collections
17import contextlib
18import hashlib
19from copy import deepcopy
20from uuid import UUID, uuid1
21from weakref import ref
22import atexit # for @atexit.register
23import faulthandler
24# ##-- end stdlib imports
25
26from jgdv._abstract.protocols.stdlib import Mapping_p
27
28# ##-- types
29# isort: off
30import abc
31import collections.abc
32from typing import TYPE_CHECKING, cast, assert_type, assert_never
33from typing import Generic, NewType
34# Protocols:
35from typing import Protocol, runtime_checkable
36# Typing Decorators:
37from typing import no_type_check, final, override, overload
38
39if TYPE_CHECKING:
40 import pathlib as pl
41 from jgdv import Maybe
42 from typing import Final
43 from typing import ClassVar, Any, LiteralString
44 from typing import Never, Self, Literal
45 from typing import TypeGuard
46 from collections.abc import Iterable, Iterator, Callable, Generator
47 from collections.abc import Sequence, MutableMapping, Hashable
48
49##--|
50
51# isort: on
52# ##-- end types
53
54##-- logging
55logging = logmod.getLogger(__name__)
56##-- end logging
57
58# Vars:
59type TomlTypes = (str | int | float | bool | list[TomlTypes] | dict[str,TomlTypes] | datetime.datetime)
60type ProxyWrapper[T] = Callable[[*Any], T]
61# Body:
62
[docs]
63class ChainProxy_p[T](Protocol):
64 """ The proxy interface
65
66 Used for special access like::
67
68 cg.on_fail(...).val()
69
70 """
71
72 def __call__(self, wrapper:Maybe[ProxyWrapper[T]]=None, fallback_wrapper:Maybe[ProxyWrapper[T]]=None) -> T: ...
73
74 def __getattr__(self, attr:str) -> Self: ...
75
76 def __getitem__(self, keys:int|str|tuple[str]) -> Self: ...
77
[docs]
78class ProxyEntry_p(Protocol):
79
[docs]
80 def on_fail[T](self, fallback:Maybe[T]=None, types:Maybe[type[T]]=None, *, non_root:bool=False) -> ChainProxy_p[T]: ...
81
[docs]
82 def first_of[T](self, fallback:Maybe[T]=None, types:Maybe[type[T]]=None) -> ChainProxy_p[T]: ...
83
[docs]
84 def all_of[T](self, fallback:Maybe[T]=None, types:Maybe[type[T]]=None) -> ChainProxy_p[T]: ...
85
[docs]
86 def flatten_on[T](self, fallback:Maybe[T]) -> ChainProxy_p[T]: ...
87
[docs]
88 def match_on(self, **kwargs:tuple[str,Any]) -> ChainProxy_p: ...
89
[docs]
90@runtime_checkable
91class ChainGuard_p(ProxyEntry_p, Mapping_p, Protocol):
92 """ The interface for a base ChainGuard object """
93
[docs]
94 @override
95 def get(self, key:str, default:Maybe=None) -> Maybe: ...
96
[docs]
97 @classmethod
98 def read[T:ChainGuard_p](cls:T, text:str) -> T: ...
99
[docs]
100 @classmethod
101 def from_dict(cls, data:dict) -> Self: ...
102
[docs]
103 @classmethod
104 def load(cls, *paths:str|pl.Path) -> Self: ...
105
[docs]
106 @classmethod
107 def load_dir(cls, dirp:str|pl.Path) -> Self: ...
108
[docs]
109 @staticmethod
110 def report_defaulted() -> list[str]: ...
111
112 def __init__(self, data:Maybe=None, *, index:Maybe[list[str]]=None, mutable:bool=False) -> None: ...
113
[docs]
114 def to_file(self, path:pl.Path) -> None: ...
115
[docs]
116 def _table(self) -> dict[str,Any]: ...
117
[docs]
118 def _index(self) -> list[str]: ...
119
[docs]
120class ChainGuard_i(ChainGuard_p, Protocol):
121 pass