validation package¶
validation
Package¶
base
Module¶
This file contains all the pyxb helpers needed for enabling a concise semantic validation approach.
-
class
ebu_tt_live.bindings.validation.base.
IDMixin
[source]¶ Bases:
object
Making sure the IDs are collected and maintained appropriately
-
_re_ebu_id_deconflict
= <_sre.SRE_Pattern object>¶
-
_tp_ebu_id_deconflict
= 'SEQ{sequence_number}.{original_id}'¶
-
-
class
ebu_tt_live.bindings.validation.base.
SemanticDocumentMixin
[source]¶ Bases:
ebu_tt_live.bindings.validation.base.SemanticValidationMixin
-
_semantic_before_validation
()[source]¶ Before PyXB starts its syntactic validation this hook runs where the user may execute custom code.
-
_validator_class
= None¶
-
validateBinding
(**extra_kwargs)[source]¶ Check whether the binding content matches its content model.
@return: C{True} if validation was not performed due to settings or complex result dictionary with success and semantic_dataset keys. @raise pyxb.BatchContentValidationError: complex content does not match model # Wondering about this… @raise pyxb.SimpleTypeValueError: attribute or simple content fails to satisfy constraints
-
-
class
ebu_tt_live.bindings.validation.base.
SemanticValidationMixin
[source]¶ Bases:
object
This mixin contains the necessary boilerplate to enable semantic validation as well as enabling _setAttribute hooks to help populate the context object with useful data.
-
_attr_en_post
= {}¶
-
_attr_en_pre
= {}¶
-
_semantic_after_subtree_copy
(copied_instance, dataset, element_content=None)[source]¶ This is helpful hook function at the copying operation :param dataset: :param element_content: :return:
-
_semantic_after_traversal
(dataset, element_content=None, parent_binding=None)[source]¶ Semantic validation postprocess hook. :param dataset: semantic context object :param element_content: the element itself
-
_semantic_attributes_missing
(attr_names)[source]¶ Making sure that attributes specified in attr_names have no value defined on the binding. :param attr_names: The attributes that were defined on the element. :return:
-
_semantic_attributes_present
(attr_names)[source]¶ Making sure that attributes specified in attr_names have a value defined on the binding :param attr_names: The missing attributes that were not defined. :return:
-
_semantic_before_copy
(dataset, element_content=None)[source]¶ Meant for checks before attempting to copy an element :param dataset: :param element_content: :return:
-
_semantic_before_subtree_copy
(copied_instance, dataset, element_content=None)[source]¶ This is helpful hook function at the copying operation :param dataset: :param element_content: :return:
-
_semantic_before_traversal
(dataset, element_content=None, parent_binding=None)[source]¶ Semantic validation preprocess hook. :param dataset: semantic context object :param element_content: the element itself
-
_semantic_copy
(dataset)[source]¶ This copy function is more powerful as it accepts an extra copying context where a smarter copy can be made. It can be customised by classes. The default is the shallow copy. :param dataset: :return: cloned element
-
_semantic_deconflicted_ids
(attr_name, dataset)[source]¶ Looks up its referenced styles/region in the conversion mapping and returns the new idref string :param datset: :return:
-
validator
Module¶
-
class
ebu_tt_live.bindings.validation.validator.
SemanticValidator
(root_element)[source]¶ Bases:
ebu_tt_live.bindings.pyxb_utils.RecursiveOperation
-
_semantic_dataset
= None¶
-
timing
Module¶
-
class
ebu_tt_live.bindings.validation.timing.
BodyTimingValidationMixin
[source]¶ Bases:
ebu_tt_live.bindings.validation.timing.TimingValidationMixin
The body element seems to be exception from too many rules and makes one common validator pretty difficult to manage. This subclass is meant to call all the extensions/limitations for the body element that does not apply to timed containers in general in the EBU-TT-Live spec.
-
class
ebu_tt_live.bindings.validation.timing.
TimingValidationMixin
[source]¶ Bases:
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¶
-
_post_calculate_begin
(children)[source]¶ The computed begin time shall be moved down to match that of the earliest child begin time in case the container does not specify a begin time itself. NOTE: This does not modify the syncbase.
Parameters: children – Returns:
-
_semantic_postprocess_timing
(dataset, element_content)[source]¶ As the validator traverses in a Depth First Search this is the hook function to call on the way UP
- Steps to take:
- Fill in end times if element doesn’t define end time
- Try using computed_end_time information from its children
- If no children are found look at parents end time constraints.
- Finalize computed_begin_time if begin is not specified using computed_begin_time of children.
Parameters: - dataset – Semantic dataset from semantic validation framework
- element_content – PyXB’s binding placeholder for this binding instance
-
_semantic_preprocess_timing
(dataset, element_content)[source]¶ As the validator traverses in a Depth First Search this is the hook function to call on the way DOWN.
- Steps to take:
- Initialize temporary variables
- Calculate end timing if element defines an end time
- Calculate begin time and syncbase for children
Parameters: - dataset – Semantic dataset from semantic validation framework
- element_content – PyXB’s binding placeholder for this binding instance
-
computed_begin_time
¶
-
computed_end_time
¶
-
presentation
Module¶
-
class
ebu_tt_live.bindings.validation.presentation.
RegionedElementMixin
[source]¶ Bases:
object
Makes sure we always know where we are. Detects double region assignment which is a warning.
-
_validated_region
= None¶
-
-
class
ebu_tt_live.bindings.validation.presentation.
SizingValidationMixin
[source]¶ Bases:
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.
-
class
ebu_tt_live.bindings.validation.presentation.
StyledElementMixin
[source]¶ Bases:
object
This functionality applies to all styled boxes to help computing styling related information
-
_compatible_style_type
= None¶
-
_computed_style
= None¶
-
_inherited_region
= None¶
-
_inherited_styles
= None¶
-
_referenced_styles
= None¶
-
_region_styles
= None¶
-
_semantic_collect_applicable_styles
(dataset, style_type, parent_binding, defer_font_size=False, extra_referenced_styles=None)[source]¶ This function identifies the styling dependency chain for the styled element in question.
Parameters: - dataset – Semantic dataset
- style_type – the style_type to be used in the process (there are different style types for EBU-TT D and live).
- parent_binding – The immediate parent of the styled element in the document structure
- defer_font_size – If True then fontsize can stay percentage in case it could not be calculated
- extra_referenced_styles – Used by region to inject its extra style attributes
Returns:
-
_specified_style
= None¶
-
_validated_styles
= None¶
-
computed_style
¶ In particular because of fontSize cascading semantics we need to be able to calculate the effective fontSize in any styled element container. Without it conversion from absolute values to relative would not be possible. This is a requirement for the EBU-TT-D conversion where only percentages are allowed in sizing attributes. To support converting the pixel/celll values that don’t cascade to percentages that do the simplest approach is to compute the style in whatever crazy constellation of units it may be provided in and generate percentage based styles for p and span elements taking into account their relative cascading nature. Yes if this confused you please refer to the documentation of EBU-TT-D, EBU-TT-Live, TTML and whatever else TTML might refer to in terms of these style attributes. :return:
-
inherited_region
¶
-
specified_style
¶ This is the resolution of the Style attributes that are directly linked to this element even via implicit inheritance of the style attributes :return:
-
validated_styles
¶
-
content
Module¶
-
class
ebu_tt_live.bindings.validation.content.
ContentContainerMixin
[source]¶ Bases:
object
-
is_empty
()[source]¶ This check is made necessary by some splitting edge cases of content. To make empty containers are not included one should check if there really was anything useful in the container. This function is meant to be implemented by the subclasses of this class to make sure the container checks for the right constraints. :return:
-
-
class
ebu_tt_live.bindings.validation.content.
SubtitleContentContainer
[source]¶ Bases:
ebu_tt_live.bindings.validation.content.ContentContainerMixin
,ebu_tt_live.bindings.validation.base.IDMixin
,ebu_tt_live.bindings.validation.timing.TimingValidationMixin
,ebu_tt_live.bindings.validation.base.SemanticValidationMixin
-
is_empty
()[source]¶ This check is made necessary by some splitting edge cases of content. To make empty containers are not included one should check if there really was anything useful in the container. This function is meant to be implemented by the subclasses of this class to make sure the container checks for the right constraints. :return:
-