@@ -35,7 +35,7 @@ def _is_special_integer_case(x, y):
35
35
36
36
class Options (object ):
37
37
"""Options to control how a JMESPath function is evaluated."""
38
- def __init__ (self , dict_cls ):
38
+ def __init__ (self , dict_cls = None , custom_functions = None ):
39
39
#: The class to use when creating a dict. The interpreter
40
40
# may create dictionaries during the evalution of a JMESPath
41
41
# expression. For example, a multi-select hash will
@@ -45,6 +45,7 @@ def __init__(self, dict_cls):
45
45
# want to set a collections.OrderedDict so that you can
46
46
# have predictible key ordering.
47
47
self .dict_cls = dict_cls
48
+ self .custom_functions = custom_functions
48
49
49
50
50
51
class _Expression (object ):
@@ -87,11 +88,16 @@ class TreeInterpreter(Visitor):
87
88
88
89
def __init__ (self , options = None ):
89
90
super (TreeInterpreter , self ).__init__ ()
90
- self ._options = options
91
91
self ._dict_cls = self .MAP_TYPE
92
- if options is not None and options .dict_cls is not None :
92
+ if options is None :
93
+ options = Options ()
94
+ self ._options = options
95
+ if options .dict_cls is not None :
93
96
self ._dict_cls = self ._options .dict_cls
94
- self ._functions = functions .RuntimeFunctions ()
97
+ if options .custom_functions is not None :
98
+ self ._functions = self ._options .custom_functions
99
+ else :
100
+ self ._functions = functions .RuntimeFunctions ()
95
101
96
102
def default_visit (self , node , * args , ** kwargs ):
97
103
raise NotImplementedError (node ['type' ])
0 commit comments