# Path: awscfncli2/config/template.py
# def find_references(params):
#     dumps = json.dumps(params)
#     references = []
#     for match in _Template.pattern.findall(dumps):
#         if match and match[2]:
#             references.append(match[2])
#     return references
# 
# def substitute_references(params, **kwargs):
#     dumps = json.dumps(params)
#     return json.loads(_Template(dumps).safe_substitute(**kwargs))


import fnmatch
import copy
from collections import namedtuple
from .template import find_references, substitute_references
class StackMetadata(
    namedtuple('StackMetadata', sorted(StackDefaults.STACK_METADATA))):
    @staticmethod
    def from_dict(**params):
        result = copy.deepcopy(StackDefaults.STACK_METADATA)
        _extends(result, **params)
        return StackMetadata(**result)


class StackProfile(
    namedtuple('StackMetadata', sorted(StackDefaults.STACK_PROFILE))):
    @staticmethod
    def from_dict(**params):
        result = copy.deepcopy(StackDefaults.STACK_PROFILE)
        _extends(result, **params)
        return StackProfile(**result)


class StackParameters(
    namedtuple('StackParameters', sorted(StackDefaults.STACK_PARAMETERS))):
    @staticmethod
    def from_dict(**params):
        result = copy.deepcopy(StackDefaults.STACK_PARAMETERS)
        _extends(result, **params)
        return StackParameters(**result)

    def find_references(self):
        # TODO Need refactor to reduce duplicated ParameterTemplate construction
        return find_references(self._asdict())


# Path: awscfncli2/config/template.py
# def find_references(params):
#     dumps = json.dumps(params)
#     references = []
#     for match in _Template.pattern.findall(dumps):
#         if match and match[2]:
#             references.append(match[2])
#     return references
# 
# def substitute_references(params, **kwargs):
#     dumps = json.dumps(params)
#     return json.loads(_Template(dumps).safe_substitute(**kwargs))


# Path: awscfncli2/config/deployment.py
import fnmatch
import copy
from collections import namedtuple
from .template import find_references, substitute_references

class StackMetadata(
    namedtuple('StackMetadata', sorted(StackDefaults.STACK_METADATA))):
    @staticmethod
    def from_dict(**params):
        result = copy.deepcopy(StackDefaults.STACK_METADATA)
        _extends(result, **params)
        return StackMetadata(**result)


class StackProfile(
    namedtuple('StackMetadata', sorted(StackDefaults.STACK_PROFILE))):
    @staticmethod
    def from_dict(**params):
        result = copy.deepcopy(StackDefaults.STACK_PROFILE)
        _extends(result, **params)
        return StackProfile(**result)


class StackParameters(
    namedtuple('StackParameters', sorted(StackDefaults.STACK_PARAMETERS))):
    @staticmethod
    def from_dict(**params):
        result = copy.deepcopy(StackDefaults.STACK_PARAMETERS)
        _extends(result, **params)
        return StackParameters(**result)

    def find_references(self):
        # TODO Need refactor to reduce duplicated ParameterTemplate construction
        return find_references(self._asdict())


    def substitute_references(self, **args):