22Author : zhangxianbing1
33Date : 2020-12-27 09:22:14
44LastEditors : zhangxianbing1
5- LastEditTime : 2021-01-04 14:10:00
5+ LastEditTime : 2021-01-04 14:34:35
66Description : JSONPath
77"""
88__version__ = "0.0.3"
@@ -220,7 +220,7 @@ def _trace(self, obj, i: int, path):
220220
221221 # slice
222222 if isinstance (obj , list ) and JSONPath .REP_SLICE_CONTENT .fullmatch (step ):
223- obj = [( idx , v ) for idx , v in enumerate (obj )]
223+ obj = list ( enumerate (obj ))
224224 vals = eval (f"obj[{ step } ]" )
225225 for idx , v in vals :
226226 self ._trace (v , i + 1 , f"{ path } { JSONPath .SEP } { idx } " )
@@ -243,12 +243,12 @@ def _trace(self, obj, i: int, path):
243243 # sort
244244 if step .startswith ("/(" ) and step .endswith (")" ):
245245 if isinstance (obj , list ):
246- obj = [( idx , v ) for idx , v in enumerate (obj )]
246+ obj = list ( enumerate (obj ))
247247 self ._sorter (obj , step [2 :- 1 ])
248248 for idx , v in obj :
249249 self ._trace (v , i + 1 , f"{ path } { JSONPath .SEP } { idx } " )
250250 elif isinstance (obj , dict ):
251- obj = [( k , v ) for k , v in obj .items ()]
251+ obj = list ( obj .items ())
252252 self ._sorter (obj , step [2 :- 1 ])
253253 for k , v in obj :
254254 self ._trace (v , i + 1 , f"{ path } { JSONPath .SEP } { k } " )
0 commit comments