# 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 InvalidSchemaError(TOSCAException):
#     msg_fmt = _('%(message)s')
# 
# Path: toscaparser/common/exception.py
# class TOSCAException(Exception):
#     '''Base exception class for TOSCA
# 
#     To correctly use this class, inherit from it and define
#     a 'msg_fmt' property.
# 
#     '''
# 
#     _FATAL_EXCEPTION_FORMAT_ERRORS = False
# 
#     message = _('An unknown exception occurred.')
# 
#     def __init__(self, **kwargs):
#         try:
#             self.message = self.msg_fmt % kwargs
#         except KeyError:
#             exc_info = sys.exc_info()
#             log.exception('Exception in string format operation: %s'
#                           % exc_info[1])
# 
#             if TOSCAException._FATAL_EXCEPTION_FORMAT_ERRORS:
#                 raise exc_info[0]
# 
#     def __str__(self):
#         return self.message
# 
#     @staticmethod
#     def generate_inv_schema_property_error(self, attr, value, valid_values):
#         msg = (_('Schema definition of "%(propname)s" has '
#                  '"%(attr)s" attribute with invalid value '
#                  '"%(value1)s". The value must be one of '
#                  '"%(value2)s".') % {"propname": self.name,
#                                      "attr": attr,
#                                      "value1": value,
#                                      "value2": valid_values})
#         ExceptionCollector.appendException(
#             InvalidSchemaError(message=msg))
# 
#     @staticmethod
#     def set_fatal_format_exception(flag):
#         if isinstance(flag, bool):
#             TOSCAException._FATAL_EXCEPTION_FORMAT_ERRORS = flag
# 
# Path: toscaparser/utils/gettextutils.py
# def _(msg):
#     # type: (object) -> object
#     return _t.gettext(msg)


from toscaparser.common.exception import ExceptionCollector
from toscaparser.common.exception import InvalidSchemaError
from toscaparser.common.exception import TOSCAException
from toscaparser.utils.gettextutils import _
class PropertyDef(object):
    '''TOSCA built-in Property type.'''

    VALID_PROPERTY_KEYNAMES = (PROPERTY_KEYNAME_DEFAULT,
                               PROPERTY_KEYNAME_REQUIRED,
                               PROPERTY_KEYNAME_STATUS) = \
        ('default', 'required', 'status')

    PROPERTY_REQUIRED_DEFAULT = True

    VALID_REQUIRED_VALUES = ['true', 'false']
    VALID_STATUS_VALUES = (PROPERTY_STATUS_SUPPORTED,
                           PROPERTY_STATUS_EXPERIMENTAL) = \
        ('supported', 'experimental')

    PROPERTY_STATUS_DEFAULT = PROPERTY_STATUS_SUPPORTED

    def __init__(self, name, value=None, schema=None):
        self.name = name
        self.value = value
        self.schema = schema
        self._status = self.PROPERTY_STATUS_DEFAULT
        self._required = self.PROPERTY_REQUIRED_DEFAULT

        # Validate required 'type' property exists
        try:
            self.schema['type']
        except KeyError:
            msg = (_('Schema definition of "%(pname)s" must have a "type" '
                     'attribute.') % dict(pname=self.name))

# 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 InvalidSchemaError(TOSCAException):
#     msg_fmt = _('%(message)s')
# 
# Path: toscaparser/common/exception.py
# class TOSCAException(Exception):
#     '''Base exception class for TOSCA
# 
#     To correctly use this class, inherit from it and define
#     a 'msg_fmt' property.
# 
#     '''
# 
#     _FATAL_EXCEPTION_FORMAT_ERRORS = False
# 
#     message = _('An unknown exception occurred.')
# 
#     def __init__(self, **kwargs):
#         try:
#             self.message = self.msg_fmt % kwargs
#         except KeyError:
#             exc_info = sys.exc_info()
#             log.exception('Exception in string format operation: %s'
#                           % exc_info[1])
# 
#             if TOSCAException._FATAL_EXCEPTION_FORMAT_ERRORS:
#                 raise exc_info[0]
# 
#     def __str__(self):
#         return self.message
# 
#     @staticmethod
#     def generate_inv_schema_property_error(self, attr, value, valid_values):
#         msg = (_('Schema definition of "%(propname)s" has '
#                  '"%(attr)s" attribute with invalid value '
#                  '"%(value1)s". The value must be one of '
#                  '"%(value2)s".') % {"propname": self.name,
#                                      "attr": attr,
#                                      "value1": value,
#                                      "value2": valid_values})
#         ExceptionCollector.appendException(
#             InvalidSchemaError(message=msg))
# 
#     @staticmethod
#     def set_fatal_format_exception(flag):
#         if isinstance(flag, bool):
#             TOSCAException._FATAL_EXCEPTION_FORMAT_ERRORS = flag
# 
# Path: toscaparser/utils/gettextutils.py
# def _(msg):
#     # type: (object) -> object
#     return _t.gettext(msg)


# Path: toscaparser/elements/property_definition.py
from toscaparser.common.exception import ExceptionCollector
from toscaparser.common.exception import InvalidSchemaError
from toscaparser.common.exception import TOSCAException
from toscaparser.utils.gettextutils import _

class PropertyDef(object):
    '''TOSCA built-in Property type.'''

    VALID_PROPERTY_KEYNAMES = (PROPERTY_KEYNAME_DEFAULT,
                               PROPERTY_KEYNAME_REQUIRED,
                               PROPERTY_KEYNAME_STATUS) = \
        ('default', 'required', 'status')

    PROPERTY_REQUIRED_DEFAULT = True

    VALID_REQUIRED_VALUES = ['true', 'false']
    VALID_STATUS_VALUES = (PROPERTY_STATUS_SUPPORTED,
                           PROPERTY_STATUS_EXPERIMENTAL) = \
        ('supported', 'experimental')

    PROPERTY_STATUS_DEFAULT = PROPERTY_STATUS_SUPPORTED

    def __init__(self, name, value=None, schema=None):
        self.name = name
        self.value = value
        self.schema = schema
        self._status = self.PROPERTY_STATUS_DEFAULT
        self._required = self.PROPERTY_REQUIRED_DEFAULT

        # Validate required 'type' property exists
        try:
            self.schema['type']
        except KeyError:
            msg = (_('Schema definition of "%(pname)s" must have a "type" '
                     'attribute.') % dict(pname=self.name))

            ExceptionCollector.appendException(