# 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 InvalidTypeAdditionalRequirementsError(TOSCAException):
#     msg_fmt = _('Additional requirements for type "%(type)s" not met.')
# 
# Path: toscaparser/utils/gettextutils.py
# def _(msg):
#     # type: (object) -> object
#     return _t.gettext(msg)


import logging
import toscaparser.utils.validateutils as validateutils
from toscaparser.common.exception import ExceptionCollector
from toscaparser.common.exception import InvalidTypeAdditionalRequirementsError
from toscaparser.utils.gettextutils import _
                from toscaparser.dataentity import DataEntity
                from toscaparser.dataentity import DataEntity
        'protocol', 'source', 'source_range',
        'target', 'target_range'
    )

    # TODO(TBD) May want to make this a subclass of DataType
    # and change init method to set PortSpec's properties
    def __init__(self):
        pass

    # The following additional requirements MUST be tested:
    # 1) A valid PortSpec MUST have at least one of the following properties:
    #   target, target_range, source or source_range.
    # 2) A valid PortSpec MUST have a value for the source property that
    #    is within the numeric range specified by the property source_range
    #    when source_range is specified.
    # 3) A valid PortSpec MUST have a value for the target property that is
    #    within the numeric range specified by the property target_range
    #    when target_range is specified.
    @staticmethod
    def validate_additional_req(properties, prop_name, custom_def=None, ):
        try:
            source = properties.get(PortSpec.SOURCE)
            source_range = properties.get(PortSpec.SOURCE_RANGE)
            target = properties.get(PortSpec.TARGET)
            target_range = properties.get(PortSpec.TARGET_RANGE)

            # verify one of the specified values is set
            if source is None and source_range is None and \
                    target is None and target_range is None:
                ExceptionCollector.appendException(

# 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 InvalidTypeAdditionalRequirementsError(TOSCAException):
#     msg_fmt = _('Additional requirements for type "%(type)s" not met.')
# 
# Path: toscaparser/utils/gettextutils.py
# def _(msg):
#     # type: (object) -> object
#     return _t.gettext(msg)


# Path: toscaparser/elements/portspectype.py
import logging
import toscaparser.utils.validateutils as validateutils
from toscaparser.common.exception import ExceptionCollector
from toscaparser.common.exception import InvalidTypeAdditionalRequirementsError
from toscaparser.utils.gettextutils import _
                from toscaparser.dataentity import DataEntity
                from toscaparser.dataentity import DataEntity

        'protocol', 'source', 'source_range',
        'target', 'target_range'
    )

    # TODO(TBD) May want to make this a subclass of DataType
    # and change init method to set PortSpec's properties
    def __init__(self):
        pass

    # The following additional requirements MUST be tested:
    # 1) A valid PortSpec MUST have at least one of the following properties:
    #   target, target_range, source or source_range.
    # 2) A valid PortSpec MUST have a value for the source property that
    #    is within the numeric range specified by the property source_range
    #    when source_range is specified.
    # 3) A valid PortSpec MUST have a value for the target property that is
    #    within the numeric range specified by the property target_range
    #    when target_range is specified.
    @staticmethod
    def validate_additional_req(properties, prop_name, custom_def=None, ):
        try:
            source = properties.get(PortSpec.SOURCE)
            source_range = properties.get(PortSpec.SOURCE_RANGE)
            target = properties.get(PortSpec.TARGET)
            target_range = properties.get(PortSpec.TARGET_RANGE)

            # verify one of the specified values is set
            if source is None and source_range is None and \
                    target is None and target_range is None:
                ExceptionCollector.appendException(

                    InvalidTypeAdditionalRequirementsError(