recursively substitute value with the context_dict

def __substitute_objects(self, value, context_dict):
        """
        recursively substitute value with the context_dict
        """
        if type(value) == dict:
            return dict([(k, self.__substitute_objects(v, context_dict)) for k, v in value.items()])
        elif type(value) == str:
            try:
                return value % context_dict
            except KeyError:
                e = sys.exc_info()[1]
                logger.warn("Could not specialize %s! Error: %s" % (value, e))
                return value
        else:
            return value