# Path: ebu_tt_live/bindings/pyxb_utils.py
# def get_xml_parsing_context():
#     """
#     The parsing context is a simple python dictionary that helps tie together semantic rules at parsing time.
# 
#     For example: making sure that limitedClockTimingtype and fullClockTimingType are instantiated appropriately taking
#     into account the timeBase attribute on the tt element. In that case when the timeBase element is encountered by the
#     parser is is added to the parsing context object to help PyXB make the right type in the timingType union.
# 
#     :return: dict that is te parsing context for the currently running parser
#     :return: None if not in parsing mode
#     """
#     log.debug('Accessing xml_parsing_context: {}'.format(__xml_parsing_context))
#     if __xml_parsing_context.parsing is False:
#         # We are not in parsing mode
#         return None
#     return __xml_parsing_context.context
# 
# Path: ebu_tt_live/errors.py
# class LogicError(Exception):
#     pass
# 
# class SemanticValidationError(Exception):
#     pass
# 
# class OutsideSegmentError(StopBranchIteration):
#     """
#     This exception is meant to be raised by the copying functionality to make the iterator know that a particular
#     subtree is not meant to be parsed.
#     """
# 
# Path: ebu_tt_live/strings.py
# ERR_SEMANTIC_VALIDATION_TIMING_TYPE = gettext('{attr_type}({attr_value}) is not a valid type for {attr_name} in timeBase={time_base}')


from datetime import timedelta
from ebu_tt_live.bindings import get_xml_parsing_context
from ebu_tt_live.errors import LogicError, SemanticValidationError, OutsideSegmentError
from ebu_tt_live.strings import ERR_SEMANTIC_VALIDATION_TIMING_TYPE



class TimingValidationMixin(object):
    """
    This mixin is meant to be applied to timed elements (body, div, p, span) and provides parser hooks for timing
    attributes as well as a generic semantic validation for timing attributes in the document's timeBase.
    """

    _computed_begin_time = None
    _computed_end_time = None

    @property
    def computed_begin_time(self):
        return self._computed_begin_time

    @property
    def computed_end_time(self):
        return self._computed_end_time

    def _pre_timing_set_attribute(self, attr_en, attr_use):
        # Pass in the timing_attribute_name to the context to help the timing type constructor refuse creation
        context = get_xml_parsing_context()
        if context is not None:
            # This means we are in XML parsing mode
            context['timing_attribute_name'] = attr_en.localName()

    def _post_timing_set_attribute(self, attr_use):

# Path: ebu_tt_live/bindings/pyxb_utils.py
# def get_xml_parsing_context():
#     """
#     The parsing context is a simple python dictionary that helps tie together semantic rules at parsing time.
# 
#     For example: making sure that limitedClockTimingtype and fullClockTimingType are instantiated appropriately taking
#     into account the timeBase attribute on the tt element. In that case when the timeBase element is encountered by the
#     parser is is added to the parsing context object to help PyXB make the right type in the timingType union.
# 
#     :return: dict that is te parsing context for the currently running parser
#     :return: None if not in parsing mode
#     """
#     log.debug('Accessing xml_parsing_context: {}'.format(__xml_parsing_context))
#     if __xml_parsing_context.parsing is False:
#         # We are not in parsing mode
#         return None
#     return __xml_parsing_context.context
# 
# Path: ebu_tt_live/errors.py
# class LogicError(Exception):
#     pass
# 
# class SemanticValidationError(Exception):
#     pass
# 
# class OutsideSegmentError(StopBranchIteration):
#     """
#     This exception is meant to be raised by the copying functionality to make the iterator know that a particular
#     subtree is not meant to be parsed.
#     """
# 
# Path: ebu_tt_live/strings.py
# ERR_SEMANTIC_VALIDATION_TIMING_TYPE = gettext('{attr_type}({attr_value}) is not a valid type for {attr_name} in timeBase={time_base}')


# Path: ebu_tt_live/bindings/validation/timing.py
from datetime import timedelta
from ebu_tt_live.bindings import get_xml_parsing_context
from ebu_tt_live.errors import LogicError, SemanticValidationError, OutsideSegmentError
from ebu_tt_live.strings import ERR_SEMANTIC_VALIDATION_TIMING_TYPE




class TimingValidationMixin(object):
    """
    This mixin is meant to be applied to timed elements (body, div, p, span) and provides parser hooks for timing
    attributes as well as a generic semantic validation for timing attributes in the document's timeBase.
    """

    _computed_begin_time = None
    _computed_end_time = None

    @property
    def computed_begin_time(self):
        return self._computed_begin_time

    @property
    def computed_end_time(self):
        return self._computed_end_time

    def _pre_timing_set_attribute(self, attr_en, attr_use):
        # Pass in the timing_attribute_name to the context to help the timing type constructor refuse creation
        context = get_xml_parsing_context()
        if context is not None:
            # This means we are in XML parsing mode
            context['timing_attribute_name'] = attr_en.localName()

    def _post_timing_set_attribute(self, attr_use):

        context = get_xml_parsing_context()