Example #1
0
 def _semantic_timebase_validation(self, dataset, element_content):
     time_base = dataset['tt_element'].timeBase
     if self.begin is not None:
         if hasattr(self.begin, 'compatible_timebases'):
             # Check typing of begin attribute against the timebase
             timebases = self.begin.compatible_timebases()
             if time_base not in timebases['begin']:
                 raise SemanticValidationError(
                     ERR_SEMANTIC_VALIDATION_TIMING_TYPE.format(
                         attr_type=type(self.begin),
                         attr_value=self.begin,
                         attr_name='begin',
                         time_base=time_base
                     )
                 )
     if self.end is not None:
         if hasattr(self.end, 'compatible_timebases'):
             # Check typing of end attribute against the timebase
             timebases = self.end.compatible_timebases()
             if time_base not in timebases['end']:
                 raise SemanticValidationError(
                     ERR_SEMANTIC_VALIDATION_TIMING_TYPE.format(
                         attr_type=type(self.end),
                         attr_value=self.end,
                         attr_name='end',
                         time_base=time_base
                     )
                 )
Example #2
0
    def _ConvertArguments_vx(cls, args, kw):
        """
        This hook is called before the type in question is instantiated. This is meant to do some normalization
        of input parameters and convert them to tuple. In this function we check the timeBase and the attribute name
        against our compatible_timebases mapping inside the timing type class. If an invalid scenario is encountered
        SimpleTypeValueError is raised, which effectively prevents the timingType union to instantiate the type.

        :raises pyxb.SimpleTypeValueError:
        :param args:
        :param kw:
        :return: tuple of converted input parameters.
        """
        result = []
        # In parsing mode check timebase compatibility at instantiation time. This prevents pyxb instantiating
        # the wrong type given 2 types having overlapping values in a union as it happens in full and limited
        # clock timing types.
        context = get_xml_parsing_context()
        if context is not None:
            # This means we are in XML parsing context. There should be a timeBase and a timing_attribute_name in the
            # context object.
            time_base = context['timeBase']
            # It is possible for a timing type to exist as the value of an element not an attribute,
            # in which case no timing_attribute_name is in the context; in that case don't attempt
            # to validate the data against a timebase. At the moment this only affects the
            # documentStartOfProgramme metadata element.
            if 'timing_attribute_name' in context:
                timing_att_name = context['timing_attribute_name']
                if time_base not in cls._compatible_timebases[timing_att_name]:
                    log.debug(
                        ERR_SEMANTIC_VALIDATION_TIMING_TYPE.format(
                            attr_name=timing_att_name,
                            attr_type=cls,
                            attr_value=args,
                            time_base=time_base))
                    raise pyxb.SimpleTypeValueError(
                        ERR_SEMANTIC_VALIDATION_TIMING_TYPE.format(
                            attr_name=timing_att_name,
                            attr_type=cls,
                            attr_value=args,
                            time_base=time_base))
        for item in args:
            if isinstance(item, timedelta):
                result.append(cls.from_timedelta(item))
            else:
                result.append(item)
        return tuple(result)
Example #3
0
    def _ConvertArguments_vx(cls, args, kw):
        """
        This hook is called before the type in question is instantiated. This is meant to do some normalization
        of input parameters and convert them to tuple. In this function we check the timeBase and the attribute name
        against our compatible_timebases mapping inside the timing type class. If an invalid scenario is encountered
        SimpleTypeValueError is raised, which effectively prevents the timingType union to instantiate the type.

        :raises pyxb.SimpleTypeValueError:
        :param args:
        :param kw:
        :return: tuple of converted input parameters.
        """
        result = []
        # In parsing mode check timebase compatibility at instantiation time. This prevents pyxb instantiating
        # the wrong type given 2 types having overlapping values in a union as it happens in full and limited
        # clock timing types.
        context = get_xml_parsing_context()
        if context is not None:
            # This means we are in XML parsing context. There should be a timeBase and a timing_attribute_name in the
            # context object.
            time_base = context['timeBase']
            timing_att_name = context['timing_attribute_name']
            if time_base not in cls._compatible_timebases[timing_att_name]:
                log.debug(ERR_SEMANTIC_VALIDATION_TIMING_TYPE.format(
                    attr_name=timing_att_name,
                    attr_type=cls,
                    attr_value=args,
                    time_base=time_base
                ))
                raise pyxb.SimpleTypeValueError(ERR_SEMANTIC_VALIDATION_TIMING_TYPE.format(
                    attr_name=timing_att_name,
                    attr_type=cls,
                    attr_value=args,
                    time_base=time_base
                ))
        for item in args:
            if isinstance(item, timedelta):
                result.append(cls.from_timedelta(item))
            else:
                result.append(item)
        return tuple(result)
Example #4
0
 def _semantic_timebase_validation(self, dataset, element_content):
     time_base = dataset['tt_element'].timeBase
     if self.begin is not None:
         if hasattr(self.begin, 'compatible_timebases'):
             # Check typing of begin attribute against the timebase
             timebases = self.begin.compatible_timebases()
             if time_base not in timebases['begin']:
                 raise SemanticValidationError(
                     ERR_SEMANTIC_VALIDATION_TIMING_TYPE.format(
                         attr_type=type(self.begin),
                         attr_value=self.begin,
                         attr_name='begin',
                         time_base=time_base))
     if self.end is not None:
         if hasattr(self.end, 'compatible_timebases'):
             # Check typing of end attribute against the timebase
             timebases = self.end.compatible_timebases()
             if time_base not in timebases['end']:
                 raise SemanticValidationError(
                     ERR_SEMANTIC_VALIDATION_TIMING_TYPE.format(
                         attr_type=type(self.end),
                         attr_value=self.end,
                         attr_name='end',
                         time_base=time_base))
Example #5
0
    def _semantic_timebase_validation(self, dataset, element_content):

        super(BodyTimingValidationMixin,
              self)._semantic_timebase_validation(dataset, element_content)
        time_base = dataset['tt_element'].timeBase

        if self.dur is not None:
            if hasattr(self.dur, 'compatible_timebases'):
                # Check typing of dur attribute against the timebase
                timebases = self.dur.compatible_timebases()
                if time_base not in timebases['dur']:
                    raise SemanticValidationError(
                        ERR_SEMANTIC_VALIDATION_TIMING_TYPE.format(
                            attr_type=type(self.dur),
                            attr_value=self.dur,
                            attr_name='dur',
                            time_base=time_base))
Example #6
0
    def _semantic_timebase_validation(self, dataset, element_content):

        super(BodyTimingValidationMixin, self)._semantic_timebase_validation(dataset, element_content)
        time_base = dataset['tt_element'].timeBase

        if self.dur is not None:
            if hasattr(self.dur, 'compatible_timebases'):
                # Check typing of dur attribute against the timebase
                timebases = self.dur.compatible_timebases()
                if time_base not in timebases['dur']:
                    raise SemanticValidationError(
                        ERR_SEMANTIC_VALIDATION_TIMING_TYPE.format(
                            attr_type=type(self.dur),
                            attr_value=self.dur,
                            attr_name='dur',
                            time_base=time_base
                        )
                    )