omlish 0.0.0.dev212__py3-none-any.whl → 0.0.0.dev214__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.
Files changed (39) hide show
  1. omlish/.manifests.json +4 -4
  2. omlish/__about__.py +3 -5
  3. omlish/antlr/__init__.py +3 -0
  4. omlish/antlr/parsing.py +34 -2
  5. omlish/asyncs/asyncio/asyncio.py +34 -0
  6. omlish/asyncs/ioproxy/__init__.py +1 -0
  7. omlish/asyncs/ioproxy/all.py +32 -0
  8. omlish/asyncs/ioproxy/io.py +242 -0
  9. omlish/asyncs/ioproxy/proxier.py +154 -0
  10. omlish/asyncs/ioproxy/proxy.py +141 -0
  11. omlish/asyncs/ioproxy/typing.py +108 -0
  12. omlish/check.py +1 -0
  13. omlish/configs/processing/matching.py +9 -1
  14. omlish/formats/json/stream/lex.py +1 -0
  15. omlish/formats/json5/Json5.g4 +172 -0
  16. omlish/formats/json5/__init__.py +8 -0
  17. omlish/formats/json5/_antlr/Json5Lexer.py +353 -0
  18. omlish/formats/json5/_antlr/Json5Listener.py +78 -0
  19. omlish/formats/json5/_antlr/Json5Parser.py +616 -0
  20. omlish/formats/json5/_antlr/Json5Visitor.py +51 -0
  21. omlish/formats/json5/_antlr/__init__.py +0 -0
  22. omlish/formats/{json5.py → json5/codec.py} +6 -11
  23. omlish/formats/json5/errors.py +2 -0
  24. omlish/formats/json5/literals.py +130 -0
  25. omlish/formats/json5/parsing.py +79 -0
  26. omlish/io/abc.py +1 -0
  27. omlish/lang/__init__.py +2 -0
  28. omlish/lang/imports.py +4 -0
  29. omlish/lang/strings.py +33 -1
  30. omlish/lite/check.py +23 -0
  31. omlish/lite/contextmanagers.py +39 -0
  32. omlish/os/files.py +17 -30
  33. omlish/os/temp.py +50 -0
  34. {omlish-0.0.0.dev212.dist-info → omlish-0.0.0.dev214.dist-info}/METADATA +5 -7
  35. {omlish-0.0.0.dev212.dist-info → omlish-0.0.0.dev214.dist-info}/RECORD +39 -22
  36. {omlish-0.0.0.dev212.dist-info → omlish-0.0.0.dev214.dist-info}/LICENSE +0 -0
  37. {omlish-0.0.0.dev212.dist-info → omlish-0.0.0.dev214.dist-info}/WHEEL +0 -0
  38. {omlish-0.0.0.dev212.dist-info → omlish-0.0.0.dev214.dist-info}/entry_points.txt +0 -0
  39. {omlish-0.0.0.dev212.dist-info → omlish-0.0.0.dev214.dist-info}/top_level.txt +0 -0
omlish/.manifests.json CHANGED
@@ -108,13 +108,13 @@
108
108
  }
109
109
  },
110
110
  {
111
- "module": ".formats.json5",
111
+ "module": ".formats.json5.codec",
112
112
  "attr": "_JSON5_LAZY_CODEC",
113
- "file": "omlish/formats/json5.py",
114
- "line": 30,
113
+ "file": "omlish/formats/json5/codec.py",
114
+ "line": 25,
115
115
  "value": {
116
116
  "$.codecs.base.LazyLoadedCodec": {
117
- "mod_name": "omlish.formats.json5",
117
+ "mod_name": "omlish.formats.json5.codec",
118
118
  "attr_name": "JSON5_CODEC",
119
119
  "name": "json5",
120
120
  "aliases": null
omlish/__about__.py CHANGED
@@ -1,5 +1,5 @@
1
- __version__ = '0.0.0.dev212'
2
- __revision__ = 'bd253a140a7f57dc37a30f1a4f0b227123281988'
1
+ __version__ = '0.0.0.dev214'
2
+ __revision__ = '9512c6d71a63bb51772d9183f0205459f229de64'
3
3
 
4
4
 
5
5
  #
@@ -54,7 +54,7 @@ class Project(ProjectBase):
54
54
 
55
55
  'diag': [
56
56
  'asttokens ~= 3.0',
57
- 'executing ~= 2.1',
57
+ 'executing ~= 2.2',
58
58
 
59
59
  'psutil ~= 6.0',
60
60
  ],
@@ -63,8 +63,6 @@ class Project(ProjectBase):
63
63
  'orjson ~= 3.10',
64
64
  'ujson ~= 5.10',
65
65
 
66
- 'json5 ~= 0.9',
67
-
68
66
  'pyyaml ~= 6.0',
69
67
 
70
68
  'cbor2 ~= 5.6',
omlish/antlr/__init__.py CHANGED
@@ -0,0 +1,3 @@
1
+ from . import errors # noqa
2
+ from . import parsing # noqa
3
+ from . import runtime # noqa
omlish/antlr/parsing.py CHANGED
@@ -1,19 +1,51 @@
1
1
  # ruff: noqa: N802 N803
2
2
  import typing as ta
3
3
 
4
+ from .. import check
4
5
  from . import runtime as antlr4
6
+ from .errors import SilentRaisingErrorListener
5
7
 
6
8
 
7
9
  LexerT = ta.TypeVar('LexerT', bound=antlr4.Lexer)
8
10
  ParserT = ta.TypeVar('ParserT', bound=antlr4.Parser)
9
11
 
10
12
 
11
- def parse(
13
+ def is_eof_context(ctx: antlr4.ParserRuleContext) -> bool:
14
+ return ctx.getChildCount() == 1 and ctx.getChild(0).getSymbol().type == antlr4.Token.EOF
15
+
16
+
17
+ class StandardParseTreeVisitor(antlr4.ParseTreeVisitor):
18
+ def visit(self, ctx: antlr4.ParserRuleContext):
19
+ check.isinstance(ctx, antlr4.ParserRuleContext)
20
+ return ctx.accept(self)
21
+
22
+ def aggregateResult(self, aggregate, nextResult): # noqa
23
+ if aggregate is not None:
24
+ check.none(nextResult)
25
+ return aggregate
26
+ else:
27
+ check.none(aggregate)
28
+ return nextResult
29
+
30
+
31
+ def make_parser(
12
32
  buf: str,
13
33
  lexer_cls: type[LexerT],
14
34
  parser_cls: type[ParserT],
35
+ *,
36
+ silent_errors: bool = False,
15
37
  ) -> ParserT:
16
38
  lexer = lexer_cls(antlr4.InputStream(buf))
39
+ if silent_errors:
40
+ lexer.removeErrorListeners()
41
+ lexer.addErrorListener(SilentRaisingErrorListener())
42
+
17
43
  stream = antlr4.CommonTokenStream(lexer)
18
44
  stream.fill()
19
- return parser_cls(stream)
45
+
46
+ parser = parser_cls(stream)
47
+ if silent_errors:
48
+ parser.removeErrorListeners()
49
+ parser.addErrorListener(SilentRaisingErrorListener())
50
+
51
+ return parser
@@ -1,9 +1,13 @@
1
+ # ruff: noqa: UP006 UP007
2
+ # @omlish-lite
1
3
  import asyncio
2
4
  import contextlib
3
5
  import functools
4
6
  import typing as ta
5
7
 
6
8
 
9
+ T = ta.TypeVar('T')
10
+
7
11
  CallableT = ta.TypeVar('CallableT', bound=ta.Callable)
8
12
 
9
13
 
@@ -36,3 +40,33 @@ def draining_asyncio_tasks() -> ta.Iterator[None]:
36
40
  finally:
37
41
  if loop is not None:
38
42
  drain_tasks(loop) # noqa
43
+
44
+
45
+ async def asyncio_wait_concurrent(
46
+ coros: ta.Iterable[ta.Awaitable[T]],
47
+ concurrency: ta.Union[int, asyncio.Semaphore],
48
+ *,
49
+ return_when: ta.Any = asyncio.FIRST_EXCEPTION,
50
+ ) -> ta.List[T]:
51
+ if isinstance(concurrency, asyncio.Semaphore):
52
+ semaphore = concurrency
53
+ elif isinstance(concurrency, int):
54
+ semaphore = asyncio.Semaphore(concurrency)
55
+ else:
56
+ raise TypeError(concurrency)
57
+
58
+ async def limited_task(coro):
59
+ async with semaphore:
60
+ return await coro
61
+
62
+ tasks = [asyncio.create_task(limited_task(coro)) for coro in coros]
63
+ done, pending = await asyncio.wait(tasks, return_when=return_when)
64
+
65
+ for task in pending:
66
+ task.cancel()
67
+
68
+ for task in done:
69
+ if task.exception():
70
+ raise task.exception() # type: ignore
71
+
72
+ return [task.result() for task in done]
@@ -0,0 +1 @@
1
+ # @omlish-lite
@@ -0,0 +1,32 @@
1
+ from .io import ( # noqa
2
+ BufferedIOBase_AsyncIoProxy as BufferedIOBase,
3
+ BufferedRandom_AsyncIoProxy as BufferedRandom,
4
+ BufferedReader_AsyncIoProxy as BufferedReader,
5
+ BufferedRWPair_AsyncIoProxy as BufferedRWPair,
6
+ BufferedWriter_AsyncIoProxy as BufferedWriter,
7
+ BytesIO_AsyncIoProxy as BytesIO,
8
+ FileIO_AsyncIoProxy as FileIO,
9
+ IOBase_AsyncIoProxy as IOBase,
10
+ RawIOBase_AsyncIoProxy as RawIOBase,
11
+ StringIO_AsyncIoProxy as StringIO,
12
+ TextIOBase_AsyncIoProxy as TextIOBase,
13
+ TextIOWrapper_AsyncIoProxy as TextIOWrapper,
14
+ )
15
+
16
+ from .proxier import ( # noqa
17
+ AsyncIoProxier as Proxier,
18
+ )
19
+
20
+ from .proxy import ( # noqa
21
+ AsyncIoProxy as Proxy,
22
+ AsyncIoProxyRunner as Runer,
23
+ AsyncIoProxyTarget as Target,
24
+ async_io_proxy_cls_for as proxy_cls_for,
25
+ async_io_proxy_fn as proxy_fn,
26
+ )
27
+
28
+ from .typing import ( # noqa
29
+ TypingBinaryIO_AsyncIoProxy as TypingBinaryIO,
30
+ TypingIO_AsyncIoProxy as TypingIO,
31
+ TypingTextIO_AsyncIoProxy as TypingTextIO,
32
+ )
@@ -0,0 +1,242 @@
1
+ # ruff: noqa: UP006 UP007
2
+ import io
3
+ import typing as ta
4
+
5
+ from .proxy import AsyncIoProxy
6
+ from .proxy import _register_async_io_proxy_cls
7
+
8
+
9
+ SelfT = ta.TypeVar('SelfT')
10
+
11
+
12
+ ##
13
+
14
+
15
+ @_register_async_io_proxy_cls
16
+ class IOBase_AsyncIoProxy(AsyncIoProxy, proxied_cls=io.IOBase): # noqa
17
+ # https://github.com/python/cpython/blob/e65a1eb93ae35f9fbab1508606e3fbc89123629f/Lib/_pyio.py#L305
18
+
19
+ ##
20
+ # Positioning
21
+
22
+ async def seek(self, pos, whence=0):
23
+ raise TypeError
24
+
25
+ async def tell(self):
26
+ raise TypeError
27
+
28
+ async def truncate(self, pos=None):
29
+ raise TypeError
30
+
31
+ ##
32
+ # Flush and close
33
+
34
+ async def flush(self):
35
+ raise TypeError
36
+
37
+ async def close(self):
38
+ raise TypeError
39
+
40
+ ##
41
+ # Inquiries
42
+
43
+ def seekable(self):
44
+ raise TypeError
45
+
46
+ def readable(self):
47
+ raise TypeError
48
+
49
+ def writable(self):
50
+ raise TypeError
51
+
52
+ @property
53
+ def closed(self):
54
+ raise TypeError
55
+
56
+ ##
57
+ # Context manager
58
+
59
+ async def __aenter__(self: SelfT) -> SelfT:
60
+ raise TypeError
61
+
62
+ async def __aexit__(self, exc_type, exc_value, exc_tb):
63
+ raise TypeError
64
+
65
+ ##
66
+ # Lower-level APIs
67
+
68
+ def fileno(self):
69
+ raise TypeError
70
+
71
+ def isatty(self):
72
+ raise TypeError
73
+
74
+ ##
75
+ # Readline[s] and writelines
76
+
77
+ async def readline(self, size=-1):
78
+ raise TypeError
79
+
80
+ # def __iter__(self):
81
+ # raise TypeError
82
+
83
+ # def __next__(self):
84
+ # raise TypeError
85
+
86
+ async def readlines(self, hint=None):
87
+ raise TypeError
88
+
89
+ async def writelines(self, lines):
90
+ raise TypeError
91
+
92
+
93
+ @_register_async_io_proxy_cls
94
+ class RawIOBase_AsyncIoProxy(IOBase_AsyncIoProxy, proxied_cls=io.RawIOBase): # noqa
95
+ async def read(self, size=-1):
96
+ raise TypeError
97
+
98
+ async def readall(self):
99
+ raise TypeError
100
+
101
+ async def readinto(self, b):
102
+ raise TypeError
103
+
104
+ async def write(self, b):
105
+ raise TypeError
106
+
107
+
108
+ @_register_async_io_proxy_cls
109
+ class BufferedIOBase_AsyncIoProxy(IOBase_AsyncIoProxy, proxied_cls=io.BufferedIOBase): # noqa
110
+ async def read(self, size=-1):
111
+ raise TypeError
112
+
113
+ async def read1(self, size=-1):
114
+ raise TypeError
115
+
116
+ async def readinto(self, b):
117
+ raise TypeError
118
+
119
+ async def readinto1(self, b):
120
+ raise TypeError
121
+
122
+ async def write(self, b):
123
+ raise TypeError
124
+
125
+ async def detach(self):
126
+ raise TypeError
127
+
128
+
129
+ class BufferedIOMixin_AsyncIoProxy(BufferedIOBase_AsyncIoProxy): # noqa
130
+ @property
131
+ def raw(self):
132
+ raise TypeError
133
+
134
+ @property
135
+ def name(self):
136
+ raise TypeError
137
+
138
+ @property
139
+ def mode(self):
140
+ raise TypeError
141
+
142
+
143
+ @_register_async_io_proxy_cls
144
+ class BytesIO_AsyncIoProxy(BufferedIOBase_AsyncIoProxy, proxied_cls=io.BytesIO): # noqa
145
+ async def getvalue(self):
146
+ raise TypeError
147
+
148
+ async def getbuffer(self):
149
+ raise TypeError
150
+
151
+
152
+ @_register_async_io_proxy_cls
153
+ class BufferedReader_AsyncIoProxy(BufferedIOMixin_AsyncIoProxy, proxied_cls=io.BufferedReader): # noqa
154
+ async def peek(self, size=0):
155
+ raise TypeError
156
+
157
+
158
+ @_register_async_io_proxy_cls
159
+ class BufferedWriter_AsyncIoProxy(BufferedIOMixin_AsyncIoProxy, proxied_cls=io.BufferedWriter): # noqa
160
+ pass
161
+
162
+
163
+ @_register_async_io_proxy_cls
164
+ class BufferedRWPair_AsyncIoProxy(BufferedIOBase_AsyncIoProxy, proxied_cls=io.BufferedRWPair): # noqa
165
+ async def peek(self, size=0):
166
+ raise TypeError
167
+
168
+
169
+ @_register_async_io_proxy_cls
170
+ class BufferedRandom_AsyncIoProxy(BufferedWriter_AsyncIoProxy, BufferedReader_AsyncIoProxy, proxied_cls=io.BufferedRandom): # noqa
171
+ pass
172
+
173
+
174
+ @_register_async_io_proxy_cls
175
+ class FileIO_AsyncIoProxy(RawIOBase_AsyncIoProxy, proxied_cls=io.FileIO): # noqa
176
+ @property
177
+ def closefd(self):
178
+ raise TypeError
179
+
180
+ @property
181
+ def mode(self):
182
+ raise TypeError
183
+
184
+
185
+ @_register_async_io_proxy_cls
186
+ class TextIOBase_AsyncIoProxy(IOBase_AsyncIoProxy, proxied_cls=io.TextIOBase): # noqa
187
+ async def read(self, size=-1):
188
+ raise TypeError
189
+
190
+ async def write(self, s):
191
+ raise TypeError
192
+
193
+ async def detach(self):
194
+ raise TypeError
195
+
196
+ @property
197
+ def encoding(self):
198
+ raise TypeError
199
+
200
+ @property
201
+ def newlines(self):
202
+ raise TypeError
203
+
204
+ @property
205
+ def errors(self):
206
+ raise TypeError
207
+
208
+
209
+ @_register_async_io_proxy_cls
210
+ class TextIOWrapper_AsyncIoProxy(TextIOBase_AsyncIoProxy, proxied_cls=io.TextIOWrapper): # noqa
211
+ @property
212
+ def line_buffering(self):
213
+ raise TypeError
214
+
215
+ @property
216
+ def write_through(self):
217
+ raise TypeError
218
+
219
+ @property
220
+ def buffer(self):
221
+ raise TypeError
222
+
223
+ async def reconfigure(
224
+ self,
225
+ *,
226
+ encoding=None,
227
+ errors=None,
228
+ newline=Ellipsis,
229
+ line_buffering=None,
230
+ write_through=None,
231
+ ):
232
+ raise TypeError
233
+
234
+ @property
235
+ def name(self):
236
+ raise TypeError
237
+
238
+
239
+ @_register_async_io_proxy_cls
240
+ class StringIO_AsyncIoProxy(TextIOWrapper_AsyncIoProxy, proxied_cls=io.StringIO): # noqa
241
+ async def getvalue(self):
242
+ raise TypeError
@@ -0,0 +1,154 @@
1
+ # ruff: noqa: UP006 UP007
2
+ import io
3
+ import types
4
+ import typing as ta
5
+
6
+ from .io import BufferedIOBase_AsyncIoProxy
7
+ from .io import BufferedRandom_AsyncIoProxy
8
+ from .io import BufferedReader_AsyncIoProxy
9
+ from .io import BufferedRWPair_AsyncIoProxy
10
+ from .io import BufferedWriter_AsyncIoProxy
11
+ from .io import BytesIO_AsyncIoProxy
12
+ from .io import FileIO_AsyncIoProxy
13
+ from .io import IOBase_AsyncIoProxy
14
+ from .io import RawIOBase_AsyncIoProxy
15
+ from .io import StringIO_AsyncIoProxy
16
+ from .io import TextIOBase_AsyncIoProxy
17
+ from .io import TextIOWrapper_AsyncIoProxy
18
+ from .proxy import AsyncIoProxyRunner
19
+ from .proxy import AsyncIoProxyTarget
20
+ from .proxy import async_io_proxy_cls_for
21
+ from .proxy import async_io_proxy_fn
22
+ from .typing import TypingBinaryIO_AsyncIoProxy
23
+ from .typing import TypingIO_AsyncIoProxy
24
+ from .typing import TypingTextIO_AsyncIoProxy
25
+
26
+
27
+ ##
28
+
29
+
30
+ @ta.final
31
+ class AsyncIoProxier:
32
+ def __init__(self, runner_policy: ta.Callable[[ta.Any], AsyncIoProxyRunner]) -> None:
33
+ super().__init__()
34
+
35
+ self._runner_policy = runner_policy
36
+
37
+ def get_runner(self, obj: ta.Any) -> AsyncIoProxyRunner:
38
+ return self._runner_policy(obj)
39
+
40
+ ##
41
+
42
+ def target_obj(self, obj: ta.Any) -> AsyncIoProxyTarget:
43
+ runner = self.get_runner(obj)
44
+ return AsyncIoProxyTarget(obj, runner)
45
+
46
+ def proxy_obj_with_cls(self, obj, proxy_cls):
47
+ target = self.target_obj(obj)
48
+ proxy = proxy_cls(target)
49
+ return proxy
50
+
51
+ def maybe_proxy_obj(self, obj):
52
+ if (proxy_cls := async_io_proxy_cls_for(obj)) is None:
53
+ return obj
54
+ return self.proxy_obj_with_cls(obj, proxy_cls)
55
+
56
+ ##
57
+
58
+ @ta.overload
59
+ def proxy_obj(self, obj: io.StringIO) -> StringIO_AsyncIoProxy: # type: ignore[overload-overlap] # 1
60
+ ...
61
+
62
+ @ta.overload
63
+ def proxy_obj(self, obj: io.TextIOWrapper) -> TextIOWrapper_AsyncIoProxy: # type: ignore[overload-overlap] # 2
64
+ ...
65
+
66
+ @ta.overload
67
+ def proxy_obj(self, obj: io.TextIOBase) -> TextIOBase_AsyncIoProxy: # 3
68
+ ...
69
+
70
+ @ta.overload
71
+ def proxy_obj(self, obj: io.FileIO) -> FileIO_AsyncIoProxy: # type: ignore[overload-overlap] # 4
72
+ ...
73
+
74
+ @ta.overload
75
+ def proxy_obj(self, obj: io.BufferedRandom) -> BufferedRandom_AsyncIoProxy: # type: ignore[overload-overlap] # 5
76
+ ...
77
+
78
+ @ta.overload
79
+ def proxy_obj(self, obj: io.BufferedRWPair) -> BufferedRWPair_AsyncIoProxy: # 6
80
+ ...
81
+
82
+ @ta.overload
83
+ def proxy_obj(self, obj: io.BufferedWriter) -> BufferedWriter_AsyncIoProxy: # type: ignore[overload-overlap] # 7
84
+ ...
85
+
86
+ @ta.overload
87
+ def proxy_obj(self, obj: io.BufferedReader) -> BufferedReader_AsyncIoProxy: # type: ignore[overload-overlap] # 8
88
+ ...
89
+
90
+ @ta.overload
91
+ def proxy_obj(self, obj: io.BytesIO) -> BytesIO_AsyncIoProxy: # type: ignore[overload-overlap] # 9
92
+ ...
93
+
94
+ @ta.overload
95
+ def proxy_obj(self, obj: io.BufferedIOBase) -> BufferedIOBase_AsyncIoProxy: # 10
96
+ ...
97
+
98
+ @ta.overload
99
+ def proxy_obj(self, obj: io.RawIOBase) -> RawIOBase_AsyncIoProxy: # 11
100
+ ...
101
+
102
+ @ta.overload
103
+ def proxy_obj(self, obj: io.IOBase) -> IOBase_AsyncIoProxy: # 12
104
+ ...
105
+
106
+ #
107
+
108
+ @ta.overload
109
+ def proxy_obj(self, obj: ta.TextIO) -> TypingTextIO_AsyncIoProxy: # 13
110
+ ...
111
+
112
+ @ta.overload
113
+ def proxy_obj(self, obj: ta.BinaryIO) -> TypingBinaryIO_AsyncIoProxy: # 14
114
+ ...
115
+
116
+ @ta.overload
117
+ def proxy_obj(self, obj: ta.IO) -> TypingIO_AsyncIoProxy: # 15
118
+ ...
119
+
120
+ #
121
+
122
+ def proxy_obj(self, obj):
123
+ if (proxy_cls := async_io_proxy_cls_for(obj)) is None:
124
+ raise TypeError(obj)
125
+ return self.proxy_obj_with_cls(obj, proxy_cls)
126
+
127
+ ##
128
+
129
+ def proxy_fn(self, fn, *, wrap_result='auto'):
130
+ if wrap_result == 'auto':
131
+ result_wrapper = self.maybe_proxy_obj
132
+ elif wrap_result is True:
133
+ result_wrapper = self.proxy_obj
134
+ elif wrap_result is False:
135
+ result_wrapper = None
136
+ else:
137
+ raise TypeError(wrap_result)
138
+ runner = self.get_runner(fn)
139
+ return async_io_proxy_fn(fn, runner, result_wrapper=result_wrapper)
140
+
141
+ ##
142
+
143
+ FN_TYPES: ta.Tuple[type, ...] = (
144
+ types.BuiltinFunctionType,
145
+ types.BuiltinMethodType,
146
+ types.FunctionType,
147
+ types.MethodType,
148
+ )
149
+
150
+ def proxy(self, obj):
151
+ if isinstance(obj, self.FN_TYPES):
152
+ return self.proxy_fn(obj)
153
+ else:
154
+ return self.proxy_obj(obj)