11import operator
2+ from numbers import Number
23
34from jmespath import functions
45from jmespath .compat import string_type
5- from numbers import Number
66
77
88def _equals (x , y ):
@@ -58,7 +58,7 @@ def _is_actual_number(x):
5858
5959class Options (object ):
6060 """Options to control how a JMESPath function is evaluated."""
61- def __init__ (self , dict_cls = None , custom_functions = None ):
61+ def __init__ (self , dict_cls = None , custom_functions = None , not_found_value = None ):
6262 #: The class to use when creating a dict. The interpreter
6363 # may create dictionaries during the evaluation of a JMESPath
6464 # expression. For example, a multi-select hash will
@@ -69,6 +69,7 @@ def __init__(self, dict_cls=None, custom_functions=None):
6969 # have predictable key ordering.
7070 self .dict_cls = dict_cls
7171 self .custom_functions = custom_functions
72+ self .not_found_value = not_found_value
7273
7374
7475class _Expression (object ):
@@ -133,9 +134,9 @@ def visit_subexpression(self, node, value):
133134
134135 def visit_field (self , node , value ):
135136 try :
136- return value .get (node ['value' ])
137+ return value .get (node ['value' ], self . _options . not_found_value )
137138 except AttributeError :
138- return None
139+ return self . _options . not_found_value
139140
140141 def visit_comparator (self , node , value ):
141142 # Common case: comparator is == or !=
@@ -298,7 +299,7 @@ def _is_false(self, value):
298299 # because the truth/false values are different between
299300 # python and jmespath.
300301 return (value == '' or value == [] or value == {} or value is None or
301- value is False )
302+ value is False or value == self . _options . not_found_value )
302303
303304 def _is_true (self , value ):
304305 return not self ._is_false (value )
0 commit comments