# Path: toscaparser/common/exception.py
# class ExceptionCollector(object):
# 
#     exceptions = []
#     collecting = False
# 
#     @staticmethod
#     def clear():
#         del ExceptionCollector.exceptions[:]
# 
#     @staticmethod
#     def start():
#         ExceptionCollector.clear()
#         ExceptionCollector.collecting = True
# 
#     @staticmethod
#     def stop():
#         ExceptionCollector.collecting = False
# 
#     @staticmethod
#     def contains(exception):
#         for ex in ExceptionCollector.exceptions:
#             if str(ex) == str(exception):
#                 return True
#         return False
# 
#     @staticmethod
#     def appendException(exception):
#         if ExceptionCollector.collecting:
#             if not ExceptionCollector.contains(exception):
#                 exception.trace = traceback.extract_stack()[:-1]
#                 ExceptionCollector.exceptions.append(exception)
#         else:
#             raise exception
# 
#     @staticmethod
#     def exceptionsCaught():
#         return len(ExceptionCollector.exceptions) > 0
# 
#     @staticmethod
#     def getTraceString(traceList):
#         traceString = ''
#         for entry in traceList:
#             f, l, m, c = entry[0], entry[1], entry[2], entry[3]
#             traceString += (_('\t\tFile %(file)s, line %(line)s, in '
#                               '%(method)s\n\t\t\t%(call)s\n')
#                             % {'file': f, 'line': l, 'method': m, 'call': c})
#         return traceString
# 
#     @staticmethod
#     def getExceptionReportEntry(exception, full=True):
#         entry = exception.__class__.__name__ + ': ' + str(exception)
#         if full:
#             entry += '\n' + ExceptionCollector.getTraceString(exception.trace)
#         return entry
# 
#     @staticmethod
#     def getExceptions():
#         return ExceptionCollector.exceptions
# 
#     @staticmethod
#     def getExceptionsReport(full=True):
#         report = []
#         for exception in ExceptionCollector.exceptions:
#             report.append(
#                 ExceptionCollector.getExceptionReportEntry(exception, full))
#         return report
# 
#     @staticmethod
#     def assertExceptionMessage(exception, message):
#         err_msg = exception.__name__ + ': ' + message
#         report = ExceptionCollector.getExceptionsReport(False)
#         assert err_msg in report, (_('Could not find "%(msg)s" in "%(rep)s".')
#                                    % {'rep': report.__str__(), 'msg': err_msg})
# 
# Path: toscaparser/common/exception.py
# class UnsupportedTypeError(TOSCAException):
#     msg_fmt = _('Type "%(what)s" is valid TOSCA type'
#                 ' but not supported at this time.')
# 
# Path: toscaparser/utils/gettextutils.py
# def _(msg):
#     # type: (object) -> object
#     return _t.gettext(msg)


import logging
from toscaparser.common.exception import ExceptionCollector
from toscaparser.common.exception import UnsupportedTypeError
from toscaparser.utils.gettextutils import _


log = logging.getLogger('tosca')


class UnsupportedType(object):

    """Note: TOSCA spec version related

    The tosca.nodes.Storage.ObjectStorage and tosca.nodes.Storage.BlockStorage
    used here as un_supported_types are part of the name changes in TOSCA spec
    version 1.1. The original name as specified in version 1.0 are,
    tosca.nodes.BlockStorage and tosca.nodes.ObjectStorage which are supported
    by the tosca-parser. Since there are little overlapping in version support
    currently in the tosca-parser, the names tosca.nodes.Storage.ObjectStorage
    and tosca.nodes.Storage.BlockStorage are used here to demonstrate the usage
    of un_supported_types. As tosca-parser move to provide support for version
    1.1 and higher, they will be removed.
    """
    un_supported_types = ['tosca.test.invalidtype',
                          'tosca.nodes.Storage.ObjectStorage',
                          'tosca.nodes.Storage.BlockStorage']

    def __init__(self):
        pass

    @staticmethod
    def validate_type(entitytype):
        if entitytype in UnsupportedType.un_supported_types:
            ExceptionCollector.appendException(UnsupportedTypeError(

# Path: toscaparser/common/exception.py
# class ExceptionCollector(object):
# 
#     exceptions = []
#     collecting = False
# 
#     @staticmethod
#     def clear():
#         del ExceptionCollector.exceptions[:]
# 
#     @staticmethod
#     def start():
#         ExceptionCollector.clear()
#         ExceptionCollector.collecting = True
# 
#     @staticmethod
#     def stop():
#         ExceptionCollector.collecting = False
# 
#     @staticmethod
#     def contains(exception):
#         for ex in ExceptionCollector.exceptions:
#             if str(ex) == str(exception):
#                 return True
#         return False
# 
#     @staticmethod
#     def appendException(exception):
#         if ExceptionCollector.collecting:
#             if not ExceptionCollector.contains(exception):
#                 exception.trace = traceback.extract_stack()[:-1]
#                 ExceptionCollector.exceptions.append(exception)
#         else:
#             raise exception
# 
#     @staticmethod
#     def exceptionsCaught():
#         return len(ExceptionCollector.exceptions) > 0
# 
#     @staticmethod
#     def getTraceString(traceList):
#         traceString = ''
#         for entry in traceList:
#             f, l, m, c = entry[0], entry[1], entry[2], entry[3]
#             traceString += (_('\t\tFile %(file)s, line %(line)s, in '
#                               '%(method)s\n\t\t\t%(call)s\n')
#                             % {'file': f, 'line': l, 'method': m, 'call': c})
#         return traceString
# 
#     @staticmethod
#     def getExceptionReportEntry(exception, full=True):
#         entry = exception.__class__.__name__ + ': ' + str(exception)
#         if full:
#             entry += '\n' + ExceptionCollector.getTraceString(exception.trace)
#         return entry
# 
#     @staticmethod
#     def getExceptions():
#         return ExceptionCollector.exceptions
# 
#     @staticmethod
#     def getExceptionsReport(full=True):
#         report = []
#         for exception in ExceptionCollector.exceptions:
#             report.append(
#                 ExceptionCollector.getExceptionReportEntry(exception, full))
#         return report
# 
#     @staticmethod
#     def assertExceptionMessage(exception, message):
#         err_msg = exception.__name__ + ': ' + message
#         report = ExceptionCollector.getExceptionsReport(False)
#         assert err_msg in report, (_('Could not find "%(msg)s" in "%(rep)s".')
#                                    % {'rep': report.__str__(), 'msg': err_msg})
# 
# Path: toscaparser/common/exception.py
# class UnsupportedTypeError(TOSCAException):
#     msg_fmt = _('Type "%(what)s" is valid TOSCA type'
#                 ' but not supported at this time.')
# 
# Path: toscaparser/utils/gettextutils.py
# def _(msg):
#     # type: (object) -> object
#     return _t.gettext(msg)


# Path: toscaparser/unsupportedtype.py
import logging
from toscaparser.common.exception import ExceptionCollector
from toscaparser.common.exception import UnsupportedTypeError
from toscaparser.utils.gettextutils import _



log = logging.getLogger('tosca')


class UnsupportedType(object):

    """Note: TOSCA spec version related

    The tosca.nodes.Storage.ObjectStorage and tosca.nodes.Storage.BlockStorage
    used here as un_supported_types are part of the name changes in TOSCA spec
    version 1.1. The original name as specified in version 1.0 are,
    tosca.nodes.BlockStorage and tosca.nodes.ObjectStorage which are supported
    by the tosca-parser. Since there are little overlapping in version support
    currently in the tosca-parser, the names tosca.nodes.Storage.ObjectStorage
    and tosca.nodes.Storage.BlockStorage are used here to demonstrate the usage
    of un_supported_types. As tosca-parser move to provide support for version
    1.1 and higher, they will be removed.
    """
    un_supported_types = ['tosca.test.invalidtype',
                          'tosca.nodes.Storage.ObjectStorage',
                          'tosca.nodes.Storage.BlockStorage']

    def __init__(self):
        pass

    @staticmethod
    def validate_type(entitytype):
        if entitytype in UnsupportedType.un_supported_types:
            ExceptionCollector.appendException(UnsupportedTypeError(

                                               what=_('%s')