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>
_semantic_register_id(dataset)[source]
_tp_ebu_id_deconflict = 'SEQ{sequence_number}.{original_id}'
deconflict_id(seq_num)[source]
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 = {}
_find_deconflicted_elem_by_id(elem_id, dataset)[source]
_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:

_setAttribute(attr_en, value_lex)[source]
get_attribute_value(att_name)[source]

This function is a handy extension that allows us to easily look up attribute values regardless whether they are local or namespaced attribute names. I did not find its equivalent in PyXB. :param att_name: :return:

merge(other_elem, dataset)[source]

Try and merge the contents of 2 elements of the same type. :param other_elem: :return:

validator Module

class ebu_tt_live.bindings.validation.validator.SemanticValidator(root_element)[source]

Bases: ebu_tt_live.bindings.pyxb_utils.RecursiveOperation

_after_element(value, element=None, parent_binding=None, **kwargs)[source]
_before_element(value, element=None, parent_binding=None, **kwargs)[source]
_process_element(value, element=None, parent_binding=None, **kwargs)[source]
_process_non_element(value, non_element, parent_binding=None, **kwargs)[source]
_semantic_dataset = None
_semantic_validation_filter(value, element)[source]
proceed(**kwargs)[source]

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.

_post_cleanup_variables()[source]
_post_pop_end()[source]
_pre_calculate_begin()[source]
_pre_calculate_end()[source]
_pre_init_variables(dataset, element_content)[source]
_semantic_timebase_validation(dataset, element_content)[source]
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.

_assert_in_segment(dataset, element_content=None)[source]
_computed_begin_time = None
_computed_end_time = None
_element_badly_timed(value, element)[source]
_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:
_post_cleanup_variables()[source]
_post_pop_begin()[source]
_post_pop_end()[source]
_post_timing_set_attribute(attr_use)[source]
_pre_assign_begin(proposed_begin)[source]
_pre_assign_end(proposed_end)[source]
_pre_calculate_begin()[source]
_pre_calculate_end()[source]
_pre_init_variables(dataset, element_content)[source]
_pre_timing_set_attribute(attr_en, attr_use)[source]
_semantic_copy_apply_leaf_timing(copied_instance, dataset, element_content=None)[source]
_semantic_manage_timeline(dataset, element_content)[source]
_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
_semantic_timebase_validation(dataset, element_content)[source]
computed_begin_time
computed_end_time
is_in_segment(begin=None, end=None)[source]
is_timed_leaf()[source]

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.

_semantic_copy_verify_referenced_region(dataset)[source]
_semantic_set_region(dataset, region_type)[source]
_semantic_unset_region(dataset)[source]
_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.

_semantic_check_sizing_type(value, dataset)[source]

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

_semantic_validate_sizing_context(dataset)[source]

The attribute can check if it is valid in the context provided by dataset :param dataset: The semantic dataset :raises SimpleTypeValueError

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:

_semantic_copy_verify_referenced_styles(dataset)[source]
_semantic_pop_styles(dataset)[source]
_semantic_push_styles(dataset)[source]
_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

_assert_empty_container()[source]
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

contains_subtitles()[source]
content_to_string(begin=None, end=None)[source]
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: