jsonpath-rfc9535 2.0.2__tar.gz → 2.1.0__tar.gz

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 (109) hide show
  1. {jsonpath_rfc9535-2.0.2 → jsonpath_rfc9535-2.1.0}/.github/workflows/lint.yaml +1 -1
  2. jsonpath_rfc9535-2.1.0/.github/workflows/publish.yaml +65 -0
  3. {jsonpath_rfc9535-2.0.2 → jsonpath_rfc9535-2.1.0}/.github/workflows/tests.yaml +2 -2
  4. {jsonpath_rfc9535-2.0.2 → jsonpath_rfc9535-2.1.0}/.github/workflows/typing.yaml +1 -1
  5. {jsonpath_rfc9535-2.0.2 → jsonpath_rfc9535-2.1.0}/CHANGELOG.md +8 -0
  6. {jsonpath_rfc9535-2.0.2 → jsonpath_rfc9535-2.1.0}/CONTRIBUTING.md +10 -0
  7. {jsonpath_rfc9535-2.0.2 → jsonpath_rfc9535-2.1.0}/PKG-INFO +3 -2
  8. {jsonpath_rfc9535-2.0.2 → jsonpath_rfc9535-2.1.0}/docs/api.rst +15 -0
  9. {jsonpath_rfc9535-2.0.2 → jsonpath_rfc9535-2.1.0}/pyproject.toml +56 -7
  10. jsonpath_rfc9535-2.1.0/scripts/bench_char_membership.py +61 -0
  11. {jsonpath_rfc9535-2.0.2 → jsonpath_rfc9535-2.1.0}/scripts/bench_citylots.py +7 -5
  12. jsonpath_rfc9535-2.1.0/src/jsonpath_rfc9535/__about__.py +1 -0
  13. {jsonpath_rfc9535-2.0.2 → jsonpath_rfc9535-2.1.0}/src/jsonpath_rfc9535/__init__.py +15 -0
  14. {jsonpath_rfc9535-2.0.2 → jsonpath_rfc9535-2.1.0}/src/jsonpath_rfc9535/_environment.py +28 -3
  15. jsonpath_rfc9535-2.1.0/src/jsonpath_rfc9535/_iregexp.py +321 -0
  16. {jsonpath_rfc9535-2.0.2 → jsonpath_rfc9535-2.1.0}/src/jsonpath_rfc9535/_lexer.py +1 -1
  17. jsonpath_rfc9535-2.1.0/src/jsonpath_rfc9535/_resolver_basic.py +226 -0
  18. jsonpath_rfc9535-2.1.0/src/jsonpath_rfc9535/_resolver_basic_abstract.py +245 -0
  19. jsonpath_rfc9535-2.0.2/src/jsonpath_rfc9535/_resolver_basic.py → jsonpath_rfc9535-2.1.0/src/jsonpath_rfc9535/_resolver_basic_native.py +19 -11
  20. jsonpath_rfc9535-2.1.0/src/jsonpath_rfc9535/_resolver_basic_strict.py +231 -0
  21. jsonpath_rfc9535-2.1.0/src/jsonpath_rfc9535/_resolver_standard.py +229 -0
  22. jsonpath_rfc9535-2.1.0/src/jsonpath_rfc9535/_resolver_standard_abstract.py +248 -0
  23. jsonpath_rfc9535-2.0.2/src/jsonpath_rfc9535/_resolve_standard.py → jsonpath_rfc9535-2.1.0/src/jsonpath_rfc9535/_resolver_standard_native.py +19 -11
  24. jsonpath_rfc9535-2.1.0/src/jsonpath_rfc9535/_resolver_standard_strict.py +234 -0
  25. jsonpath_rfc9535-2.1.0/src/jsonpath_rfc9535/functions.py +277 -0
  26. {jsonpath_rfc9535-2.0.2 → jsonpath_rfc9535-2.1.0}/src/jsonpath_rfc9535/query.py +2 -4
  27. {jsonpath_rfc9535-2.0.2 → jsonpath_rfc9535-2.1.0}/tests/test_compliance.py +18 -19
  28. jsonpath_rfc9535-2.1.0/tests/test_iregexp.py +201 -0
  29. jsonpath_rfc9535-2.1.0/tests/test_regex_functions.py +38 -0
  30. jsonpath_rfc9535-2.1.0/tests/test_resolve_abstract_types.py +47 -0
  31. jsonpath_rfc9535-2.1.0/tools/generate.py +159 -0
  32. jsonpath_rfc9535-2.0.2/src/jsonpath_rfc9535/__about__.py +0 -1
  33. jsonpath_rfc9535-2.0.2/src/jsonpath_rfc9535/functions.py +0 -178
  34. jsonpath_rfc9535-2.0.2/tests/cts/.editorconfig +0 -6
  35. jsonpath_rfc9535-2.0.2/tests/cts/.github/workflows/build_cts_json.yaml +0 -51
  36. jsonpath_rfc9535-2.0.2/tests/cts/.github/workflows/validate_json_schema.yaml +0 -14
  37. jsonpath_rfc9535-2.0.2/tests/cts/CODE_OF_CONDUCT.md +0 -80
  38. jsonpath_rfc9535-2.0.2/tests/cts/CONTRIBUTING.md +0 -122
  39. jsonpath_rfc9535-2.0.2/tests/cts/LICENSE +0 -15
  40. jsonpath_rfc9535-2.0.2/tests/cts/NOTICE +0 -7
  41. jsonpath_rfc9535-2.0.2/tests/cts/README.md +0 -25
  42. jsonpath_rfc9535-2.0.2/tests/cts/build.js +0 -225
  43. jsonpath_rfc9535-2.0.2/tests/cts/build.ps1 +0 -4
  44. jsonpath_rfc9535-2.0.2/tests/cts/build.sh +0 -4
  45. jsonpath_rfc9535-2.0.2/tests/cts/cts.schema.json +0 -142
  46. jsonpath_rfc9535-2.0.2/tests/cts/tests/basic.json +0 -986
  47. jsonpath_rfc9535-2.0.2/tests/cts/tests/filter.json +0 -3849
  48. jsonpath_rfc9535-2.0.2/tests/cts/tests/functions/count.json +0 -194
  49. jsonpath_rfc9535-2.0.2/tests/cts/tests/functions/length.json +0 -276
  50. jsonpath_rfc9535-2.0.2/tests/cts/tests/functions/match.json +0 -466
  51. jsonpath_rfc9535-2.0.2/tests/cts/tests/functions/search.json +0 -483
  52. jsonpath_rfc9535-2.0.2/tests/cts/tests/functions/value.json +0 -86
  53. jsonpath_rfc9535-2.0.2/tests/cts/tests/index_selector.json +0 -242
  54. jsonpath_rfc9535-2.0.2/tests/cts/tests/name_selector.json +0 -1276
  55. jsonpath_rfc9535-2.0.2/tests/cts/tests/slice_selector.json +0 -1323
  56. jsonpath_rfc9535-2.0.2/tests/cts/tests/whitespace/filter.json +0 -420
  57. jsonpath_rfc9535-2.0.2/tests/cts/tests/whitespace/functions.json +0 -652
  58. jsonpath_rfc9535-2.0.2/tests/cts/tests/whitespace/operators.json +0 -2112
  59. jsonpath_rfc9535-2.0.2/tests/cts/tests/whitespace/selectors.json +0 -548
  60. jsonpath_rfc9535-2.0.2/tests/cts/tests/whitespace/slice.json +0 -388
  61. jsonpath_rfc9535-2.0.2/tests/test_iregexp.py +0 -139
  62. {jsonpath_rfc9535-2.0.2 → jsonpath_rfc9535-2.1.0}/.github/FUNDING.yml +0 -0
  63. {jsonpath_rfc9535-2.0.2 → jsonpath_rfc9535-2.1.0}/.gitignore +0 -0
  64. {jsonpath_rfc9535-2.0.2 → jsonpath_rfc9535-2.1.0}/.gitmodules +0 -0
  65. {jsonpath_rfc9535-2.0.2 → jsonpath_rfc9535-2.1.0}/LICENSE.txt +0 -0
  66. {jsonpath_rfc9535-2.0.2 → jsonpath_rfc9535-2.1.0}/README.md +0 -0
  67. {jsonpath_rfc9535-2.0.2 → jsonpath_rfc9535-2.1.0}/docs/_static/jsonpath_rfc9535.xcf +0 -0
  68. {jsonpath_rfc9535-2.0.2 → jsonpath_rfc9535-2.1.0}/docs/_static/jsonpath_rfc9535_dark.png +0 -0
  69. {jsonpath_rfc9535-2.0.2 → jsonpath_rfc9535-2.1.0}/docs/_static/jsonpath_rfc9535_light.png +0 -0
  70. {jsonpath_rfc9535-2.0.2 → jsonpath_rfc9535-2.1.0}/docs/conf.py +0 -0
  71. {jsonpath_rfc9535-2.0.2 → jsonpath_rfc9535-2.1.0}/docs/functions.rst +0 -0
  72. {jsonpath_rfc9535-2.0.2 → jsonpath_rfc9535-2.1.0}/docs/index.rst +0 -0
  73. {jsonpath_rfc9535-2.0.2 → jsonpath_rfc9535-2.1.0}/docs/quick.rst +0 -0
  74. {jsonpath_rfc9535-2.0.2 → jsonpath_rfc9535-2.1.0}/docs/syntax.rst +0 -0
  75. {jsonpath_rfc9535-2.0.2 → jsonpath_rfc9535-2.1.0}/scripts/__init__.py +0 -0
  76. {jsonpath_rfc9535-2.0.2 → jsonpath_rfc9535-2.1.0}/scripts/bench_parse.py +0 -0
  77. {jsonpath_rfc9535-2.0.2 → jsonpath_rfc9535-2.1.0}/scripts/bench_resolve.py +0 -0
  78. {jsonpath_rfc9535-2.0.2 → jsonpath_rfc9535-2.1.0}/scripts/bench_tokenize.py +0 -0
  79. {jsonpath_rfc9535-2.0.2 → jsonpath_rfc9535-2.1.0}/scripts/benchmark.py +0 -0
  80. {jsonpath_rfc9535-2.0.2 → jsonpath_rfc9535-2.1.0}/scripts/micro_bench_types.py +0 -0
  81. {jsonpath_rfc9535-2.0.2 → jsonpath_rfc9535-2.1.0}/scripts/profile_citylots.py +0 -0
  82. {jsonpath_rfc9535-2.0.2 → jsonpath_rfc9535-2.1.0}/scripts/profile_types_memory.py +0 -0
  83. {jsonpath_rfc9535-2.0.2 → jsonpath_rfc9535-2.1.0}/src/jsonpath_rfc9535/__main__.py +0 -0
  84. {jsonpath_rfc9535-2.0.2 → jsonpath_rfc9535-2.1.0}/src/jsonpath_rfc9535/_ast.py +0 -0
  85. {jsonpath_rfc9535-2.0.2 → jsonpath_rfc9535-2.1.0}/src/jsonpath_rfc9535/_debug.py +0 -0
  86. {jsonpath_rfc9535-2.0.2 → jsonpath_rfc9535-2.1.0}/src/jsonpath_rfc9535/_lru_cache.py +0 -0
  87. {jsonpath_rfc9535-2.0.2 → jsonpath_rfc9535-2.1.0}/src/jsonpath_rfc9535/_node.py +0 -0
  88. {jsonpath_rfc9535-2.0.2 → jsonpath_rfc9535-2.1.0}/src/jsonpath_rfc9535/_nothing.py +0 -0
  89. {jsonpath_rfc9535-2.0.2 → jsonpath_rfc9535-2.1.0}/src/jsonpath_rfc9535/_parser.py +0 -0
  90. {jsonpath_rfc9535-2.0.2 → jsonpath_rfc9535-2.1.0}/src/jsonpath_rfc9535/_parser_standard.py +0 -0
  91. {jsonpath_rfc9535-2.0.2 → jsonpath_rfc9535-2.1.0}/src/jsonpath_rfc9535/_resolver.py +0 -0
  92. {jsonpath_rfc9535-2.0.2 → jsonpath_rfc9535-2.1.0}/src/jsonpath_rfc9535/_serialize.py +0 -0
  93. {jsonpath_rfc9535-2.0.2 → jsonpath_rfc9535-2.1.0}/src/jsonpath_rfc9535/_tokens.py +0 -0
  94. {jsonpath_rfc9535-2.0.2 → jsonpath_rfc9535-2.1.0}/src/jsonpath_rfc9535/cli.py +0 -0
  95. {jsonpath_rfc9535-2.0.2 → jsonpath_rfc9535-2.1.0}/src/jsonpath_rfc9535/exceptions.py +0 -0
  96. {jsonpath_rfc9535-2.0.2 → jsonpath_rfc9535-2.1.0}/src/jsonpath_rfc9535/py.typed +0 -0
  97. {jsonpath_rfc9535-2.0.2 → jsonpath_rfc9535-2.1.0}/tests/canonical_paths.json +0 -0
  98. {jsonpath_rfc9535-2.0.2 → jsonpath_rfc9535-2.1.0}/tests/test_api.py +0 -0
  99. {jsonpath_rfc9535-2.0.2 → jsonpath_rfc9535-2.1.0}/tests/test_canonical_paths.py +0 -0
  100. {jsonpath_rfc9535-2.0.2 → jsonpath_rfc9535-2.1.0}/tests/test_cli.py +0 -0
  101. {jsonpath_rfc9535-2.0.2 → jsonpath_rfc9535-2.1.0}/tests/test_env.py +0 -0
  102. {jsonpath_rfc9535-2.0.2 → jsonpath_rfc9535-2.1.0}/tests/test_errors.py +0 -0
  103. {jsonpath_rfc9535-2.0.2 → jsonpath_rfc9535-2.1.0}/tests/test_ietf_examples.py +0 -0
  104. {jsonpath_rfc9535-2.0.2 → jsonpath_rfc9535-2.1.0}/tests/test_ietf_well_typedness.py +0 -0
  105. {jsonpath_rfc9535-2.0.2 → jsonpath_rfc9535-2.1.0}/tests/test_issues.py +0 -0
  106. {jsonpath_rfc9535-2.0.2 → jsonpath_rfc9535-2.1.0}/tests/test_lru_cache.py +0 -0
  107. {jsonpath_rfc9535-2.0.2 → jsonpath_rfc9535-2.1.0}/tests/test_node.py +0 -0
  108. {jsonpath_rfc9535-2.0.2 → jsonpath_rfc9535-2.1.0}/tests/test_regex_cache.py +0 -0
  109. {jsonpath_rfc9535-2.0.2 → jsonpath_rfc9535-2.1.0}/tests/test_tokenize.py +0 -0
@@ -14,4 +14,4 @@ jobs:
14
14
  run: |
15
15
  python -m pip install --upgrade pip
16
16
  python -m pip install --upgrade hatch
17
- - run: hatch run lint
17
+ - run: hatch run lint-ci
@@ -0,0 +1,65 @@
1
+ name: Build and publish to PyPI
2
+
3
+ on:
4
+ workflow_dispatch:
5
+
6
+ permissions:
7
+ contents: read
8
+
9
+ jobs:
10
+ build:
11
+ name: Build distributions
12
+ runs-on: ubuntu-latest
13
+ timeout-minutes: 15
14
+
15
+ steps:
16
+ - name: Check out repository
17
+ uses: actions/checkout@v7
18
+
19
+ - name: Set up Python
20
+ uses: actions/setup-python@v7
21
+ with:
22
+ python-version: "3.14"
23
+
24
+ - name: Install Hatch
25
+ run: python -m pip install --upgrade hatch
26
+
27
+ - name: Build distributions
28
+ run: hatch build
29
+
30
+ - name: Validate package
31
+ run: |
32
+ python -m pip install --upgrade twine
33
+ python -m twine check dist/*
34
+
35
+ - name: Upload distributions
36
+ uses: actions/upload-artifact@v7
37
+ with:
38
+ name: python-package-distributions
39
+ path: dist/
40
+ if-no-files-found: error
41
+ retention-days: 30
42
+
43
+ publish:
44
+ name: Publish to PyPI
45
+ needs: build
46
+ runs-on: ubuntu-latest
47
+ timeout-minutes: 15
48
+
49
+ environment:
50
+ name: pypi
51
+ url: https://github.com/jg-rp/python-jsonpath-rfc9535/
52
+
53
+ permissions:
54
+ id-token: write
55
+
56
+
57
+ steps:
58
+ - name: Download distributions
59
+ uses: actions/download-artifact@v8
60
+ with:
61
+ name: python-package-distributions
62
+ path: dist/
63
+
64
+ - name: Publish to PyPI
65
+ uses: pypa/gh-action-pypi-publish@release/v1
@@ -9,7 +9,7 @@ jobs:
9
9
  fail-fast: false
10
10
  matrix:
11
11
  os: [ubuntu-latest, windows-latest, macos-latest]
12
- python-version: ["3.12", "3.13", "3.14"]
12
+ python-version: ["3.12", "3.13", "3.14", "3.15"]
13
13
  steps:
14
14
  - uses: actions/checkout@v7
15
15
  with:
@@ -23,4 +23,4 @@ jobs:
23
23
  python -m pip install --upgrade pip
24
24
  python -m pip install --upgrade hatch
25
25
  - name: Test
26
- run: hatch run test
26
+ run: hatch run test-ci
@@ -14,4 +14,4 @@ jobs:
14
14
  run: |
15
15
  python -m pip install --upgrade pip
16
16
  python -m pip install --upgrade hatch
17
- - run: hatch run typing
17
+ - run: hatch run typing-ci
@@ -1,5 +1,13 @@
1
1
  # Python JSONPath RFC 9535 Change Log
2
2
 
3
+ ## Version 2.1.0
4
+
5
+ - Added support for PyPy 3.12 (as a result of removing the iregexp-check dependency).
6
+ - Removed the iregexp-check dependency in favour of our own faster and more correct implementation.
7
+ - Added an `escape_anchors` argument to `jsonpath_rfc9535.functions.Match` and `jsonpath_rfc9535.functions.Search` for controlling `^` and `$` behavior in regular expression patterns.
8
+ - Added non-standard versions of the `match` and `search` functions for anyone who wants to opt out of I-Regexp validation and mapping altogether. `jsonpath_rfc9535.functions.PyMatch` and `jsonpath_rfc9535.functions.PySearch` use Python's built-in `re` module.
9
+ - Added the `composite_types` argument to the `JSONPathEnvironment` constructor. In order from fastest to slowest, `composite_types` can be one of `"strict"`, `"native"` or `"abstract"`. Strict type detection works with data composed of `list` and `dict` instances. Native type detection works with data composed of lists, dicts and list/dict subclasses. And abstract type detection works with data composed of Mapping and Sequence types.
10
+
3
11
  ## Version 2.0.2
4
12
 
5
13
  **Fixes**
@@ -45,6 +45,16 @@ $ hatch run cov
45
45
 
46
46
  Then open `htmlcov/index.html` in your browser.
47
47
 
48
+ ### Code generation
49
+
50
+ For performance reasons, we use `tools/generate.py` to generate multiple versions of `src/jsonpath_rfc9535/_resolver_basic.py` and `src/jsonpath_rfc9535/_resolver_standard.py` with hard coded data type checks.
51
+
52
+ `generate.py` is run automatically before `hatch run test`, but not when running `pytest` directly.
53
+
54
+ Generated files must be committed to Git and included in package builds.
55
+
56
+ Generated files must not be edited directly.
57
+
48
58
  ## Documentation
49
59
 
50
60
  Documentation lives in the `docs` directory and is built with Sphinx. Build it to the `site` directory with:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: jsonpath-rfc9535
3
- Version: 2.0.2
3
+ Version: 2.1.0
4
4
  Summary: RFC 9535 - JSONPath: Query Expressions for JSON in Python
5
5
  Project-URL: Documentation, https://jg-rp.github.io/python-jsonpath-rfc9535/
6
6
  Project-URL: Issues, https://github.com/jg-rp/python-jsonpath-rfc9535/issues
@@ -13,9 +13,10 @@ Classifier: Programming Language :: Python
13
13
  Classifier: Programming Language :: Python :: 3.12
14
14
  Classifier: Programming Language :: Python :: 3.13
15
15
  Classifier: Programming Language :: Python :: 3.14
16
+ Classifier: Programming Language :: Python :: 3.15
16
17
  Classifier: Programming Language :: Python :: Implementation :: CPython
18
+ Classifier: Programming Language :: Python :: Implementation :: PyPy
17
19
  Requires-Python: >=3.12
18
- Requires-Dist: iregexp-check>=0.1.4
19
20
  Requires-Dist: regex
20
21
  Description-Content-Type: text/markdown
21
22
 
@@ -27,12 +27,27 @@ API Docs
27
27
  .. autoclass:: jsonpath_rfc9535.JSONPathNodeList
28
28
  :members:
29
29
 
30
+ .. autofunction:: jsonpath_rfc9535.check_iregexp
31
+
32
+ .. autofunction:: jsonpath_rfc9535.map_iregexp
33
+
34
+ Query resolvers
35
+ ---------------
36
+
37
+ .. autoclass:: jsonpath_rfc9535.BasicResolverStrict
38
+ .. autoclass:: jsonpath_rfc9535.BasicResolverNative
39
+ .. autoclass:: jsonpath_rfc9535.BasicResolverAbstract
40
+ .. autoclass:: jsonpath_rfc9535.StandardResolverStrict
41
+ .. autoclass:: jsonpath_rfc9535.StandardResolverNative
42
+ .. autoclass:: jsonpath_rfc9535.StandardResolverAbstract
43
+
30
44
  Function Extensions
31
45
  -------------------
32
46
 
33
47
  .. automodule:: jsonpath_rfc9535.functions
34
48
  :members:
35
49
  :member-order: bysource
50
+ :show-inheritance:
36
51
 
37
52
  Exceptions
38
53
  ----------
@@ -21,10 +21,12 @@ classifiers = [
21
21
  "Programming Language :: Python :: 3.12",
22
22
  "Programming Language :: Python :: 3.13",
23
23
  "Programming Language :: Python :: 3.14",
24
+ "Programming Language :: Python :: 3.15",
24
25
  "Programming Language :: Python :: Implementation :: CPython",
26
+ "Programming Language :: Python :: Implementation :: PyPy",
25
27
  ]
26
28
 
27
- dependencies = ["regex", "iregexp-check>=0.1.4"]
29
+ dependencies = ["regex"]
28
30
 
29
31
  [project.urls]
30
32
  Documentation = "https://jg-rp.github.io/python-jsonpath-rfc9535/"
@@ -61,16 +63,63 @@ extra-dependencies = [
61
63
 
62
64
 
63
65
  [tool.hatch.envs.default.scripts]
64
- cov = "pytest --cov=jsonpath_rfc9535 tests/"
65
- docs-build = "sphinx-build -d .doctrees -b html docs site --fail-on-warning {args}"
66
+ generate = "python tools/generate.py"
67
+ generate-check = "python tools/generate.py --check"
68
+
69
+ cov = [
70
+ "generate",
71
+ "pytest --cov=jsonpath_rfc9535 tests/"
72
+ ]
73
+
74
+ docs-build = [
75
+ "generate",
76
+ "sphinx-build -d .doctrees -b html docs site --fail-on-warning {args}"
77
+ ]
78
+
66
79
  docs-deploy = [
67
80
  "docs-build",
68
81
  "ghp-import --push --force site"
69
82
  ]
70
- test = "pytest {args}"
71
- lint = "ruff check ."
72
- typing = "mypy src"
83
+
84
+ test = [
85
+ "generate",
86
+ "pytest {args}"
87
+ ]
88
+
89
+ lint = [
90
+ "generate",
91
+ "ruff check ."
92
+ ]
93
+
94
+ typing = [
95
+ "generate",
96
+ "mypy src"
97
+ ]
98
+
99
+ test-ci = [
100
+ "generate-check",
101
+ "pytest {args}"
102
+ ]
103
+
104
+ lint-ci = "ruff check ."
105
+ typing-ci = "mypy src"
73
106
 
74
107
 
108
+ [tool.hatch.envs.pypy]
109
+ template = "pypy"
110
+ python = "pypy312"
111
+ dependencies = []
112
+
75
113
  [[tool.hatch.envs.all.matrix]]
76
- python = ["3.12", "3.13", "3.14"]
114
+ python = ["3.12", "3.13", "3.14", "3.15"]
115
+
116
+
117
+ [tool.coverage.run]
118
+ omit = [
119
+ "src/jsonpath_rfc9535/_resolver_basic.py",
120
+ "src/jsonpath_rfc9535/_resolver_standard.py",
121
+ "src/jsonpath_rfc9535/_debug.py",
122
+ "scripts/*",
123
+ "tools/*",
124
+ "dev.py"
125
+ ]
@@ -0,0 +1,61 @@
1
+ import statistics
2
+ import timeit
3
+ from collections.abc import Container
4
+
5
+ chars = r"()*+-...?[\\]^nrt{|}"
6
+
7
+ containers: dict[str, Container[str]] = {
8
+ "string": chars,
9
+ "tuple": tuple(chars),
10
+ "set": set(chars),
11
+ "frozenset": frozenset(chars),
12
+ }
13
+
14
+ test_chars = {
15
+ "hit": "n",
16
+ "miss": "z",
17
+ }
18
+
19
+ NUMBER = 1_000_000
20
+ REPEAT = 7
21
+
22
+ print(f"Iterations per run: {NUMBER:,}")
23
+ print(f"Repeats: {REPEAT}")
24
+ print()
25
+
26
+ for test_name, ch in test_chars.items():
27
+ print(f"--- {test_name.upper()} ({ch!r}) ---")
28
+
29
+ results: list[tuple[str, float, float]] = []
30
+
31
+ for container_name, container in containers.items():
32
+ stmt = "ch in container"
33
+ setup = "pass"
34
+
35
+ times = timeit.repeat(
36
+ stmt=stmt,
37
+ setup=setup,
38
+ globals={"ch": ch, "container": container},
39
+ number=NUMBER,
40
+ repeat=REPEAT,
41
+ )
42
+
43
+ best = min(times)
44
+ median = statistics.median(times)
45
+
46
+ results.append((container_name, best, median))
47
+
48
+ # Sort by best execution time
49
+ results.sort(key=lambda x: x[1])
50
+
51
+ fastest = results[0][1]
52
+
53
+ for name, best, median in results:
54
+ print(
55
+ f"{name:10s}: "
56
+ f"best={best:.6f}s "
57
+ f"median={median:.6f}s "
58
+ f"relative={best / fastest:.2f}x"
59
+ )
60
+
61
+ print()
@@ -2,7 +2,7 @@ import dataclasses
2
2
  import json
3
3
  import timeit
4
4
 
5
- from jsonpath_rfc9535 import compile
5
+ from jsonpath_rfc9535 import JSONPathEnvironment
6
6
 
7
7
 
8
8
  @dataclasses.dataclass
@@ -35,13 +35,15 @@ FIXTURES: list[Fixture] = [
35
35
  ),
36
36
  ]
37
37
 
38
+ ENV = JSONPathEnvironment(composite_types="strict")
39
+
38
40
  QUERIES = {
39
- "shallow": compile("$.features..properties"),
40
- "deep": compile("$.features..properties.BLOCK_NUM"),
41
- "conditional": compile(
41
+ "shallow": ENV.compile("$.features..properties"),
42
+ "deep": ENV.compile("$.features..properties.BLOCK_NUM"),
43
+ "conditional": ENV.compile(
42
44
  "$.features[?@.properties.STREET=='UNKNOWN'].properties.BLOCK_NUM"
43
45
  ),
44
- "regex": compile(
46
+ "regex": ENV.compile(
45
47
  "$.features[?match(@.properties.STREET, 'UNKNOWN')].properties.BLOCK_NUM"
46
48
  ),
47
49
  }
@@ -0,0 +1 @@
1
+ __version__ = "2.1.0"
@@ -4,9 +4,16 @@ from collections.abc import Iterable
4
4
 
5
5
  from ._debug import tree_view
6
6
  from ._environment import JSONPathEnvironment
7
+ from ._iregexp import check_iregexp, map_iregexp
7
8
  from ._node import JSONPathNode, JSONPathNodeList, Node, NodeList
8
9
  from ._parser import Parser, Parser_
9
10
  from ._parser_standard import StandardParser
11
+ from ._resolver_basic_abstract import BasicResolverAbstract
12
+ from ._resolver_basic_native import BasicResolverNative
13
+ from ._resolver_basic_strict import BasicResolverStrict
14
+ from ._resolver_standard_abstract import StandardResolverAbstract
15
+ from ._resolver_standard_native import StandardResolverNative
16
+ from ._resolver_standard_strict import StandardResolverStrict
10
17
  from .exceptions import (
11
18
  DetailedJSONPathError,
12
19
  JSONPathError,
@@ -30,6 +37,9 @@ __all__ = (
30
37
  "LOGICAL_TYPE",
31
38
  "NODES_TYPE",
32
39
  "VALUE_TYPE",
40
+ "BasicResolverAbstract",
41
+ "BasicResolverNative",
42
+ "BasicResolverStrict",
33
43
  "DetailedJSONPathError",
34
44
  "ExpressionType",
35
45
  "FunctionExtension",
@@ -48,6 +58,11 @@ __all__ = (
48
58
  "Parser",
49
59
  "Parser_",
50
60
  "StandardParser",
61
+ "StandardResolverAbstract",
62
+ "StandardResolverNative",
63
+ "StandardResolverStrict",
64
+ "check_iregexp",
65
+ "map_iregexp",
51
66
  "parse",
52
67
  "tree_view",
53
68
  )
@@ -1,15 +1,22 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  from collections.abc import Iterable
4
- from typing import TYPE_CHECKING
4
+ from typing import TYPE_CHECKING, Literal
5
5
 
6
6
  from . import functions
7
7
  from ._node import JSONPathNode, JSONPathNodeList
8
8
  from ._parser import Parser
9
9
  from ._parser_standard import StandardParser
10
+ from ._resolver_basic_abstract import BasicResolverAbstract
11
+ from ._resolver_basic_native import BasicResolverNative
12
+ from ._resolver_basic_strict import BasicResolverStrict
13
+ from ._resolver_standard_abstract import StandardResolverAbstract
14
+ from ._resolver_standard_native import StandardResolverNative
15
+ from ._resolver_standard_strict import StandardResolverStrict
10
16
  from .query import JSONPathQuery
11
17
 
12
18
  if TYPE_CHECKING:
19
+ from ._resolver import BasicResolver, Resolver
13
20
  from .functions import FunctionExtension
14
21
 
15
22
 
@@ -29,8 +36,15 @@ class JSONPathEnvironment:
29
36
  The maximum depth the descendant segment can go before a `JSONPathRecursionError`
30
37
  is raised.
31
38
  parser
32
- The JSONPath query parser to use. You can subclass `StandardParser` to customize
33
- JSONPath parsing behavior.
39
+ The JSONPath query parser to use. You can subclass ``StandardParser`` to
40
+ customize JSONPath parsing behavior.
41
+ composite_types
42
+ One of ``"strict"``, ``"native"`` or ``"abstract"``.
43
+
44
+ In order from fastest to slowest, the strict strategy works with data composed of
45
+ :class:`list` and :class:`dict` instances. The native strategy works with data
46
+ composed of lists, dicts and list/dict subclasses. And the abstract strategy
47
+ works with data composed of Mapping and Sequence types.
34
48
 
35
49
  Attributes
36
50
  ----------
@@ -47,6 +61,7 @@ class JSONPathEnvironment:
47
61
  max_recursion_depth: int = 100,
48
62
  max_expression_depth: int = 30,
49
63
  parser: Parser = StandardParser,
64
+ composite_types: Literal["strict", "native", "abstract"] = "native",
50
65
  ) -> None:
51
66
 
52
67
  self.max_recursion_depth = max_recursion_depth
@@ -56,6 +71,16 @@ class JSONPathEnvironment:
56
71
 
57
72
  self.parser: Parser = parser
58
73
 
74
+ if composite_types == "strict":
75
+ self.resolver: Resolver = StandardResolverStrict
76
+ self.basic_resolver: BasicResolver = BasicResolverStrict
77
+ elif composite_types == "native":
78
+ self.resolver = StandardResolverNative
79
+ self.basic_resolver = BasicResolverNative
80
+ else:
81
+ self.resolver = StandardResolverAbstract
82
+ self.basic_resolver = BasicResolverAbstract
83
+
59
84
  self.functions: dict[str, FunctionExtension] = {
60
85
  "count": functions.Count(),
61
86
  "length": functions.Length(),