devlooped-jqlite 1.0.0a0__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 (65) hide show
  1. devlooped_jqlite-1.0.0a0.dist-info/METADATA +233 -0
  2. devlooped_jqlite-1.0.0a0.dist-info/RECORD +65 -0
  3. devlooped_jqlite-1.0.0a0.dist-info/WHEEL +5 -0
  4. devlooped_jqlite-1.0.0a0.dist-info/licenses/LICENSE +22 -0
  5. devlooped_jqlite-1.0.0a0.dist-info/top_level.txt +1 -0
  6. jqlite/__init__.py +79 -0
  7. jqlite/binding/__init__.py +0 -0
  8. jqlite/binding/bound.py +518 -0
  9. jqlite/binding/modules.py +259 -0
  10. jqlite/binding/prelude.py +77 -0
  11. jqlite/binding/resolver.py +699 -0
  12. jqlite/builtins/__init__.py +0 -0
  13. jqlite/builtins/assign_natives.py +350 -0
  14. jqlite/builtins/calendar.py +105 -0
  15. jqlite/builtins/collection_natives.py +136 -0
  16. jqlite/builtins/containment.py +101 -0
  17. jqlite/builtins/core_natives.py +138 -0
  18. jqlite/builtins/date_natives.py +111 -0
  19. jqlite/builtins/formats.py +154 -0
  20. jqlite/builtins/loop_natives.py +159 -0
  21. jqlite/builtins/math_extra.py +580 -0
  22. jqlite/builtins/math_natives.py +276 -0
  23. jqlite/builtins/module_natives.py +29 -0
  24. jqlite/builtins/natives.py +131 -0
  25. jqlite/builtins/path_natives.py +233 -0
  26. jqlite/builtins/regex_engine.py +358 -0
  27. jqlite/builtins/regex_natives.py +149 -0
  28. jqlite/builtins/regex_syntax.py +754 -0
  29. jqlite/builtins/registration.py +53 -0
  30. jqlite/builtins/strftime.py +428 -0
  31. jqlite/builtins/string_natives.py +90 -0
  32. jqlite/exceptions.py +37 -0
  33. jqlite/expression.py +114 -0
  34. jqlite/json_adapter.py +151 -0
  35. jqlite/options.py +75 -0
  36. jqlite/prelude.jq +138 -0
  37. jqlite/py.typed +0 -0
  38. jqlite/resolvers.py +86 -0
  39. jqlite/runtime/__init__.py +0 -0
  40. jqlite/runtime/env.py +45 -0
  41. jqlite/runtime/evaluation.py +87 -0
  42. jqlite/runtime/interpreter.py +1380 -0
  43. jqlite/runtime/native_table.py +69 -0
  44. jqlite/runtime/path.py +64 -0
  45. jqlite/runtime/signal.py +67 -0
  46. jqlite/runtime/stack_guard.py +41 -0
  47. jqlite/syntax/__init__.py +0 -0
  48. jqlite/syntax/ast.py +478 -0
  49. jqlite/syntax/lexer.py +294 -0
  50. jqlite/syntax/parser.py +1008 -0
  51. jqlite/syntax/recursion_limit.py +73 -0
  52. jqlite/syntax/syntax_error.py +85 -0
  53. jqlite/syntax/token.py +155 -0
  54. jqlite/values/__init__.py +15 -0
  55. jqlite/values/code_points.py +62 -0
  56. jqlite/values/errors.py +330 -0
  57. jqlite/values/jq_array.py +122 -0
  58. jqlite/values/jq_array_builder.py +49 -0
  59. jqlite/values/jq_object.py +171 -0
  60. jqlite/values/jq_object_builder.py +67 -0
  61. jqlite/values/jq_string.py +86 -0
  62. jqlite/values/jq_value.py +65 -0
  63. jqlite/values/utf8.py +27 -0
  64. jqlite/values/value_ops.py +567 -0
  65. jqlite/values/value_text.py +563 -0
@@ -0,0 +1,233 @@
1
+ Metadata-Version: 2.4
2
+ Name: devlooped-jqlite
3
+ Version: 1.0.0a0
4
+ Summary: jqlite, the portable profile of the jq language: the Python port of the JQLite reference engine
5
+ Author: Daniel Cazzulino
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/devlooped/jqlite
8
+ Project-URL: Repository, https://github.com/devlooped/jqlite
9
+ Project-URL: Issues, https://github.com/devlooped/jqlite/issues
10
+ Keywords: jq,json,query,jqlite
11
+ Classifier: Development Status :: 5 - Production/Stable
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Operating System :: OS Independent
14
+ Classifier: Topic :: Software Development :: Libraries
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3 :: Only
17
+ Classifier: Typing :: Typed
18
+ Requires-Python: >=3.11
19
+ Description-Content-Type: text/markdown
20
+ License-File: LICENSE
21
+ Dynamic: license-file
22
+
23
+ # jqlite for Python
24
+
25
+ The Python port of [jqlite](../spec/jqlite.md), the profile of the [jq](https://jqlang.org) language
26
+ whose reference implementation is the C# engine in [`dotnet/JQLite/Core`](../dotnet/JQLite/Core). It
27
+ is a 1:1 port, file by file, of that engine ([`docs/porting.md`](../docs/porting.md)), proven by the
28
+ same conformance corpus ([`spec/tests`](../spec/tests)). Python 3.11 or later, standard library only.
29
+
30
+ ## Use
31
+
32
+ ```python
33
+ import jqlite
34
+
35
+ jqlite.evaluate(".a + 1", {"a": 41}) # [42]
36
+
37
+ expression = jqlite.parse("[.[] | select(. > $min)]") # parse and bind once
38
+ expression.evaluate([1, 5, 10], {"min": 4}) # [[5, 10]], from any thread
39
+
40
+ # Stream the results, and stop when you have enough (returning False stops; it is not an error).
41
+ seen = []
42
+ jqlite.parse("range(1000000000)").stream(None, lambda r: seen.append(r) or len(seen) < 3)
43
+
44
+ # Options: modules, $ENV, clock and zone, the depth limit, debug and stderr handlers.
45
+ options = jqlite.Options(
46
+ resolver=jqlite.FileResolver("."), # import/include: files relative to the importing one
47
+ environment={"HOME": "/home/me"}, # $ENV; None (default) is os.environ
48
+ max_depth=1000, # calls of jq functions active at once (spec §11), 0 to 100,000
49
+ debug=print, stderr=print,
50
+ )
51
+ jqlite.parse("$ENV.HOME", options).evaluate(None) # ["/home/me"]
52
+
53
+ # One evaluation per value of a JSON Lines stream (also evaluate_each_async).
54
+ for result in jqlite.evaluate_each(".name", [{"name": "a"}, {"name": "b"}]):
55
+ print(result)
56
+
57
+ try:
58
+ jqlite.evaluate("error({code: 1})", None)
59
+ except jqlite.JqHaltError as e: # halt_error: e.value, e.exit_code
60
+ ...
61
+ except jqlite.JqParseError as e: # syntax or binding error: e.line, e.column, e.module
62
+ ...
63
+ except jqlite.JqError as e: # uncaught error: e.value; str(e) is spec §10.1's message
64
+ ...
65
+ ```
66
+
67
+ Values are Python's JSON values, as `json.loads` gives them. In: `int` becomes the nearest `float`,
68
+ tuples are lists, any mapping with string keys an object, and a lone surrogate in a string or a key
69
+ becomes U+FFFD (§4.1). Out: each value as `json.loads` would read its canonical text (§5.1): a
70
+ number without fraction below 1e21 in magnitude is an `int`, other numbers are `float`, NaN is `None`,
71
+ ±Infinity is ±1.7976931348623157e+308, and objects keep their key order. Host variables are checked
72
+ before evaluation (`ValueError` for a name that is not an identifier, or `ENV`). `halt` ends an
73
+ evaluation normally.
74
+
75
+ The callbacks (`stream`'s, `debug`, `stderr`, a resolver's methods) run on the thread that
76
+ parses or evaluates: the library starts no thread. `max_depth` is an `int` from 0 to 100,000
77
+ (`jqlite.Options` raises `ValueError` otherwise): 100,000 levels of calls run on a thread with a
78
+ 256 KB stack and take about 70 MB while they are active (0.7 KB a level).
79
+
80
+ Importing `jqlite` changes nothing in the process. While a parse or an evaluation runs, the
81
+ library raises Python's recursion limit (`sys.setrecursionlimit`, a setting of the process) to
82
+ what that parse or evaluation may need (spec §11 lets a program meet no recursion limit but
83
+ `max_depth`); when the last parse or evaluation that runs ends, on any thread, the limit is put back
84
+ to what it was. The host's own code running meanwhile, its callbacks included, sees the raised limit.
85
+
86
+ Differences from the .NET API: no resource resolver (the reference's `JqResourceResolver` reads
87
+ .NET embedded resources; implement `Resolver` to read from package data or anywhere else), no
88
+ `IObservable` evaluation (`stream` with a callback, `evaluate_each` and `evaluate_each_async` cover
89
+ streaming), and values are Python's JSON values instead of `JsonElement`.
90
+
91
+ ## Build, test, check
92
+
93
+ There is nothing to build. From this folder:
94
+
95
+ ```
96
+ python -m unittest # 2,557 tests: the corpus both ways, the unit tests of every layer
97
+ python -m compileall -q jqlite tests crossbench.py
98
+ python -m mypy # optional tools (pip install mypy ruff), configured in pyproject.toml
99
+ python -m ruff check
100
+ ```
101
+
102
+ - `tests/test_conformance.py`: every case of `spec/tests/*.test` (read from the shared folder), one
103
+ test each, through the public API (`CorpusPublicApi`) and through the core with every prelude
104
+ builtin bound to its definition (`CorpusWithoutNativeOverrides`): 1,151 + 1,151 tests.
105
+ `localtime.test` runs with a zone fixed at UTC+02:00, `modules.test` over `spec/tests/modules/`.
106
+ - `tests/test_catalogue.py`: the N and P lists of §9, read from the spec, against the native
107
+ catalogue and the prelude; the package's `jqlite/prelude.jq` against `spec/prelude.jq`.
108
+ - `tests/test_values.py`, `test_syntax.py`, `test_binding.py`, `test_runtime.py`, `test_builtins.py`:
109
+ the reference's `dotnet/Tests/Core/<Layer>` tests, ported. `test_builtins.py` checks the regex
110
+ engine against a backtracking matcher of the same programs on random patterns
111
+ (`backtracking_matcher.py`, `regex_fuzz.py`), its linear time and memory, and that it runs the
112
+ largest programs the limits of §11 allow. It runs 10,000 random patterns per seed (the reference
113
+ 20,000), shorter linear-time inputs, under the reference's bound of 2 seconds a case, and a shorter
114
+ input for the program with the most states.
115
+ - `tests/test_host.py`: the boundary, resolvers, threads, the depth limit through the API.
116
+ - `tests/test_portability.py`: the portability rules of `AGENTS.md` on the core's code.
117
+
118
+ `jqlite/prelude.jq` is a copy of `spec/prelude.jq` (package data); when the spec's prelude changes,
119
+ copy it again (`cp ../spec/prelude.jq jqlite/prelude.jq`): `test_the_embedded_prelude_is_spec_prelude_jq`
120
+ fails until then.
121
+
122
+ ## Benchmark
123
+
124
+ `bench.json` runs `python crossbench.py <program.jq> <input.json> <take> <warmup-ms> <measure-ms>
125
+ <output-file>` (the protocol of [`bench/README.md`](../bench/README.md)), on the core engine.
126
+ `pwsh ../bench/run.ps1 -Impl python` builds the .NET baseline and runs both.
127
+
128
+ ## Layout
129
+
130
+ | Reference (`dotnet/JQLite/Core`) | Python (`jqlite/`) |
131
+ | --- | --- |
132
+ | `Values/*.cs` | `values/jq_value.py`, `jq_array.py`, `jq_array_builder.py`, `jq_object.py`, `jq_object_builder.py`, `jq_string.py`, `code_points.py`, `utf8.py`, `value_ops.py`, `value_text.py`, `errors.py` |
133
+ | `Syntax/*.cs` | `syntax/token.py`, `lexer.py`, `ast.py`, `parser.py`, `syntax_error.py` |
134
+ | `Binding/*.cs` | `binding/bound.py`, `resolver.py`, `prelude.py`, `modules.py` |
135
+ | `Runtime/*.cs` | `runtime/interpreter.py`, `env.py`, `path.py`, `signal.py`, `evaluation.py`, `stack_guard.py`, and `native_table.py` (`Builtins/NativeTable.cs`, see below) |
136
+ | `Builtins/*.cs` | `builtins/natives.py`, `core_natives.py`, `loop_natives.py`, `collection_natives.py`, `containment.py`, `string_natives.py`, `path_natives.py`, `assign_natives.py`, `formats.py`, `math_natives.py`, `math_extra.py`, `calendar.py`, `strftime.py`, `date_natives.py`, `regex_syntax.py`, `regex_engine.py`, `regex_natives.py`, `module_natives.py`, and `registration.py` |
137
+ | the .NET boundary (`Jq.cs`, `JqExpression.cs`, …) | `__init__.py` (`parse`, `evaluate`, `evaluate_each`), `expression.py`, `options.py`, `resolvers.py`, `exceptions.py`, `json_adapter.py` |
138
+
139
+ Host-specific files (**H** in the guide), each saying in its header what it uses: `values/value_text.py`
140
+ (`repr` and `float` for number text), `values/utf8.py` (the UTF-8 codec), `binding/prelude.py`
141
+ (`importlib.resources`), `syntax/recursion_limit.py` (`sys.setrecursionlimit`, see *The host
142
+ stack* below) and `runtime/stack_guard.py` (the frames an evaluation may need),
143
+ `builtins/math_natives.py` (`math`).
144
+
145
+ Other host uses in the core, each the counterpart of something every language has:
146
+
147
+ - `struct` in `builtins/math_extra.py`: the bit casts between a double and a 64-bit integer
148
+ (`BitConverter.DoubleToInt64Bits` in the reference) of `nextafter` and of exact powers of two.
149
+ - `threading.Lock`, for what is done once per process or shared between threads, as the
150
+ reference's locks and static constructors: `values/jq_array.py` (the claim of a shared buffer's
151
+ next slot, arrays, objects and strings), `binding/prelude.py` (the prelude, bound once),
152
+ `builtins/core_natives.py` (the list of `builtins`, computed once), `builtins/registration.py`
153
+ (the native table, filled once) and `syntax/recursion_limit.py` (the count of the parses and
154
+ evaluations that run).
155
+ - The cache of compiled regex programs in `builtins/regex_engine.py`, 256 entries emptied when full,
156
+ as in the reference: a `dict`, whose reads and writes are atomic (the reference's concurrent map).
157
+
158
+ ## Differences from the reference's structure
159
+
160
+ Each is deliberate; the behaviour is the spec's in every case (the corpus runs both ways).
161
+
162
+ - **Values.** A value is Python's own `None`, `bool`, `float`, `str` or a `JqArray`/`JqObject`
163
+ (guide §2.1), or a `JqString` where `values/jq_string.py` allows one (see *Strings*); the engine
164
+ tests `type(v)` exactly, so `bool` is never a number, and no `int` enters.
165
+ For a type checker `JqValue` is `Any`: the engine dispatches on a saved `type(v)`, which checkers
166
+ do not follow to narrow a union.
167
+ - **Fallible operations** return the result or a `Fail(error)` (guide §2.2) instead of `bool` and two
168
+ `out` parameters.
169
+ - **`eval_one`** returns the output, `NOTHING` (no output) or a `Signal`, and leaves the output's
170
+ path in `self.at`, instead of the tuple the guide suggests for Python: no allocation per node.
171
+ `NOTHING` is a `Signal` object that is never a signal, so one type test tells a value from the rest.
172
+ - **Dispatch by table**: the non-tail constructs of `eval` and `eval_one` are handlers in two lists
173
+ indexed by node kind (`_MANY`, `_OTHER`); the tail positions stay loops, as in the reference.
174
+ A few fast paths avoid calls without changing the order of evaluation: `.name` on the input, a
175
+ literal or `.` operand of one operator, `as $x` bindings and `reduce … as $x` without matching.
176
+ - **Arrays and objects** (guide §2.9): the buffer is a growable Python list; the latest version
177
+ appends in place, the check and the append done under one lock (the reference's compare-and-swap).
178
+ Every object keeps its key index (a dict shared by the versions of a buffer, extended under the
179
+ same lock): a dict lookup is faster in Python than the reference's scan of up to 8 keys.
180
+ - **Strings** are Python `str`, already code points: no code point map, no UTF-16 ordering fix.
181
+ `sanitize` also joins a high and a low surrogate that a host `str` holds as two code points.
182
+ A `+` on strings that gives 256 code points or more makes a `JqString` (guide §2.9: a buffer of
183
+ `str` parts, joined once when read), which the next `+` extends in place, so `add` and `join` are
184
+ linear. Unlike the reference's, it is not a value every part of the engine takes: only the values
185
+ layer and the interpreter see one, which turns it into a `str` where it enters a container, a
186
+ native, a template or a format, or reaches the host (the list is in `values/jq_string.py`), so the
187
+ natives and the boundary test `type(v) is str` as before. `LongStringTests` runs programs through
188
+ each of those places with every concatenation a `JqString`; running the whole suite with
189
+ `MIN_LENGTH = 1` checks the corpus the same way.
190
+ - **UTF-8** uses Python's codec (`errors="replace"` gives one U+FFFD per maximal subpart, as §4.1
191
+ says, guide §3.2) instead of the reference's loops.
192
+ - **Sorting** uses Python's stable sort (the same order as the reference's stable merge sort, by the
193
+ same total preorder), keyed by tuples for scalars and arrays of them, by `compare` otherwise.
194
+ - **The JSON reader** keeps the reference's algorithm and messages, with fast paths for strings
195
+ without escapes and for plain integers.
196
+ - **The native table** (guide §1.1) is `runtime/native_table.py`, filled by
197
+ `builtins/registration.py` when the package is imported; the formats of §9.9, which the
198
+ interpreter applies, are reached through it too (`native_table.FORMATS`), so the runtime does not
199
+ import the builtins.
200
+ - **Modules**: `BindImports` and `BindModule`, a partial class of the Resolver in C#, are the
201
+ functions `bind_imports` and `bind_module` of `binding/modules.py`.
202
+ - **The host stack** (guide §3.6): CPython 3.11+ runs Python-to-Python calls without growing the C
203
+ stack, and nothing on the recursive paths of the parser, the resolver or the interpreter calls
204
+ back into Python through C, so no thread is needed (the reference continues on a fresh thread):
205
+ `max_depth` 100,000 runs on a 256 KB thread (`test_the_largest_max_depth_runs_on_a_small_stack`).
206
+ What limits depth is the recursion limit, a counter of Python frames: `syntax/recursion_limit.py`
207
+ raises it while a parse, a binding or an evaluation runs and puts it back when the last one ends.
208
+ A parse needs 8 frames per level of nesting (`PARSE_FRAMES`); an evaluation 16 frames per node of
209
+ the bound program (its `size`, prelude included) per level of `max_depth` (`stack_guard.py`), a
210
+ loose bound that costs nothing until the frames exist.
211
+ - **Regex** (guide §3.3): positions are code point indices, since a Python `str` is indexed by code
212
+ point. The engine reads one code point per index (the reference reads a surrogate pair as one), and
213
+ the natives need no code point map. A pattern that starts with a literal skips to the literal's
214
+ first occurrence with `str.find`, whatever the code point (the reference only for a code point of
215
+ one UTF-16 unit). The matcher's generation counter is never reset: a Python `int` does not
216
+ overflow.
217
+ - **Math** (guide §3.5): `math` raises where IEEE gives a value; each library function checks its
218
+ domain or catches the overflow and returns the IEEE result. `math.fma` (3.13+) raises on
219
+ overflow; there, and before 3.13, `fma` is computed exactly with `fractions.Fraction`.
220
+ - **`s * n`** fails only past 2^31 − 1 UTF-8 bytes, the spec's limit: Python has no smaller string
221
+ limit (the reference's .NET limit stops `"ab" * 1e9`).
222
+ - **Tests left out**, because they are about .NET: the size of a value (16 bytes), the culture of
223
+ number text (`repr` has none), and the tests of the two .NET APIs this port does not have
224
+ (`JqObservableTests`, `JqResourceResolver`). The allocation measurements of `CollectionTests` and
225
+ `AssignTests` are replaced by structural checks (one buffer shared by 10,000 appends, or by
226
+ 100,000 string appends) and, for the native `_modify`, by the growth of its time from 4,000 to
227
+ 32,000 elements (linear, not quadratic as the prelude's definition, which the test also measures).
228
+ - **`JqArray` and `JqObject`** have no `__len__`: a value is never tested for truth (an empty
229
+ array would be false), the engine reads `count`.
230
+
231
+ The single-call rule of spec §7.7 and §11 (commit `3074345`: `Function.single`,
232
+ `CallFunction.single`, `Native.single_when`, the resolver's `Defining` and replay, `eval_one` of
233
+ calls and closure natives) is ported, with the reference's two unit tests.
@@ -0,0 +1,65 @@
1
+ devlooped_jqlite-1.0.0a0.dist-info/licenses/LICENSE,sha256=4_2nqepiUq6X0PdIV5neoDQfCyol4FS_fDRDfFwI_n8,1096
2
+ jqlite/__init__.py,sha256=oDoM0zqpWjBR32GGWoMLa0LsC2Kgzg8rNV-HiqBirRs,3812
3
+ jqlite/exceptions.py,sha256=7oN-LV-Dox1Zx5dKr5j1J5669fuOykQV93l-WWhoLTQ,1495
4
+ jqlite/expression.py,sha256=6lyH59RjZmnFYFIlK2zzwslPQqPId5Tw32IoW_Woxkw,5140
5
+ jqlite/json_adapter.py,sha256=ozyssg0upRAbNLk8wFcyxloFwR10PdKqLopUyBbw7mE,4991
6
+ jqlite/options.py,sha256=h8NBTe8S8oj_Ono3_ML5gSCAOlNQddz4ufk7VQCeH58,3091
7
+ jqlite/prelude.jq,sha256=UlCscGyZhCM8BoIv6ajIBxin792OuLb6A1m90aOLYo8,7908
8
+ jqlite/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
+ jqlite/resolvers.py,sha256=7WuLLVj87TgEjwWFAxlSEOlX9Xzfq-oUXuA2cydBv8M,3688
10
+ jqlite/binding/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
11
+ jqlite/binding/bound.py,sha256=24lwuCjWeumWzw_lNhomnZLI87IOoBExRf4weibdDbY,15615
12
+ jqlite/binding/modules.py,sha256=sxoj0zzI8ntz932M7pfvAPvLQgtUYN_IEmwyim6_pA0,11917
13
+ jqlite/binding/prelude.py,sha256=pD2rDQ-RZcWtazIyQaIbhBjfDFBsXR9DxWA0klnOYy8,3445
14
+ jqlite/binding/resolver.py,sha256=FRKs-euyRAE0IXK379XBkKQrFYy-DCNvAc_PZg9V8ec,33875
15
+ jqlite/builtins/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
16
+ jqlite/builtins/assign_natives.py,sha256=5SkegTJiqVZCWnvMGtVehLKGjX-tqJxX1VB3QgPRWxc,15188
17
+ jqlite/builtins/calendar.py,sha256=62dW2ndxp7kcvrrmfE5pCh1TTc5P5K92nArVkXe3piQ,3547
18
+ jqlite/builtins/collection_natives.py,sha256=WN-skhTZpCmdf3kNez0I7gJNXf-XopOH2tYLPZQWgKg,5587
19
+ jqlite/builtins/containment.py,sha256=E7xdPqKqeDMplb8Zopd4kNKIMhVDWAVpqYzK-LI14Ko,3334
20
+ jqlite/builtins/core_natives.py,sha256=lejHsmZEsfTpVYfgVZLLVTYANyihw76LrCczxknkNTQ,5310
21
+ jqlite/builtins/date_natives.py,sha256=hGp8iq-v4DFH7ke5F3X614avG38dZe4JwGMiha9Blss,5039
22
+ jqlite/builtins/formats.py,sha256=s96hsZ9hzxCgXYW52nSTjrWc0_O2XQno-fZzNLxaQ2E,5987
23
+ jqlite/builtins/loop_natives.py,sha256=pTPIgBirxvMJ1S99ay1q5E4OhbjVhEbY9Z6apc8YVYA,7897
24
+ jqlite/builtins/math_extra.py,sha256=L0Fjrg_1Xvi_vM_OvvLKC7FIi_zRaljHe0EE0C1gvpA,19954
25
+ jqlite/builtins/math_natives.py,sha256=v7tXWazHKJxQMoE444Y9nPRNFH9F0KXsDuUtrp_AeMQ,7815
26
+ jqlite/builtins/module_natives.py,sha256=AloT4H_uiy0MJBvdLO2JGOnWeu4Wry69HB1iv4NBjc8,1058
27
+ jqlite/builtins/natives.py,sha256=s_5kFkSHEAtl_GSEgEx0wG--aiEmAGpm4H9gH1C1NtI,6238
28
+ jqlite/builtins/path_natives.py,sha256=C3ykweJZQM8-C0Gop4sr32adrqAEURiSTOKr_flpKDE,10172
29
+ jqlite/builtins/regex_engine.py,sha256=hfLmsn3vbr0d_jOBIvCTx4i_fho2R6ZIWnS-K1jM5zo,15170
30
+ jqlite/builtins/regex_natives.py,sha256=YYfZ7mWX-NA3VxrA43zBmRQ8ER7bnm4k8eGNRnlb9cI,6051
31
+ jqlite/builtins/regex_syntax.py,sha256=7YdT8N9Vi5N_0_eI1WAkQggPcWgreEQa6cxikiO72rU,28305
32
+ jqlite/builtins/registration.py,sha256=nHyD9-tCFJxs5spEWIqjByJgAq6TWJnTZ4VC5rBHCos,1365
33
+ jqlite/builtins/strftime.py,sha256=4e1b1lIKVZebDRfj-uFeuAt78pJBWlKBNRgXQ-LJQP8,14642
34
+ jqlite/builtins/string_natives.py,sha256=bALxT46OQedg8CR-EQJ3nOppmDVojAG_c7tYZGaF8Mk,4606
35
+ jqlite/runtime/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
36
+ jqlite/runtime/env.py,sha256=_5WbmsDWLbvQigLSUz4623_asQcey9d3hJziv6ObvNk,1485
37
+ jqlite/runtime/evaluation.py,sha256=_GGOAkpsYu5clSep7GuGuOCwievB5C6LOq5g2lEZJ0A,3178
38
+ jqlite/runtime/interpreter.py,sha256=NjJgg9lyegqCj_Qm_cTJkNzUW-w7bup2jhA5mP3PN58,64336
39
+ jqlite/runtime/native_table.py,sha256=wdsevQDHahyNcRKyQuHQGBvmI6yqa07OxoycicbMj9g,2689
40
+ jqlite/runtime/path.py,sha256=9Sj9d7lmLDh5b8mX0q9U02c-alACqClmvFtMASvp6eU,2177
41
+ jqlite/runtime/signal.py,sha256=joLjS7wnc4fDKJ9CYkDbtz46RFq4Jwq09-_DA3nDLQc,2438
42
+ jqlite/runtime/stack_guard.py,sha256=BqyKnVtTLSCjJy08c4_7E8-Xrn5rm6_NnQAz4nkIfJE,2031
43
+ jqlite/syntax/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
44
+ jqlite/syntax/ast.py,sha256=H0spIAzH2m48ZfA5TThoMuXuD-FhjM-h6bj5L9jWiew,13489
45
+ jqlite/syntax/lexer.py,sha256=LAC_MCo58kKUXVMP4aZ_nUUkDSvWK4s17CvJDm8uo9c,12768
46
+ jqlite/syntax/parser.py,sha256=WIKG29oFruu47maI1azFr5tU748irb8-7dwSEmCADKc,42231
47
+ jqlite/syntax/recursion_limit.py,sha256=vXWWTY1Y0HD0QHyZnBx1PAA5IT3J7vzzNIW93C1Y0xs,2722
48
+ jqlite/syntax/syntax_error.py,sha256=bm_YBNbDScKNHVZNJuY-01fRfxQTUW2-_psWqP66u2k,3246
49
+ jqlite/syntax/token.py,sha256=vCe1WfOvpsOvf9xQq_zxR0apt49k00aZBrH-sPH5G4Q,4054
50
+ jqlite/values/__init__.py,sha256=6rJRc1NNPAFUO8b9KibhJsviBvyc0iQQ3MhNt7C-5Ng,623
51
+ jqlite/values/code_points.py,sha256=_9pg4SLBW5_wNW80QgtDXp24vOMHt8mHz0BZNIStwk0,2057
52
+ jqlite/values/errors.py,sha256=YO68BJ4YhbyqHpOEfNDlK9UI9IAdP3ahofvToD2_Mqo,10270
53
+ jqlite/values/jq_array.py,sha256=Iv1wapuzLNm4wEHmvbxM31XTS3lC6Fr8z47qISqL1oU,4437
54
+ jqlite/values/jq_array_builder.py,sha256=zRJI-TMO_eBn-wx2BUYrVvSnVA7K9GV_m9gYtK3C1KE,1461
55
+ jqlite/values/jq_object.py,sha256=XQKx-sQTuK2IRkMWSVjWakblISLskb07ulVAfDb49jQ,6263
56
+ jqlite/values/jq_object_builder.py,sha256=8X12OZWb39Q3yzxT6JxkUffnLim2QnzLw0jOnyGA3uw,2136
57
+ jqlite/values/jq_string.py,sha256=I1FvoYdBS-r8MzWHbfeKCy7ifSQIxNbCEgjqznxbF-c,4165
58
+ jqlite/values/jq_value.py,sha256=7FLRTzAoZTqyOtD8epVg6wrZn4XQk3z-_Xly9a1sfQU,2070
59
+ jqlite/values/utf8.py,sha256=VjGduD520rtC4m2xJvOCZx7TwhueKTGM3hCp20KJoBM,1048
60
+ jqlite/values/value_ops.py,sha256=f-3cNOZzDFgIgqgs2ywzU956S9IlZRzxyqIUWJlwxlg,22046
61
+ jqlite/values/value_text.py,sha256=lm_aVDs-aBN9bZqe27JZG9dnJd1h-rwxC4egsuyi99w,20975
62
+ devlooped_jqlite-1.0.0a0.dist-info/METADATA,sha256=450Us13bhq_3C-tJLTnSPJqCwDv06jTviefJACfS6_k,15846
63
+ devlooped_jqlite-1.0.0a0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
64
+ devlooped_jqlite-1.0.0a0.dist-info/top_level.txt,sha256=5COwhDlsYXk-rtzpGGyRsgDazLmxwKpiWAGs0FwhU1A,7
65
+ devlooped_jqlite-1.0.0a0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.2.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) Daniel Cazzulino and Contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
@@ -0,0 +1 @@
1
+ jqlite
jqlite/__init__.py ADDED
@@ -0,0 +1,79 @@
1
+ """jqlite: the Python port of jqlite, the profile of jq that JQLite implements.
2
+
3
+ The host boundary (spec §12): parse an expression once into an `Expression`, then evaluate it on
4
+ Python JSON values (what `json.loads` gives) as many times as needed, from any thread.
5
+
6
+ >>> import jqlite
7
+ >>> jqlite.evaluate(".a + 1", {"a": 41})
8
+ [42]
9
+ >>> expression = jqlite.parse("[.[] | select(. > $min)]")
10
+ >>> expression.evaluate([1, 5, 10], {"min": 4})
11
+ [[5, 10]]
12
+
13
+ The engine itself is the packages `values`, `syntax`, `binding`, `runtime` and `builtins`.
14
+ """
15
+
16
+ from __future__ import annotations
17
+
18
+ from collections.abc import AsyncIterable, AsyncIterator, Iterable, Iterator, Mapping
19
+ from typing import Any
20
+
21
+ from .builtins.registration import register_all
22
+
23
+ register_all()
24
+
25
+ from .binding.resolver import Resolver as _CoreResolver # noqa: E402
26
+ from .exceptions import JqError, JqHaltError, JqParseError # noqa: E402
27
+ from .expression import Expression # noqa: E402
28
+ from .options import Clock, Options, SystemClock # noqa: E402
29
+ from .resolvers import FileResolver, ModuleKind, Resolver, ResolverSource # noqa: E402
30
+ from .syntax.syntax_error import SyntaxError as _SyntaxError # noqa: E402
31
+
32
+ __all__ = [
33
+ "Clock", "Expression", "FileResolver", "JqError", "JqHaltError", "JqParseError", "ModuleKind", "Options", "Resolver",
34
+ "SystemClock", "evaluate", "evaluate_each", "evaluate_each_async", "parse",
35
+ ]
36
+
37
+ _DEFAULTS = Options()
38
+
39
+
40
+ def parse(expression: str, options: Options | None = None) -> Expression:
41
+ """Parses and binds `expression` (an empty one is `.`), loading its modules through the options'
42
+ resolver, into an expression to evaluate any number of times, concurrently if need be.
43
+
44
+ Raises JqParseError for a syntax or binding error (an unknown function, label or module, a
45
+ cycle of imports), with its line and column.
46
+ """
47
+ if type(expression) is not str:
48
+ raise TypeError("the expression must be a string")
49
+ options = _DEFAULTS if options is None else options
50
+ source = None if options.resolver is None else ResolverSource(options.resolver)
51
+ program = _CoreResolver.try_compile(expression, True, source)
52
+ if type(program) is _SyntaxError:
53
+ where = "" if program.module is None else f"{program.module}, "
54
+ raise JqParseError(f"{program.message} at {where}line {program.line}, column {program.column}",
55
+ program.line, program.column, program.module)
56
+ return Expression(program, options) # type: ignore[arg-type]
57
+
58
+
59
+ def evaluate(expression: str, input: Any, variables: Mapping[str, Any] | None = None, options: Options | None = None) -> list[Any]:
60
+ """Parses `expression` and evaluates it on `input`, returning all its results."""
61
+ return parse(expression, options).evaluate(input, variables)
62
+
63
+
64
+ def evaluate_each(expression: str | Expression, inputs: Iterable[Any], variables: Mapping[str, Any] | None = None) -> Iterator[Any]:
65
+ """Evaluates `expression` on each value of `inputs` in turn (a JSON Lines stream, for
66
+ example), yielding the results of each; the results of one input are computed before they are
67
+ yielded. Each value is evaluated alone: `halt` ends only the evaluation of its value."""
68
+ parsed = parse(expression) if isinstance(expression, str) else expression
69
+ for value in inputs:
70
+ yield from parsed.evaluate(value, variables)
71
+
72
+
73
+ async def evaluate_each_async(expression: str | Expression, inputs: AsyncIterable[Any],
74
+ variables: Mapping[str, Any] | None = None) -> AsyncIterator[Any]:
75
+ """`evaluate_each` over an asynchronous source of values."""
76
+ parsed = parse(expression) if isinstance(expression, str) else expression
77
+ async for value in inputs:
78
+ for result in parsed.evaluate(value, variables):
79
+ yield result
File without changes