# 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 InvalidTemplateVersion(TOSCAException):
#     msg_fmt = _('The template version "%(what)s" is invalid. '
#                 'Valid versions are "%(valid_versions)s".')
# 
# Path: toscaparser/common/exception.py
# class UnknownFieldError(TOSCAException):
#     msg_fmt = _('%(what)s contains unknown field "%(field)s". Refer to the '
#                 'definition to verify valid values.')
# 
# Path: toscaparser/extensions/exttools.py
# class ExtTools(object):
#     def __init__(self):
#         self.EXTENSION_INFO = self._load_extensions()
# 
#     def _load_extensions(self):
#         '''Dynamically load all the extensions .'''
#         extensions = collections.OrderedDict()
# 
#         extns = extension.ExtensionManager(namespace='toscaparser.extensions',
#                                            invoke_on_load=True).extensions
# 
#         for e in extns:
#             try:
#                 extinfo = importlib.import_module(e.plugin.__module__)
#                 base_path = os.path.dirname(extinfo.__file__)
#                 version = e.plugin().VERSION
#                 defs_file = base_path + '/' + e.plugin().DEFS_FILE
# 
#                 # Sections is an optional attribute
#                 sections = getattr(e.plugin(), 'SECTIONS', ())
# 
#                 extensions[version] = {'sections': sections,
#                                        'defs_file': defs_file}
#             except ImportError:
#                 raise ToscaExtImportError(ext_name=e.name)
#             except AttributeError:
#                 attrs = ', '.join(REQUIRED_ATTRIBUTES)
#                 raise ToscaExtAttributeError(ext_name=e.name, attrs=attrs)
# 
#         return extensions
# 
#     def get_versions(self):
#         return sorted(self.EXTENSION_INFO.keys())
# 
#     def get_sections(self):
#         sections = {}
#         for version in self.EXTENSION_INFO.keys():
#             sections[version] = self.EXTENSION_INFO[version]['sections']
# 
#         return sections
# 
#     def get_defs_file(self, version):
#         versiondata = self.EXTENSION_INFO.get(version)
# 
#         if versiondata:
#             return versiondata.get('defs_file')
#         else:
#             return None


from toscaparser.common.exception import ExceptionCollector
from toscaparser.common.exception import InvalidTemplateVersion
from toscaparser.common.exception import UnknownFieldError
from toscaparser.extensions.exttools import ExtTools
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.



class TypeValidation(object):

    ALLOWED_TYPE_SECTIONS = (DEFINITION_VERSION, DESCRIPTION, IMPORTS,
                             DSL_DEFINITIONS, NODE_TYPES, REPOSITORIES,
                             DATA_TYPES, ARTIFACT_TYPES, GROUP_TYPES,
                             RELATIONSHIP_TYPES, CAPABILITY_TYPES,
                             INTERFACE_TYPES, POLICY_TYPES,
                             TOPOLOGY_TEMPLATE, METADATA) = \
        ('tosca_definitions_version', 'description', 'imports',
         'dsl_definitions', 'node_types', 'repositories',
         'data_types', 'artifact_types', 'group_types',
         'relationship_types', 'capability_types',
         'interface_types', 'policy_types', 'topology_template',
         'metadata')
    VALID_TEMPLATE_VERSIONS = ['tosca_simple_yaml_1_0',
                               'tosca_simple_yaml_1_2']

# 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 InvalidTemplateVersion(TOSCAException):
#     msg_fmt = _('The template version "%(what)s" is invalid. '
#                 'Valid versions are "%(valid_versions)s".')
# 
# Path: toscaparser/common/exception.py
# class UnknownFieldError(TOSCAException):
#     msg_fmt = _('%(what)s contains unknown field "%(field)s". Refer to the '
#                 'definition to verify valid values.')
# 
# Path: toscaparser/extensions/exttools.py
# class ExtTools(object):
#     def __init__(self):
#         self.EXTENSION_INFO = self._load_extensions()
# 
#     def _load_extensions(self):
#         '''Dynamically load all the extensions .'''
#         extensions = collections.OrderedDict()
# 
#         extns = extension.ExtensionManager(namespace='toscaparser.extensions',
#                                            invoke_on_load=True).extensions
# 
#         for e in extns:
#             try:
#                 extinfo = importlib.import_module(e.plugin.__module__)
#                 base_path = os.path.dirname(extinfo.__file__)
#                 version = e.plugin().VERSION
#                 defs_file = base_path + '/' + e.plugin().DEFS_FILE
# 
#                 # Sections is an optional attribute
#                 sections = getattr(e.plugin(), 'SECTIONS', ())
# 
#                 extensions[version] = {'sections': sections,
#                                        'defs_file': defs_file}
#             except ImportError:
#                 raise ToscaExtImportError(ext_name=e.name)
#             except AttributeError:
#                 attrs = ', '.join(REQUIRED_ATTRIBUTES)
#                 raise ToscaExtAttributeError(ext_name=e.name, attrs=attrs)
# 
#         return extensions
# 
#     def get_versions(self):
#         return sorted(self.EXTENSION_INFO.keys())
# 
#     def get_sections(self):
#         sections = {}
#         for version in self.EXTENSION_INFO.keys():
#             sections[version] = self.EXTENSION_INFO[version]['sections']
# 
#         return sections
# 
#     def get_defs_file(self, version):
#         versiondata = self.EXTENSION_INFO.get(version)
# 
#         if versiondata:
#             return versiondata.get('defs_file')
#         else:
#             return None


# Path: toscaparser/elements/tosca_type_validation.py
from toscaparser.common.exception import ExceptionCollector
from toscaparser.common.exception import InvalidTemplateVersion
from toscaparser.common.exception import UnknownFieldError
from toscaparser.extensions.exttools import ExtTools

#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.



class TypeValidation(object):

    ALLOWED_TYPE_SECTIONS = (DEFINITION_VERSION, DESCRIPTION, IMPORTS,
                             DSL_DEFINITIONS, NODE_TYPES, REPOSITORIES,
                             DATA_TYPES, ARTIFACT_TYPES, GROUP_TYPES,
                             RELATIONSHIP_TYPES, CAPABILITY_TYPES,
                             INTERFACE_TYPES, POLICY_TYPES,
                             TOPOLOGY_TEMPLATE, METADATA) = \
        ('tosca_definitions_version', 'description', 'imports',
         'dsl_definitions', 'node_types', 'repositories',
         'data_types', 'artifact_types', 'group_types',
         'relationship_types', 'capability_types',
         'interface_types', 'policy_types', 'topology_template',
         'metadata')
    VALID_TEMPLATE_VERSIONS = ['tosca_simple_yaml_1_0',
                               'tosca_simple_yaml_1_2']

    exttools = ExtTools()