<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def instantiate_objects(self, node):
 """ Recursively traverse a structure to identify dictionaries that represent objects that need to be instantiated Traverse all values of all dictionaries and all elements of all lists to identify dictionaries that contain the special "ENGINE" key which indicates that a class of that type should be instantiated and passed all key-value pairs found in the sibling "OPTIONS" dictionary as keyword arguments. For example:: tree = { 'a': { 'b': { 'first_obj': { 'ENGINE': 'mypackage.mymodule.Clazz', 'OPTIONS': { 'size': 10, 'foo': 'bar' } } }, 'c': [ { 'ENGINE': 'mypackage.mymodule.Clazz2', 'OPTIONS': { 'more_objects': { 'd': {'ENGINE': 'mypackage.foo.Bar'} } } } ] } } root = self.instantiate_objects(tree) That structure of dicts, lists, and strings will end up with (this example assumes that all keyword arguments to constructors were saved as attributes of the same name):
 assert type(root['a']['b']['first_obj']) == <type 'mypackage.mymodule.Clazz'> assert root['a']['b']['first_obj'].size == 10 assert root['a']['b']['first_obj'].foo == 'bar' assert type(root['a']['c'][0]) == <type 'mypackage.mymodule.Clazz2'> assert type(root['a']['c'][0].more_objects['d']) == <type 'mypackage.foo.Bar'> """

        result = node
        if isinstance(node, dict):
            if 'ENGINE' in node:
                result = self.instantiate_from_dict(node)
            else:
                result = {}
                for key, value in six.iteritems(node):
                    result[key] = self.instantiate_objects(value)
        elif isinstance(node, list):
            result = []
            for child in node:
                result.append(self.instantiate_objects(child))

        return result