44
55# python imports
66from typing import Union
7+ from collections import OrderedDict
78
89
910class Parser :
@@ -67,7 +68,7 @@ def find_key(self, data, key):
6768
6869 if type (elem ) is list :
6970 self ._stack_push_list_elem (elem )
70- elif type (elem ) is dict :
71+ elif isinstance (elem , ( dict , OrderedDict )) :
7172 value = self ._stack_all_key_values_in_dict (key , elem )
7273 if value :
7374 for v in value :
@@ -95,7 +96,7 @@ def find_keys(self, data, keys, group=True):
9596
9697 if type (elem ) is list :
9798 self ._stack_push_list_elem (elem )
98- elif type (elem ) is dict :
99+ elif isinstance (elem , ( dict , OrderedDict )) :
99100 value = self ._stack_all_keys_values_in_dict (keys , elem )
100101 if value and group :
101102 value_list .insert (0 , value )
@@ -132,7 +133,7 @@ def find_key_chain(self, data, keys):
132133
133134 if type (elem ) is list :
134135 self ._queue_push_list_elem (elem )
135- elif type (elem ) is dict :
136+ elif isinstance (elem , ( dict , OrderedDict )) :
136137 if self ._queue_all_key_values_in_dict (keys [0 ], elem ):
137138 key_found = True
138139 else : # according to RFC 7159, valid JSON can also contain a
@@ -163,7 +164,7 @@ def find_key_value(self, data, key, value):
163164
164165 if type (elem ) is list :
165166 self ._stack_push_list_elem (elem )
166- elif type (elem ) is dict :
167+ elif isinstance (elem , ( dict , OrderedDict )) :
167168 if self ._stack_all_key_and_value_in_dict (key , value , elem ):
168169 value_list .insert (0 , elem )
169170 else : # according to RFC 7159, valid JSON can also contain a
@@ -189,7 +190,7 @@ def find_value(self, data, value):
189190
190191 if type (elem ) is list :
191192 self ._stack_push_list_elem (elem )
192- elif type (elem ) is dict :
193+ elif isinstance (elem , ( dict , OrderedDict )) :
193194 key = self ._stack_all_value_in_dict (value , elem )
194195 if key :
195196 key_list .insert (0 , key )
@@ -244,7 +245,7 @@ def _stack_all_key_values_in_dict(self, key, elem):
244245 # type: (str, dict) -> list
245246 value_list = []
246247
247- if type (elem ) is not dict :
248+ if not isinstance (elem , ( dict , OrderedDict )) :
248249 raise TypeError
249250 elif type (key ) is not str :
250251 raise TypeError
@@ -264,7 +265,7 @@ def _stack_all_keys_values_in_dict(self, keys, elem):
264265 # type: (list, dict) -> list
265266 value_list = []
266267
267- if type (elem ) is not dict :
268+ if not isinstance (elem , ( dict , OrderedDict )) :
268269 raise TypeError
269270 elif type (keys ) is not list :
270271 raise TypeError
@@ -285,7 +286,7 @@ def _stack_all_keys_values_in_dict(self, keys, elem):
285286
286287 def _stack_all_key_and_value_in_dict (self , key , value , elem ):
287288 # type: (str, Union[str, int, float, bool, None], dict) -> bool
288- if type (elem ) is not dict :
289+ if not isinstance (elem , ( dict , OrderedDict )) :
289290 raise TypeError
290291 elif type (key ) is not str :
291292 raise TypeError
@@ -305,7 +306,7 @@ def _stack_all_key_and_value_in_dict(self, key, value, elem):
305306
306307 def _stack_all_value_in_dict (self , value , elem ):
307308 # type: (Union[str, int, float, bool, None], dict) -> str
308- if type (elem ) is not dict :
309+ if not isinstance (elem , ( dict , OrderedDict )) :
309310 raise TypeError
310311 elif not isinstance (value , (str , int , float , bool , type (None ))):
311312 raise TypeError
@@ -374,7 +375,7 @@ def _queue_push_list_elem(self, elem):
374375 def _queue_all_key_values_in_dict (self , key , elem ):
375376 # type: (str, dict) -> bool
376377 found = False
377- if type (elem ) is not dict :
378+ if not isinstance (elem , ( dict , OrderedDict )) :
378379 raise TypeError
379380 elif type (key ) is not str :
380381 raise TypeError
@@ -406,8 +407,8 @@ def _queue_trace(self):
406407 # Input validation
407408
408409 def _valid_key_input (self , data , key ):
409- # type: (Union[dict, list], str) -> bool
410- if not isinstance (data , (dict , list )):
410+ # type: (Union[dict, list, OrderedDict ], str) -> bool
411+ if not isinstance (data , (dict , list , OrderedDict )):
411412 raise TypeError
412413 elif not isinstance (key , str ):
413414 raise TypeError
@@ -416,8 +417,8 @@ def _valid_key_input(self, data, key):
416417 return True
417418
418419 def _valid_keys_input (self , data , keys , group ):
419- # type: (Union[dict, list], list, bool) -> bool
420- if not isinstance (data , (dict , list )):
420+ # type: (Union[dict, list, OrderedDict ], list, bool) -> bool
421+ if not isinstance (data , (dict , list , OrderedDict )):
421422 raise TypeError
422423 elif not isinstance (keys , list ):
423424 raise TypeError
@@ -428,8 +429,8 @@ def _valid_keys_input(self, data, keys, group):
428429 return True
429430
430431 def _valid_key_chain_input (self , data , keys ):
431- # type: (Union[dict, list], list) -> bool
432- if not isinstance (data , (dict , list )):
432+ # type: (Union[dict, list, OrderedDict ], list) -> bool
433+ if not isinstance (data , (dict , list , OrderedDict )):
433434 raise TypeError
434435 elif not isinstance (keys , list ):
435436 raise TypeError
@@ -443,8 +444,8 @@ def _valid_key_chain_input(self, data, keys):
443444 return True
444445
445446 def _valid_key_value_input (self , data , key , value ):
446- # type: (Union[dict, list], str, Union[str, int, float, bool, None]) -> bool
447- if not isinstance (data , (dict , list )):
447+ # type: (Union[dict, list, OrderedDict ], str, Union[str, int, float, bool, None]) -> bool
448+ if not isinstance (data , (dict , list , OrderedDict )):
448449 raise TypeError
449450 elif not isinstance (key , str ):
450451 raise TypeError
@@ -455,8 +456,8 @@ def _valid_key_value_input(self, data, key, value):
455456 return True
456457
457458 def _valid_value_input (self , data , value ):
458- # type: (Union[dict, list], Union[str, int, float, bool, None]) -> bool
459- if not isinstance (data , (dict , list )):
459+ # type: (Union[dict, list, OrderedDict ], Union[str, int, float, bool, None]) -> bool
460+ if not isinstance (data , (dict , list , OrderedDict )):
460461 raise TypeError
461462 elif not isinstance (value , (str , int , float , bool , type (None ))):
462463 raise TypeError
0 commit comments