# Path: ebu_tt_live/errors.py
# class TimeFormatOverflowError(Exception):
#     pass
# 
# class ExtentMissingError(Exception):
# 
#     _attribute = None
# 
#     def __init__(self, attribute):
#         self._attribute = attribute
# 
#     def __str__(self):
#         return ERR_DOCUMENT_EXTENT_MISSING.format(type=type(self._attribute), value=self._attribute)
# 
# Path: ebu_tt_live/strings.py
# ERR_TIME_FORMAT_OVERFLOW = gettext('Time value is out of format range')
# 
# ERR_SEMANTIC_VALIDATION_TIMING_TYPE = gettext('{attr_type}({attr_value}) is not a valid type for {attr_name} in timeBase={time_base}')
# 
# ERR_1DIM_ONLY = gettext('{type} accepts 1 dimensional values only')
# 
# ERR_2DIM_ONLY = gettext('{type} accepts 2 dimensional values only')
# 
# 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/bindings/validation/presentation.py
# class SizingValidationMixin(object):
#     """
#     This is meant to validate that the sizing types correspond to the tt element and head region definitions.
#     It is meant to be used by the containing element and its attributes as well so the class interoperates with itself.
#     """
# 
#     def _semantic_check_sizing_type(self, value, dataset):
#         """
#         The sizing attribute is checked by the element for a value and attribute validation is ran as required.
#         :param value: The sizing value to be checked
#         :param dataset: The semantic dataset
#         """
#         if value is not None and isinstance(value, SizingValidationMixin):
#             value._semantic_validate_sizing_context(dataset=dataset)
# 
#     def _semantic_validate_sizing_context(self, dataset):
#         """
#         The attribute can check if it is valid in the context provided by dataset
#         :param dataset: The semantic dataset
#         :raises SimpleTypeValueError
#         """
#         raise NotImplementedError()


from raw._ebuttdt import *
from raw import _ebuttdt as ebuttdt_raw
from datetime import timedelta
from decimal import Decimal
from pyxb.exceptions_ import SimpleTypeValueError, SimpleFacetValueError
from ebu_tt_live.errors import TimeFormatOverflowError, ExtentMissingError
from ebu_tt_live.strings import ERR_TIME_FORMAT_OVERFLOW, ERR_SEMANTIC_VALIDATION_TIMING_TYPE, ERR_1DIM_ONLY, \
    ERR_2DIM_ONLY
from .pyxb_utils import get_xml_parsing_context
from .validation.base import SemanticValidationMixin
from .validation.presentation import SizingValidationMixin
import re, logging
import six

class PixelOriginType(TwoDimSizingMixin, SizingValidationMixin, ebuttdt_raw.pixelOriginType):

    _groups_regex = re.compile('(?:[+-]?(?P<first>\d*\.?\d+)(?:px))\s(?:[+-]?(?P<second>\d*\.?\d+)(?:px))')
    _2dim_format = '{}px {}px'

    def _semantic_validate_sizing_context(self, dataset):
        extent = dataset['tt_element'].extent
        if extent is None:
            raise ExtentMissingError(self)

ebuttdt_raw.pixelOriginType._SetSupersedingClass(PixelOriginType)


class CellOriginType(TwoDimSizingMixin, ebuttdt_raw.cellOriginType):

    _groups_regex = re.compile(r'(?:[+-]?(?P<first>\d*\.?\d+)(?:c))\s(?:[+-]?(?P<second>\d*\.?\d+)(?:c))')
    _2dim_format = '{}c {}c'

ebuttdt_raw.cellOriginType._SetSupersedingClass(CellOriginType)


class PercentageOriginType(TwoDimSizingMixin, ebuttdt_raw.percentageOriginType):

    _groups_regex = re.compile('(?:[+-]?(?P<first>\d*\.?\d+)(?:%))\s(?:[+-]?(?P<second>\d*\.?\d+)(?:%))')
    _2dim_format = '{}% {}%'

ebuttdt_raw.percentageOriginType._SetSupersedingClass(PercentageOriginType)



# Path: ebu_tt_live/errors.py
# class TimeFormatOverflowError(Exception):
#     pass
# 
# class ExtentMissingError(Exception):
# 
#     _attribute = None
# 
#     def __init__(self, attribute):
#         self._attribute = attribute
# 
#     def __str__(self):
#         return ERR_DOCUMENT_EXTENT_MISSING.format(type=type(self._attribute), value=self._attribute)
# 
# Path: ebu_tt_live/strings.py
# ERR_TIME_FORMAT_OVERFLOW = gettext('Time value is out of format range')
# 
# ERR_SEMANTIC_VALIDATION_TIMING_TYPE = gettext('{attr_type}({attr_value}) is not a valid type for {attr_name} in timeBase={time_base}')
# 
# ERR_1DIM_ONLY = gettext('{type} accepts 1 dimensional values only')
# 
# ERR_2DIM_ONLY = gettext('{type} accepts 2 dimensional values only')
# 
# 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/bindings/validation/presentation.py
# class SizingValidationMixin(object):
#     """
#     This is meant to validate that the sizing types correspond to the tt element and head region definitions.
#     It is meant to be used by the containing element and its attributes as well so the class interoperates with itself.
#     """
# 
#     def _semantic_check_sizing_type(self, value, dataset):
#         """
#         The sizing attribute is checked by the element for a value and attribute validation is ran as required.
#         :param value: The sizing value to be checked
#         :param dataset: The semantic dataset
#         """
#         if value is not None and isinstance(value, SizingValidationMixin):
#             value._semantic_validate_sizing_context(dataset=dataset)
# 
#     def _semantic_validate_sizing_context(self, dataset):
#         """
#         The attribute can check if it is valid in the context provided by dataset
#         :param dataset: The semantic dataset
#         :raises SimpleTypeValueError
#         """
#         raise NotImplementedError()


# Path: ebu_tt_live/bindings/_ebuttdt.py
from raw._ebuttdt import *
from raw import _ebuttdt as ebuttdt_raw
from datetime import timedelta
from decimal import Decimal
from pyxb.exceptions_ import SimpleTypeValueError, SimpleFacetValueError
from ebu_tt_live.errors import TimeFormatOverflowError, ExtentMissingError
from ebu_tt_live.strings import ERR_TIME_FORMAT_OVERFLOW, ERR_SEMANTIC_VALIDATION_TIMING_TYPE, ERR_1DIM_ONLY, \
    ERR_2DIM_ONLY
from .pyxb_utils import get_xml_parsing_context
from .validation.base import SemanticValidationMixin
from .validation.presentation import SizingValidationMixin
import re, logging
import six


class PixelOriginType(TwoDimSizingMixin, SizingValidationMixin, ebuttdt_raw.pixelOriginType):

    _groups_regex = re.compile('(?:[+-]?(?P<first>\d*\.?\d+)(?:px))\s(?:[+-]?(?P<second>\d*\.?\d+)(?:px))')
    _2dim_format = '{}px {}px'

    def _semantic_validate_sizing_context(self, dataset):
        extent = dataset['tt_element'].extent
        if extent is None:
            raise ExtentMissingError(self)

ebuttdt_raw.pixelOriginType._SetSupersedingClass(PixelOriginType)


class CellOriginType(TwoDimSizingMixin, ebuttdt_raw.cellOriginType):

    _groups_regex = re.compile(r'(?:[+-]?(?P<first>\d*\.?\d+)(?:c))\s(?:[+-]?(?P<second>\d*\.?\d+)(?:c))')
    _2dim_format = '{}c {}c'

ebuttdt_raw.cellOriginType._SetSupersedingClass(CellOriginType)


class PercentageOriginType(TwoDimSizingMixin, ebuttdt_raw.percentageOriginType):

    _groups_regex = re.compile('(?:[+-]?(?P<first>\d*\.?\d+)(?:%))\s(?:[+-]?(?P<second>\d*\.?\d+)(?:%))')
    _2dim_format = '{}% {}%'

ebuttdt_raw.percentageOriginType._SetSupersedingClass(PercentageOriginType)



class PixelExtentType(TwoDimSizingMixin, SizingValidationMixin, ebuttdt_raw.pixelExtentType):