1- """Core JSONPath objects ."""
1+ """Core JSONPath configuration object ."""
22from __future__ import annotations
33
44import json
1010from typing import Iterable
1111from typing import List
1212from typing import Mapping
13+ from typing import Optional
1314from typing import Sequence
1415from typing import Union
1516
1920from .filter import UNDEFINED
2021
2122from .lex import Lexer
23+ from .match import FilterContextVars
2224from .parse import Parser
2325
24- from .path import JSONPath
2526from .path import CompoundJSONPath
27+ from .path import JSONPath
2628
2729from .stream import TokenStream
2830
@@ -40,7 +42,7 @@ class JSONPathEnvironment:
4042 root_token = "$"
4143 self_token = "@"
4244 union_token = "|"
43- context_vars_token = "#"
45+ filter_context_token = "#"
4446
4547 # Unquoted mapping keys (JSON object properties) should match this
4648 # pattern. It should be raw/escaped.
@@ -93,6 +95,8 @@ def findall(
9395 self ,
9496 path : str ,
9597 data : Union [str , Sequence [Any ], Mapping [str , Any ]],
98+ * ,
99+ filter_context : Optional [FilterContextVars ] = None ,
96100 ) -> List [object ]:
97101 """Find all objects in `data` matching the given JSONPath. Return a
98102 list of matches, or an empty list if no matches.
@@ -105,12 +109,14 @@ def findall(
105109 _path = self .compile (path )
106110 if isinstance (data , str ):
107111 data = json .loads (data )
108- return _path .findall (data )
112+ return _path .findall (data , filter_context = filter_context )
109113
110114 def finditer (
111115 self ,
112116 path : str ,
113117 data : Union [str , Sequence [Any ], Mapping [str , Any ]],
118+ * ,
119+ filter_context : Optional [FilterContextVars ] = None ,
114120 ) -> Iterable [object ]:
115121 """Return an iterator yielding :class:`JSONPathMatch` objects for each
116122 match of the path in the given `data`.
@@ -122,7 +128,9 @@ def finditer(
122128 _path = self .compile (path )
123129 if isinstance (data , str ):
124130 data = json .loads (data )
125- return _path .finditer (data )
131+ return _path .finditer (data , filter_context = filter_context )
132+
133+ # TODO: async findall and finditer
126134
127135 def getitem (self , obj : Any , key : Any ) -> Any :
128136 """Sequence and mapping item getter used throughout JSONPath resolution."""
0 commit comments