omlish 0.0.0.dev1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of omlish might be problematic. Click here for more details.
- omlish/__about__.py +7 -0
- omlish/__init__.py +0 -0
- omlish/argparse.py +223 -0
- omlish/asyncs/__init__.py +17 -0
- omlish/asyncs/anyio.py +23 -0
- omlish/asyncs/asyncio.py +19 -0
- omlish/asyncs/asyncs.py +76 -0
- omlish/asyncs/futures.py +179 -0
- omlish/asyncs/trio.py +11 -0
- omlish/c3.py +173 -0
- omlish/cached.py +9 -0
- omlish/check.py +231 -0
- omlish/collections/__init__.py +63 -0
- omlish/collections/_abc.py +156 -0
- omlish/collections/_io_abc.py +78 -0
- omlish/collections/cache/__init__.py +11 -0
- omlish/collections/cache/descriptor.py +188 -0
- omlish/collections/cache/impl.py +485 -0
- omlish/collections/cache/types.py +37 -0
- omlish/collections/coerce.py +337 -0
- omlish/collections/frozen.py +148 -0
- omlish/collections/identity.py +106 -0
- omlish/collections/indexed.py +75 -0
- omlish/collections/mappings.py +127 -0
- omlish/collections/ordered.py +81 -0
- omlish/collections/persistent.py +36 -0
- omlish/collections/skiplist.py +193 -0
- omlish/collections/sorted.py +126 -0
- omlish/collections/treap.py +228 -0
- omlish/collections/treapmap.py +144 -0
- omlish/collections/unmodifiable.py +174 -0
- omlish/collections/utils.py +110 -0
- omlish/configs/__init__.py +0 -0
- omlish/configs/flattening.py +147 -0
- omlish/configs/props.py +64 -0
- omlish/dataclasses/__init__.py +83 -0
- omlish/dataclasses/impl/__init__.py +6 -0
- omlish/dataclasses/impl/api.py +260 -0
- omlish/dataclasses/impl/as_.py +76 -0
- omlish/dataclasses/impl/exceptions.py +2 -0
- omlish/dataclasses/impl/fields.py +148 -0
- omlish/dataclasses/impl/frozen.py +55 -0
- omlish/dataclasses/impl/hashing.py +85 -0
- omlish/dataclasses/impl/init.py +173 -0
- omlish/dataclasses/impl/internals.py +118 -0
- omlish/dataclasses/impl/main.py +150 -0
- omlish/dataclasses/impl/metaclass.py +126 -0
- omlish/dataclasses/impl/metadata.py +74 -0
- omlish/dataclasses/impl/order.py +47 -0
- omlish/dataclasses/impl/params.py +150 -0
- omlish/dataclasses/impl/processing.py +16 -0
- omlish/dataclasses/impl/reflect.py +173 -0
- omlish/dataclasses/impl/replace.py +40 -0
- omlish/dataclasses/impl/repr.py +34 -0
- omlish/dataclasses/impl/simple.py +92 -0
- omlish/dataclasses/impl/slots.py +80 -0
- omlish/dataclasses/impl/utils.py +167 -0
- omlish/defs.py +193 -0
- omlish/dispatch/__init__.py +3 -0
- omlish/dispatch/dispatch.py +137 -0
- omlish/dispatch/functions.py +52 -0
- omlish/dispatch/methods.py +162 -0
- omlish/docker.py +149 -0
- omlish/dynamic.py +220 -0
- omlish/graphs/__init__.py +0 -0
- omlish/graphs/dot/__init__.py +19 -0
- omlish/graphs/dot/items.py +162 -0
- omlish/graphs/dot/rendering.py +147 -0
- omlish/graphs/dot/utils.py +30 -0
- omlish/graphs/trees.py +249 -0
- omlish/http/__init__.py +0 -0
- omlish/http/consts.py +20 -0
- omlish/http/wsgi.py +34 -0
- omlish/inject/__init__.py +85 -0
- omlish/inject/binder.py +12 -0
- omlish/inject/bindings.py +49 -0
- omlish/inject/eagers.py +21 -0
- omlish/inject/elements.py +43 -0
- omlish/inject/exceptions.py +49 -0
- omlish/inject/impl/__init__.py +0 -0
- omlish/inject/impl/bindings.py +19 -0
- omlish/inject/impl/elements.py +154 -0
- omlish/inject/impl/injector.py +182 -0
- omlish/inject/impl/inspect.py +98 -0
- omlish/inject/impl/private.py +109 -0
- omlish/inject/impl/providers.py +132 -0
- omlish/inject/impl/scopes.py +198 -0
- omlish/inject/injector.py +40 -0
- omlish/inject/inspect.py +14 -0
- omlish/inject/keys.py +43 -0
- omlish/inject/managed.py +24 -0
- omlish/inject/overrides.py +18 -0
- omlish/inject/private.py +29 -0
- omlish/inject/providers.py +111 -0
- omlish/inject/proxy.py +48 -0
- omlish/inject/scopes.py +84 -0
- omlish/inject/types.py +21 -0
- omlish/iterators.py +184 -0
- omlish/json.py +194 -0
- omlish/lang/__init__.py +112 -0
- omlish/lang/cached.py +267 -0
- omlish/lang/classes/__init__.py +24 -0
- omlish/lang/classes/abstract.py +74 -0
- omlish/lang/classes/restrict.py +137 -0
- omlish/lang/classes/simple.py +120 -0
- omlish/lang/classes/test/__init__.py +0 -0
- omlish/lang/classes/test/test_abstract.py +89 -0
- omlish/lang/classes/test/test_restrict.py +71 -0
- omlish/lang/classes/test/test_simple.py +58 -0
- omlish/lang/classes/test/test_virtual.py +72 -0
- omlish/lang/classes/virtual.py +130 -0
- omlish/lang/clsdct.py +67 -0
- omlish/lang/cmp.py +63 -0
- omlish/lang/contextmanagers.py +249 -0
- omlish/lang/datetimes.py +67 -0
- omlish/lang/descriptors.py +52 -0
- omlish/lang/functions.py +126 -0
- omlish/lang/imports.py +153 -0
- omlish/lang/iterables.py +54 -0
- omlish/lang/maybes.py +136 -0
- omlish/lang/objects.py +103 -0
- omlish/lang/resolving.py +50 -0
- omlish/lang/strings.py +128 -0
- omlish/lang/typing.py +92 -0
- omlish/libc.py +532 -0
- omlish/logs/__init__.py +9 -0
- omlish/logs/_abc.py +247 -0
- omlish/logs/configs.py +62 -0
- omlish/logs/filters.py +9 -0
- omlish/logs/formatters.py +67 -0
- omlish/logs/utils.py +20 -0
- omlish/marshal/__init__.py +52 -0
- omlish/marshal/any.py +25 -0
- omlish/marshal/base.py +201 -0
- omlish/marshal/base64.py +25 -0
- omlish/marshal/dataclasses.py +115 -0
- omlish/marshal/datetimes.py +90 -0
- omlish/marshal/enums.py +43 -0
- omlish/marshal/exceptions.py +7 -0
- omlish/marshal/factories.py +129 -0
- omlish/marshal/global_.py +33 -0
- omlish/marshal/iterables.py +57 -0
- omlish/marshal/mappings.py +66 -0
- omlish/marshal/naming.py +17 -0
- omlish/marshal/objects.py +106 -0
- omlish/marshal/optionals.py +49 -0
- omlish/marshal/polymorphism.py +147 -0
- omlish/marshal/primitives.py +43 -0
- omlish/marshal/registries.py +57 -0
- omlish/marshal/standard.py +80 -0
- omlish/marshal/utils.py +23 -0
- omlish/marshal/uuids.py +29 -0
- omlish/marshal/values.py +30 -0
- omlish/math.py +184 -0
- omlish/os.py +32 -0
- omlish/reflect.py +359 -0
- omlish/replserver/__init__.py +5 -0
- omlish/replserver/__main__.py +4 -0
- omlish/replserver/console.py +247 -0
- omlish/replserver/server.py +146 -0
- omlish/runmodule.py +28 -0
- omlish/stats.py +342 -0
- omlish/term.py +222 -0
- omlish/testing/__init__.py +7 -0
- omlish/testing/pydevd.py +225 -0
- omlish/testing/pytest/__init__.py +8 -0
- omlish/testing/pytest/helpers.py +35 -0
- omlish/testing/pytest/inject/__init__.py +1 -0
- omlish/testing/pytest/inject/harness.py +159 -0
- omlish/testing/pytest/plugins/__init__.py +20 -0
- omlish/testing/pytest/plugins/_registry.py +6 -0
- omlish/testing/pytest/plugins/logging.py +13 -0
- omlish/testing/pytest/plugins/pycharm.py +54 -0
- omlish/testing/pytest/plugins/repeat.py +19 -0
- omlish/testing/pytest/plugins/skips.py +32 -0
- omlish/testing/pytest/plugins/spacing.py +19 -0
- omlish/testing/pytest/plugins/switches.py +70 -0
- omlish/testing/testing.py +102 -0
- omlish/text/__init__.py +0 -0
- omlish/text/delimit.py +171 -0
- omlish/text/indent.py +50 -0
- omlish/text/parts.py +265 -0
- omlish-0.0.0.dev1.dist-info/LICENSE +21 -0
- omlish-0.0.0.dev1.dist-info/METADATA +17 -0
- omlish-0.0.0.dev1.dist-info/RECORD +187 -0
- omlish-0.0.0.dev1.dist-info/WHEEL +5 -0
- omlish-0.0.0.dev1.dist-info/top_level.txt +1 -0
omlish/iterators.py
ADDED
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import collections
|
|
2
|
+
import functools
|
|
3
|
+
import itertools
|
|
4
|
+
import typing as ta
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
T = ta.TypeVar('T')
|
|
8
|
+
|
|
9
|
+
_MISSING = object()
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class PeekIterator(ta.Iterator[T]):
|
|
13
|
+
|
|
14
|
+
def __init__(self, it: ta.Iterator[T]) -> None:
|
|
15
|
+
super().__init__()
|
|
16
|
+
|
|
17
|
+
self._it = it
|
|
18
|
+
self._pos = -1
|
|
19
|
+
self._next_item: ta.Any = _MISSING
|
|
20
|
+
|
|
21
|
+
_item: T
|
|
22
|
+
|
|
23
|
+
def __iter__(self) -> ta.Iterator[T]:
|
|
24
|
+
return self
|
|
25
|
+
|
|
26
|
+
@property
|
|
27
|
+
def done(self) -> bool:
|
|
28
|
+
try:
|
|
29
|
+
self.peek()
|
|
30
|
+
return False
|
|
31
|
+
except StopIteration:
|
|
32
|
+
return True
|
|
33
|
+
|
|
34
|
+
def __next__(self) -> T:
|
|
35
|
+
if self._next_item is not _MISSING:
|
|
36
|
+
self._item = ta.cast(T, self._next_item)
|
|
37
|
+
self._next_item = _MISSING
|
|
38
|
+
else:
|
|
39
|
+
try:
|
|
40
|
+
self._item = next(self._it)
|
|
41
|
+
except StopIteration:
|
|
42
|
+
raise
|
|
43
|
+
self._pos += 1
|
|
44
|
+
return self._item
|
|
45
|
+
|
|
46
|
+
def peek(self) -> T:
|
|
47
|
+
if self._next_item is not _MISSING:
|
|
48
|
+
return ta.cast(T, self._next_item)
|
|
49
|
+
try:
|
|
50
|
+
self._next_item = next(self._it)
|
|
51
|
+
except StopIteration:
|
|
52
|
+
raise
|
|
53
|
+
return self._next_item
|
|
54
|
+
|
|
55
|
+
def next_peek(self) -> T:
|
|
56
|
+
next(self)
|
|
57
|
+
return self.peek()
|
|
58
|
+
|
|
59
|
+
def takewhile(self, fn):
|
|
60
|
+
while fn(self.peek()):
|
|
61
|
+
yield next(self)
|
|
62
|
+
|
|
63
|
+
def skipwhile(self, fn):
|
|
64
|
+
while fn(self.peek()):
|
|
65
|
+
next(self)
|
|
66
|
+
|
|
67
|
+
def takeuntil(self, fn):
|
|
68
|
+
return self.takewhile(lambda e: not fn(e))
|
|
69
|
+
|
|
70
|
+
def skipuntil(self, fn):
|
|
71
|
+
self.skipwhile(lambda e: not fn(e))
|
|
72
|
+
|
|
73
|
+
def takethrough(self, pos):
|
|
74
|
+
return self.takewhile(lambda _: self._pos < pos)
|
|
75
|
+
|
|
76
|
+
def skipthrough(self, pos):
|
|
77
|
+
self.skipwhile(lambda _: self._pos < pos)
|
|
78
|
+
|
|
79
|
+
def taketo(self, pos):
|
|
80
|
+
return self.takethrough(pos - 1)
|
|
81
|
+
|
|
82
|
+
def skipto(self, pos):
|
|
83
|
+
self.skipthrough(pos - 1)
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
class ProxyIterator(ta.Iterator[T]):
|
|
87
|
+
|
|
88
|
+
def __init__(self, fn: ta.Callable[[], T]) -> None:
|
|
89
|
+
self._fn = fn
|
|
90
|
+
|
|
91
|
+
def __iter__(self) -> ta.Iterator[T]:
|
|
92
|
+
return self
|
|
93
|
+
|
|
94
|
+
def __next__(self) -> T:
|
|
95
|
+
return self._fn()
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
class PrefetchIterator(ta.Iterator[T]):
|
|
99
|
+
|
|
100
|
+
def __init__(self, fn: ta.Optional[ta.Callable[[], T]] = None) -> None:
|
|
101
|
+
super().__init__()
|
|
102
|
+
|
|
103
|
+
self._fn = fn
|
|
104
|
+
self._deque: ta.Deque[T] = collections.deque()
|
|
105
|
+
|
|
106
|
+
def __iter__(self) -> ta.Iterator[T]:
|
|
107
|
+
return self
|
|
108
|
+
|
|
109
|
+
def push(self, item) -> None:
|
|
110
|
+
self._deque.append(item)
|
|
111
|
+
|
|
112
|
+
def __next__(self) -> T:
|
|
113
|
+
try:
|
|
114
|
+
return self._deque.popleft()
|
|
115
|
+
except IndexError:
|
|
116
|
+
if self._fn is None:
|
|
117
|
+
raise StopIteration
|
|
118
|
+
return self._fn()
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
class RetainIterator(ta.Iterator[T]):
|
|
122
|
+
|
|
123
|
+
def __init__(self, fn: ta.Callable[[], T]) -> None:
|
|
124
|
+
super().__init__()
|
|
125
|
+
|
|
126
|
+
self._fn = fn
|
|
127
|
+
self._deque: ta.Deque[T] = collections.deque()
|
|
128
|
+
|
|
129
|
+
def __iter__(self) -> ta.Iterator[T]:
|
|
130
|
+
return self
|
|
131
|
+
|
|
132
|
+
def pop(self) -> None:
|
|
133
|
+
self._deque.popleft()
|
|
134
|
+
|
|
135
|
+
def __next__(self) -> T:
|
|
136
|
+
item = self._fn()
|
|
137
|
+
self._deque.append(item)
|
|
138
|
+
return item
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
def unzip(it: ta.Iterable[T], width: ta.Optional[int] = None) -> list:
|
|
142
|
+
if width is None:
|
|
143
|
+
if not isinstance(it, PeekIterator):
|
|
144
|
+
it = PeekIterator(iter(it))
|
|
145
|
+
try:
|
|
146
|
+
width = len(it.peek())
|
|
147
|
+
except StopIteration:
|
|
148
|
+
return []
|
|
149
|
+
|
|
150
|
+
its: list[PrefetchIterator[T]] = []
|
|
151
|
+
running = True
|
|
152
|
+
|
|
153
|
+
def next_fn(idx):
|
|
154
|
+
nonlocal running
|
|
155
|
+
if not running:
|
|
156
|
+
raise StopIteration
|
|
157
|
+
try:
|
|
158
|
+
items = next(it) # type: ignore
|
|
159
|
+
except StopIteration:
|
|
160
|
+
running = False
|
|
161
|
+
raise
|
|
162
|
+
for item_idx, item in enumerate(items):
|
|
163
|
+
its[item_idx].push(item)
|
|
164
|
+
return next(its[idx])
|
|
165
|
+
|
|
166
|
+
its.extend(PrefetchIterator(functools.partial(next_fn, idx)) for idx in range(width))
|
|
167
|
+
return its
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
def take(n: int, iterable: ta.Iterable[T]) -> list[T]:
|
|
171
|
+
return list(itertools.islice(iterable, n))
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
def chunk(n: int, iterable: ta.Iterable[T], strict: bool = False) -> ta.Iterator[list[T]]:
|
|
175
|
+
iterator = iter(functools.partial(take, n, iter(iterable)), [])
|
|
176
|
+
if strict:
|
|
177
|
+
def ret():
|
|
178
|
+
for chunk in iterator:
|
|
179
|
+
if len(chunk) != n:
|
|
180
|
+
raise ValueError('iterable is not divisible by n.')
|
|
181
|
+
yield chunk
|
|
182
|
+
return iter(ret())
|
|
183
|
+
else:
|
|
184
|
+
return iterator
|
omlish/json.py
ADDED
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import functools
|
|
2
|
+
import json as _json
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
dump = _json.dump
|
|
6
|
+
dumps = _json.dumps
|
|
7
|
+
|
|
8
|
+
detect_encoding = _json.detect_encoding
|
|
9
|
+
|
|
10
|
+
load = _json.load
|
|
11
|
+
loads = _json.loads
|
|
12
|
+
|
|
13
|
+
##
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
PRETTY_INDENT = 2
|
|
17
|
+
|
|
18
|
+
PRETTY_KWARGS = dict(
|
|
19
|
+
indent=PRETTY_INDENT,
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
dump_pretty = functools.partial(dump, **PRETTY_KWARGS)
|
|
23
|
+
dumps_pretty = functools.partial(dumps, **PRETTY_KWARGS)
|
|
24
|
+
|
|
25
|
+
##
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
COMPACT_SEPARATORS = (',', ':')
|
|
29
|
+
|
|
30
|
+
COMPACT_KWARGS = dict(
|
|
31
|
+
indent=0,
|
|
32
|
+
separators=COMPACT_SEPARATORS,
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
dump_compact = functools.partial(dump, **COMPACT_KWARGS)
|
|
36
|
+
dumps_compact = functools.partial(dumps, **COMPACT_KWARGS)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
##
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
# import functools
|
|
43
|
+
# import typing as ta
|
|
44
|
+
#
|
|
45
|
+
# from . import cached
|
|
46
|
+
# from . import dataclasses as dc
|
|
47
|
+
#
|
|
48
|
+
#
|
|
49
|
+
# F = ta.TypeVar('F')
|
|
50
|
+
# T = ta.TypeVar('T')
|
|
51
|
+
# StrMap = ta.Mapping[str, ta.Any]
|
|
52
|
+
#
|
|
53
|
+
#
|
|
54
|
+
# ENCODING = 'utf-8'
|
|
55
|
+
# PRETTY_INDENT = 2
|
|
56
|
+
# COMPACT_SEPARATORS = (',', ':')
|
|
57
|
+
#
|
|
58
|
+
#
|
|
59
|
+
# Dumps = ta.Callable[[ta.Any], str]
|
|
60
|
+
# Dumpb = ta.Callable[[ta.Any], bytes]
|
|
61
|
+
# Loads = ta.Callable[[ta.Union[str, bytes, bytearray]], ta.Any]
|
|
62
|
+
#
|
|
63
|
+
#
|
|
64
|
+
# @dc.dataclass(frozen=True)
|
|
65
|
+
# class _Provider:
|
|
66
|
+
# pretty_kwargs: StrMap = dc.field(default_factory=dict)
|
|
67
|
+
# compact_kwargs: StrMap = dc.field(default_factory=dict)
|
|
68
|
+
#
|
|
69
|
+
#
|
|
70
|
+
# class Provider:
|
|
71
|
+
#
|
|
72
|
+
# def __init__(self, json: ta.Any) -> None:
|
|
73
|
+
# super().__init__()
|
|
74
|
+
# self._json = json
|
|
75
|
+
#
|
|
76
|
+
# @property
|
|
77
|
+
# def json(self) -> ta.Any:
|
|
78
|
+
# return self._json
|
|
79
|
+
#
|
|
80
|
+
# @cached.property
|
|
81
|
+
# def dumps(self) -> Dumps:
|
|
82
|
+
# return self.json.dumps
|
|
83
|
+
#
|
|
84
|
+
# @cached.property
|
|
85
|
+
# def dumpb(self) -> Dumpb:
|
|
86
|
+
# def dumpb(*args, **kwargs):
|
|
87
|
+
# return fn(*args, **kwargs).encode(ENCODING)
|
|
88
|
+
# fn = self.json.dumps
|
|
89
|
+
# return functools.wraps(fn)(dumpb)
|
|
90
|
+
#
|
|
91
|
+
# @cached.property
|
|
92
|
+
# def loads(self) -> Loads:
|
|
93
|
+
# return self.json.loads
|
|
94
|
+
#
|
|
95
|
+
# @cached.property
|
|
96
|
+
# def pretty_kwargs(self) -> StrMap:
|
|
97
|
+
# return {}
|
|
98
|
+
#
|
|
99
|
+
# @cached.property
|
|
100
|
+
# def compact_kwargs(self) -> StrMap:
|
|
101
|
+
# return {}
|
|
102
|
+
#
|
|
103
|
+
#
|
|
104
|
+
# class OrjsonProvider(Provider):
|
|
105
|
+
#
|
|
106
|
+
# def __init__(self) -> None:
|
|
107
|
+
# import orjson
|
|
108
|
+
# super().__init__(orjson)
|
|
109
|
+
#
|
|
110
|
+
# @cached.property
|
|
111
|
+
# def pretty_kwargs(self) -> StrMap:
|
|
112
|
+
# return {
|
|
113
|
+
# 'option': self.json.OPT_INDENT_2,
|
|
114
|
+
# }
|
|
115
|
+
#
|
|
116
|
+
# @cached.property
|
|
117
|
+
# def dumps(self) -> Dumps:
|
|
118
|
+
# def dumps(*args, **kwargs):
|
|
119
|
+
# return fn(*args, **kwargs).decode(ENCODING)
|
|
120
|
+
# fn = self.json.dumps
|
|
121
|
+
# return functools.wraps(fn)(dumps)
|
|
122
|
+
#
|
|
123
|
+
# @cached.property
|
|
124
|
+
# def dumpb(self) -> Dumpb:
|
|
125
|
+
# return self.json.dumps
|
|
126
|
+
#
|
|
127
|
+
#
|
|
128
|
+
# class UjsonProvider(Provider):
|
|
129
|
+
#
|
|
130
|
+
# def __init__(self) -> None:
|
|
131
|
+
# import ujson
|
|
132
|
+
# super().__init__(ujson)
|
|
133
|
+
#
|
|
134
|
+
# @cached.property
|
|
135
|
+
# def pretty_kwargs(self) -> StrMap:
|
|
136
|
+
# return {
|
|
137
|
+
# 'indent': PRETTY_INDENT,
|
|
138
|
+
# }
|
|
139
|
+
#
|
|
140
|
+
# @cached.property
|
|
141
|
+
# def loads(self) -> Loads:
|
|
142
|
+
# def loads(arg, *args, **kwargs):
|
|
143
|
+
# if isinstance(arg, (bytes, bytearray)):
|
|
144
|
+
# arg = arg.decode(ENCODING)
|
|
145
|
+
# return fn(arg, *args, **kwargs)
|
|
146
|
+
# fn = self.json.loads
|
|
147
|
+
# return functools.wraps(fn)(loads)
|
|
148
|
+
#
|
|
149
|
+
#
|
|
150
|
+
# class BuiltinProvider(Provider):
|
|
151
|
+
#
|
|
152
|
+
# def __init__(self) -> None:
|
|
153
|
+
# import json
|
|
154
|
+
# super().__init__(json)
|
|
155
|
+
#
|
|
156
|
+
# @cached.property
|
|
157
|
+
# def pretty_kwargs(self) -> StrMap:
|
|
158
|
+
# return {
|
|
159
|
+
# 'indent': PRETTY_INDENT,
|
|
160
|
+
# }
|
|
161
|
+
#
|
|
162
|
+
# @cached.property
|
|
163
|
+
# def compact_kwargs(self) -> StrMap:
|
|
164
|
+
# return {
|
|
165
|
+
# 'indent': 0,
|
|
166
|
+
# 'separators': COMPACT_SEPARATORS,
|
|
167
|
+
# }
|
|
168
|
+
#
|
|
169
|
+
#
|
|
170
|
+
# def _select_provider(typs: ta.Iterable[ta.Callable[[], Provider]]) -> Provider:
|
|
171
|
+
# for typ in typs:
|
|
172
|
+
# try:
|
|
173
|
+
# return typ()
|
|
174
|
+
# except ImportError:
|
|
175
|
+
# pass
|
|
176
|
+
# raise TypeError('No suitable json providers')
|
|
177
|
+
#
|
|
178
|
+
#
|
|
179
|
+
# PROVIDER: Provider = _select_provider([
|
|
180
|
+
# OrjsonProvider,
|
|
181
|
+
# UjsonProvider,
|
|
182
|
+
# BuiltinProvider,
|
|
183
|
+
# ])
|
|
184
|
+
#
|
|
185
|
+
#
|
|
186
|
+
# dumps: Dumps = PROVIDER.dumps
|
|
187
|
+
# dumpb: Dumpb = PROVIDER.dumpb
|
|
188
|
+
# loads: Loads = PROVIDER.loads
|
|
189
|
+
#
|
|
190
|
+
# dumps_compact: Dumps = functools.partial(dumps, **PROVIDER.compact_kwargs)
|
|
191
|
+
# dumpb_compact: Dumpb = functools.partial(dumpb, **PROVIDER.compact_kwargs)
|
|
192
|
+
#
|
|
193
|
+
# dumps_pretty: Dumps = functools.partial(dumps, **PROVIDER.pretty_kwargs)
|
|
194
|
+
# dumpb_pretty: Dumpb = functools.partial(dumpb, **PROVIDER.pretty_kwargs)
|
omlish/lang/__init__.py
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
from .cached import cached_function # noqa
|
|
2
|
+
from .cached import cached_property # noqa
|
|
3
|
+
from .classes import Abstract # noqa
|
|
4
|
+
from .classes import Callable # noqa
|
|
5
|
+
from .classes import Descriptor # noqa
|
|
6
|
+
from .classes import Final # noqa
|
|
7
|
+
from .classes import FinalException # noqa
|
|
8
|
+
from .classes import LazySingleton # noqa
|
|
9
|
+
from .classes import Marker # noqa
|
|
10
|
+
from .classes import Namespace # noqa
|
|
11
|
+
from .classes import NoBool # noqa
|
|
12
|
+
from .classes import NotInstantiable # noqa
|
|
13
|
+
from .classes import NotPicklable # noqa
|
|
14
|
+
from .classes import PackageSealed # noqa
|
|
15
|
+
from .classes import Picklable # noqa
|
|
16
|
+
from .classes import Sealed # noqa
|
|
17
|
+
from .classes import SealedException # noqa
|
|
18
|
+
from .classes import SimpleMetaDict # noqa
|
|
19
|
+
from .classes import Singleton # noqa
|
|
20
|
+
from .classes import Virtual # noqa
|
|
21
|
+
from .classes import is_abstract # noqa
|
|
22
|
+
from .classes import is_abstract_class # noqa
|
|
23
|
+
from .classes import is_abstract_method # noqa
|
|
24
|
+
from .classes import make_abstract # noqa
|
|
25
|
+
from .classes import no_bool # noqa
|
|
26
|
+
from .classes import virtual_check # noqa
|
|
27
|
+
from .clsdct import ClassDctFn # noqa
|
|
28
|
+
from .clsdct import cls_dct_fn # noqa
|
|
29
|
+
from .clsdct import get_caller_cls_dct # noqa
|
|
30
|
+
from .clsdct import is_possibly_cls_dct # noqa
|
|
31
|
+
from .cmp import Infinity # noqa
|
|
32
|
+
from .cmp import InfinityType # noqa
|
|
33
|
+
from .cmp import NegativeInfinity # noqa
|
|
34
|
+
from .cmp import NegativeInfinityType # noqa
|
|
35
|
+
from .cmp import cmp # noqa
|
|
36
|
+
from .contextmanagers import ContextManaged # noqa
|
|
37
|
+
from .contextmanagers import ContextWrapped # noqa
|
|
38
|
+
from .contextmanagers import DefaultLockable # noqa
|
|
39
|
+
from .contextmanagers import ExitStacked # noqa
|
|
40
|
+
from .contextmanagers import Lockable # noqa
|
|
41
|
+
from .contextmanagers import NOP_CONTEXT_MANAGED # noqa
|
|
42
|
+
from .contextmanagers import NOP_CONTEXT_MANAGER # noqa
|
|
43
|
+
from .contextmanagers import NopContextManaged # noqa
|
|
44
|
+
from .contextmanagers import NopContextManager # noqa
|
|
45
|
+
from .contextmanagers import a_defer # noqa
|
|
46
|
+
from .contextmanagers import attr_setting # noqa
|
|
47
|
+
from .contextmanagers import breakpoint_on_exception # noqa
|
|
48
|
+
from .contextmanagers import context_var_setting # noqa
|
|
49
|
+
from .contextmanagers import context_wrapped # noqa
|
|
50
|
+
from .contextmanagers import default_lock # noqa
|
|
51
|
+
from .contextmanagers import defer # noqa
|
|
52
|
+
from .contextmanagers import disposing # noqa
|
|
53
|
+
from .contextmanagers import maybe_managing # noqa
|
|
54
|
+
from .datetimes import months_ago # noqa
|
|
55
|
+
from .datetimes import parse_date # noqa
|
|
56
|
+
from .datetimes import parse_timedelta # noqa
|
|
57
|
+
from .datetimes import to_seconds # noqa
|
|
58
|
+
from .descriptors import AccessForbiddenException # noqa
|
|
59
|
+
from .descriptors import access_forbidden # noqa
|
|
60
|
+
from .descriptors import is_method_descriptor # noqa
|
|
61
|
+
from .descriptors import unwrap_method_descriptors # noqa
|
|
62
|
+
from .functions import VoidException # noqa
|
|
63
|
+
from .functions import constant # noqa
|
|
64
|
+
from .functions import identity # noqa
|
|
65
|
+
from .functions import is_lambda # noqa
|
|
66
|
+
from .functions import is_none # noqa
|
|
67
|
+
from .functions import is_not_none # noqa
|
|
68
|
+
from .functions import maybe_call # noqa
|
|
69
|
+
from .functions import raise_ # noqa
|
|
70
|
+
from .functions import recurse # noqa
|
|
71
|
+
from .functions import ticking_timeout # noqa
|
|
72
|
+
from .functions import try_ # noqa
|
|
73
|
+
from .functions import unwrap_func # noqa
|
|
74
|
+
from .functions import unwrap_func_with_partials # noqa
|
|
75
|
+
from .functions import void # noqa
|
|
76
|
+
from .imports import import_all # noqa
|
|
77
|
+
from .imports import import_module # noqa
|
|
78
|
+
from .imports import import_module_attr # noqa
|
|
79
|
+
from .imports import lazy_import # noqa
|
|
80
|
+
from .imports import proxy_import # noqa
|
|
81
|
+
from .imports import try_import # noqa
|
|
82
|
+
from .imports import yield_import_all # noqa
|
|
83
|
+
from .imports import yield_importable # noqa
|
|
84
|
+
from .iterables import BUILTIN_SCALAR_ITERABLE_TYPES # noqa
|
|
85
|
+
from .iterables import asrange # noqa
|
|
86
|
+
from .iterables import exhaust # noqa
|
|
87
|
+
from .iterables import ilen # noqa
|
|
88
|
+
from .iterables import peek # noqa
|
|
89
|
+
from .iterables import prodrange # noqa
|
|
90
|
+
from .iterables import take # noqa
|
|
91
|
+
from .maybes import Maybe # noqa
|
|
92
|
+
from .maybes import empty # noqa
|
|
93
|
+
from .maybes import just # noqa
|
|
94
|
+
from .maybes import maybe # noqa
|
|
95
|
+
from .objects import SimpleProxy # noqa
|
|
96
|
+
from .objects import arg_repr # noqa
|
|
97
|
+
from .objects import attr_repr # noqa
|
|
98
|
+
from .objects import new_type # noqa
|
|
99
|
+
from .objects import super_meta # noqa
|
|
100
|
+
from .strings import camel_case # noqa
|
|
101
|
+
from .strings import indent_lines # noqa
|
|
102
|
+
from .strings import is_dunder # noqa
|
|
103
|
+
from .strings import is_ident # noqa
|
|
104
|
+
from .strings import is_ident_cont # noqa
|
|
105
|
+
from .strings import is_ident_start # noqa
|
|
106
|
+
from .strings import is_sunder # noqa
|
|
107
|
+
from .strings import prefix_lines # noqa
|
|
108
|
+
from .strings import snake_case # noqa
|
|
109
|
+
from .typing import BytesLike # noqa
|
|
110
|
+
from .typing import protocol_check # noqa
|
|
111
|
+
from .typing import typed_lambda # noqa
|
|
112
|
+
from .typing import typed_partial # noqa
|