# Path: awscfncli2/cli/utils/colormaps.py
# CHANGESET_STATUS_TO_COLOR = ColorMap(_CHANGESET_STATUS_TO_COLOR)
# 
# CHANGESET_ACTION_TO_COLOR = ColorMap(_CHANGESET_ACTION_TO_COLOR)
# 
# CHANGESET_REPLACEMENT_TO_COLOR = ColorMap(_CHANGESET_REPLACEMENT_TO_COLOR)
# 
# DRIFT_STATUS_TO_COLOR = ColorMap(_DRIFT_STATUS_TO_COLOR)
# 
# STACK_STATUS_TO_COLOR = ColorMap(_STACK_STATUS_TO_COLOR)
# 
# CHANGESET_RESOURCE_REPLACEMENT_TO_COLOR = ColorMap(
#     _CHANGESET_RESOURCE_REPLACEMENT_TO_COLOR)
# 
# Path: awscfncli2/cli/utils/common.py
# def is_rate_limited_exception(e):
#     if isinstance(e, (botocore.exceptions.ClientError, botocore.exceptions.WaiterError)):
#         return 'Rate exceeded' in str(e)
#     else:
#         return False
# 
# def is_not_rate_limited_exception(e):
#     return not is_rate_limited_exception(e)
# 
# Path: awscfncli2/cli/utils/events.py
# def start_tail_stack_events_daemon(session,
#                                    stack,
#                                    latest_events=1,
#                                    event_limit=10000,
#                                    time_limit=3600,
#                                    check_interval=5,
#                                    indent=0,
#                                    prefix=None):
#     """Start tailing stack events"""
# 
#     # TODO: Now this causes AWS throttling boto3 call if the tracking stack
#     #       contains a lot of nested stacks and/or long update history.
#     #       Should implement a barrier on how many querys are being sent
#     #       concurrently.
# 
#     thread = threading.Thread(target=tail_stack_events,
#                               args=(session,
#                                     stack, latest_events, event_limit,
#                                     time_limit, check_interval,
#                                     indent, prefix))
#     thread.daemon = True
#     thread.start()
# 
# Path: awscfncli2/cli/utils/pager.py
# def custom_paginator(f, l, **kwargs):
#     """Simple custom paginator for those can_pageniate() returns false
#     :param f: API function
#     :param l: name of the list object to paginate
#     :param kwargs: Args passes to the API function
#     :return: iterator of result object
#     """
#     next_token = None
#     while True:
# 
#         if next_token is None:
#             # boto3 does not accept f(NextToken=None)
#             r = f(**kwargs)
#         else:
#             r = f(NextToken=next_token, **kwargs)
# 
#         for i in r[l]:
#             yield i
# 
#         try:
#             next_token = r['NextToken']
#         except KeyError:
#             break


import difflib
import json
import backoff
import botocore.exceptions
import click
import yaml
from .colormaps import CHANGESET_STATUS_TO_COLOR, CHANGESET_ACTION_TO_COLOR, \
    CHANGESET_REPLACEMENT_TO_COLOR, DRIFT_STATUS_TO_COLOR, \
    STACK_STATUS_TO_COLOR, CHANGESET_RESOURCE_REPLACEMENT_TO_COLOR
from .common import is_rate_limited_exception, is_not_rate_limited_exception
from .events import start_tail_stack_events_daemon
from .pager import custom_paginator
                      value_style=STACK_STATUS_TO_COLOR[status],
                      indent=4)
            if status_reason:
                echo_pair('Reason', status_reason, indent=6)
            echo_pair('Drift Status', drift_status,
                      value_style=DRIFT_STATUS_TO_COLOR[drift_status], indent=4)
            if drift_timestamp:
                echo_pair('Lasted Checked', drift_timestamp, indent=6)

    def pprint_stack_exports(self, stack, session):
        client = session.client('cloudformation')
        echo_pair('Exports')
        for export in custom_paginator(client.list_exports, 'Exports'):
            if export['ExportingStackId'] == stack.stack_id:
                echo_pair(export['Name'], export['Value'], indent=2)
                try:
                    for import_ in custom_paginator(client.list_imports,
                                                    'Imports',
                                                    ExportName=export[
                                                        'Name']):
                        echo_pair('Imported By', import_, indent=4)
                except botocore.exceptions.ClientError as e:
                    pass

    def pprint_changeset(self, result):

        status = result['Status']
        status_reason = result.get('StatusReason', None)

        echo_pair('ChangeSet Status', status,

# Path: awscfncli2/cli/utils/colormaps.py
# CHANGESET_STATUS_TO_COLOR = ColorMap(_CHANGESET_STATUS_TO_COLOR)
# 
# CHANGESET_ACTION_TO_COLOR = ColorMap(_CHANGESET_ACTION_TO_COLOR)
# 
# CHANGESET_REPLACEMENT_TO_COLOR = ColorMap(_CHANGESET_REPLACEMENT_TO_COLOR)
# 
# DRIFT_STATUS_TO_COLOR = ColorMap(_DRIFT_STATUS_TO_COLOR)
# 
# STACK_STATUS_TO_COLOR = ColorMap(_STACK_STATUS_TO_COLOR)
# 
# CHANGESET_RESOURCE_REPLACEMENT_TO_COLOR = ColorMap(
#     _CHANGESET_RESOURCE_REPLACEMENT_TO_COLOR)
# 
# Path: awscfncli2/cli/utils/common.py
# def is_rate_limited_exception(e):
#     if isinstance(e, (botocore.exceptions.ClientError, botocore.exceptions.WaiterError)):
#         return 'Rate exceeded' in str(e)
#     else:
#         return False
# 
# def is_not_rate_limited_exception(e):
#     return not is_rate_limited_exception(e)
# 
# Path: awscfncli2/cli/utils/events.py
# def start_tail_stack_events_daemon(session,
#                                    stack,
#                                    latest_events=1,
#                                    event_limit=10000,
#                                    time_limit=3600,
#                                    check_interval=5,
#                                    indent=0,
#                                    prefix=None):
#     """Start tailing stack events"""
# 
#     # TODO: Now this causes AWS throttling boto3 call if the tracking stack
#     #       contains a lot of nested stacks and/or long update history.
#     #       Should implement a barrier on how many querys are being sent
#     #       concurrently.
# 
#     thread = threading.Thread(target=tail_stack_events,
#                               args=(session,
#                                     stack, latest_events, event_limit,
#                                     time_limit, check_interval,
#                                     indent, prefix))
#     thread.daemon = True
#     thread.start()
# 
# Path: awscfncli2/cli/utils/pager.py
# def custom_paginator(f, l, **kwargs):
#     """Simple custom paginator for those can_pageniate() returns false
#     :param f: API function
#     :param l: name of the list object to paginate
#     :param kwargs: Args passes to the API function
#     :return: iterator of result object
#     """
#     next_token = None
#     while True:
# 
#         if next_token is None:
#             # boto3 does not accept f(NextToken=None)
#             r = f(**kwargs)
#         else:
#             r = f(NextToken=next_token, **kwargs)
# 
#         for i in r[l]:
#             yield i
# 
#         try:
#             next_token = r['NextToken']
#         except KeyError:
#             break


# Path: awscfncli2/cli/utils/pprint.py
import difflib
import json
import backoff
import botocore.exceptions
import click
import yaml
from .colormaps import CHANGESET_STATUS_TO_COLOR, CHANGESET_ACTION_TO_COLOR, \
    CHANGESET_REPLACEMENT_TO_COLOR, DRIFT_STATUS_TO_COLOR, \
    STACK_STATUS_TO_COLOR, CHANGESET_RESOURCE_REPLACEMENT_TO_COLOR
from .common import is_rate_limited_exception, is_not_rate_limited_exception
from .events import start_tail_stack_events_daemon
from .pager import custom_paginator

                      value_style=STACK_STATUS_TO_COLOR[status],
                      indent=4)
            if status_reason:
                echo_pair('Reason', status_reason, indent=6)
            echo_pair('Drift Status', drift_status,
                      value_style=DRIFT_STATUS_TO_COLOR[drift_status], indent=4)
            if drift_timestamp:
                echo_pair('Lasted Checked', drift_timestamp, indent=6)

    def pprint_stack_exports(self, stack, session):
        client = session.client('cloudformation')
        echo_pair('Exports')
        for export in custom_paginator(client.list_exports, 'Exports'):
            if export['ExportingStackId'] == stack.stack_id:
                echo_pair(export['Name'], export['Value'], indent=2)
                try:
                    for import_ in custom_paginator(client.list_imports,
                                                    'Imports',
                                                    ExportName=export[
                                                        'Name']):
                        echo_pair('Imported By', import_, indent=4)
                except botocore.exceptions.ClientError as e:
                    pass

    def pprint_changeset(self, result):

        status = result['Status']
        status_reason = result.get('StatusReason', None)

        echo_pair('ChangeSet Status', status,

                  value_style=CHANGESET_STATUS_TO_COLOR[status])