src.xmlChecks package

Submodules

src.xmlChecks.actorRefsCheck module

class actorRefsCheck[source]

Bases: XmlCheck

Checks that an actor element’s ttm:agent does not reference an ancestor agent of the element.

run(input: Element, context: dict, validation_results: ValidationLogger) bool[source]

Runs the check.

Must be implemented in a derived class.

Parameters:
  • input – The parsed XML element to check

  • context – A context dictionary used across validation

  • validation_results – Object in which to store any validation results

Returns:

True if the input element passes the check, False otherwise

src.xmlChecks.bbcTimingXmlCheck module

class bbcTimingCheck(epoch: float = 0.0, segment_dur: float | None = None, segment_relative_timing: bool = False)[source]

Bases: XmlCheck

Checks timings in document

Things we need to check:

  • Time expressions are well formed in begin, end, dur attributes:

  • clock-time hh:mm:ss or hh:mm:ss.sss

  • If timeContainer is present, its value is “par”

  • error if a different value

  • warn if present and “par”

Extra things to check: * What’s the earliest begin and latest end time, for info * In case this is in a segment, do the times overlap the segment interval? * Are there enough distinct subtitles in the first 23 minutes? * Are the gaps between subtitles long enough or zero?

run(input: Element, context: dict, validation_results: ValidationLogger) bool[source]

Runs the check.

Must be implemented in a derived class.

Parameters:
  • input – The parsed XML element to check

  • context – A context dictionary used across validation

  • validation_results – Object in which to store any validation results

Returns:

True if the input element passes the check, False otherwise

src.xmlChecks.bodyXmlCheck module

class bodyCheck(sub_checks: list[XmlCheck] = [])[source]

Bases: XmlCheck

Checks body element and content descendants

run(input: Element, context: dict, validation_results: ValidationLogger) bool[source]

Runs the check.

Must be implemented in a derived class.

Parameters:
  • input – The parsed XML element to check

  • context – A context dictionary used across validation

  • validation_results – Object in which to store any validation results

Returns:

True if the input element passes the check, False otherwise

src.xmlChecks.copyrightCheck module

class copyrightCheck(copyright_required: bool = False)[source]

Bases: XmlCheck

Checks presence of copyright element in head

run(input: Element, context: dict, validation_results: ValidationLogger) bool[source]

Runs the check.

Must be implemented in a derived class.

Parameters:
  • input – The parsed XML element to check

  • context – A context dictionary used across validation

  • validation_results – Object in which to store any validation results

Returns:

True if the input element passes the check, False otherwise

src.xmlChecks.daptLangCheck module

class daptLangAudioNonMatchingCheck[source]

Bases: XmlCheck

Checks that the computed xml:lang of every <audio> element matches its parent’s computed xml:lang

recursively_compute_xml_lang_and_check_audio(input: Element, parent_computed_lang: str, content_el_tags: list[str], audio_el_tag: str, validation_results: ValidationLogger) bool[source]
run(input: Element, context: dict, validation_results: ValidationLogger) bool[source]

Runs the check.

Must be implemented in a derived class.

Parameters:
  • input – The parsed XML element to check

  • context – A context dictionary used across validation

  • validation_results – Object in which to store any validation results

Returns:

True if the input element passes the check, False otherwise

class nonEmptyLangRootCheck[source]

Bases: XmlCheck

Checks xml:lang attribute is present and is not empty

run(input: Element, context: dict, validation_results: ValidationLogger) bool[source]

Runs the check.

Must be implemented in a derived class.

Parameters:
  • input – The parsed XML element to check

  • context – A context dictionary used across validation

  • validation_results – Object in which to store any validation results

Returns:

True if the input element passes the check, False otherwise

src.xmlChecks.daptTimingXmlCheck module

class daptTimingCheck(epoch: float = 0.0, segment_dur: float | None = None, segment_relative_timing: bool = False)[source]

Bases: XmlCheck

Checks timings in document

Things we need to check:

  • Time expressions are well formed in begin, end, dur, clipBegin

    and clipEnd attributes:

  • clock-time hh:mm:ss or hh:mm:ss.sss

  • offset-time nn metric or nn.nn metric where metric is h, m, s, ms, f or t

  • Time expressions are well formed in

    /tt/head/metadata/daptm:daptOriginTimecode and /tt/head/metadata/ebuttm:documentStartOfProgramme:

  • clock-time hh:mm:ss:ff for either

  • offset-time a permitted alternative for documentStartOfProgramme

  • If both daptOriginTimecode and documentStartOfProgramme are present,

    but they are different, warn that the contents may be offset by delta relative to the related media

  • If f units are used, there’s a ttp:frameRate on tt

  • frameRate: non-negative integer

  • If t units are used, there’s a ttp:tickRate on tt

  • tickRate: non-negative integer

  • If timeContainer is present, its value is “par”

  • error if a different value

  • warn if present and “par”

Extra things to check: * What’s the earliest begin and latest end time, for info * In case this is in a segment, do the times overlap the segment interval?

run(input: Element, context: dict, validation_results: ValidationLogger) bool[source]

Runs the check.

Must be implemented in a derived class.

Parameters:
  • input – The parsed XML element to check

  • context – A context dictionary used across validation

  • validation_results – Object in which to store any validation results

Returns:

True if the input element passes the check, False otherwise

src.xmlChecks.daptUtils module

isScriptEvent(el: Element, tt_ns: str = 'http://www.w3.org/ns/ttml') bool[source]
isText(el: Element, tt_ns: str = 'http://www.w3.org/ns/ttml') bool[source]

src.xmlChecks.daptmDescTypeCheck module

class daptmDescTypeCheck[source]

Bases: XmlCheck

Checks values of daptm:descType attribute on ttm:descType elements

run(input: Element, context: dict, validation_results: ValidationLogger) bool[source]

Runs the check.

Must be implemented in a derived class.

Parameters:
  • input – The parsed XML element to check

  • context – A context dictionary used across validation

  • validation_results – Object in which to store any validation results

Returns:

True if the input element passes the check, False otherwise

src.xmlChecks.daptmRepresentsCheck module

class daptmRepresentsCheck[source]

Bases: XmlCheck

Checks values of dapt:scriptRepresents and daptm:represents attributes

recursively_compute_child_represents(input: Element, parent_computed_represents: str, represents_attr_tag: str, permitted_represents_el_tags: list[str], required_computed_represents_el_tags: list[str], validation_results: ValidationLogger) bool[source]
run(input: Element, context: dict, validation_results: ValidationLogger) bool[source]

Runs the check.

Must be implemented in a derived class.

Parameters:
  • input – The parsed XML element to check

  • context – A context dictionary used across validation

  • validation_results – Object in which to store any validation results

Returns:

True if the input element passes the check, False otherwise

src.xmlChecks.divXmlCheck module

class divCheck(sub_checks: list[XmlCheck] = [], recurse_div_children: bool = True)[source]

Bases: XmlCheck

Checks the div element

run(input: Element, context: dict, validation_results: ValidationLogger) bool[source]

Runs the check.

Must be implemented in a derived class.

Parameters:
  • input – The parsed XML element to check

  • context – A context dictionary used across validation

  • validation_results – Object in which to store any validation results

Returns:

True if the input element passes the check, False otherwise

src.xmlChecks.headXmlCheck module

class headCheck(sub_checks: list[XmlCheck] = [])[source]

Bases: XmlCheck

Checks presence of several elements in /tt/head.

run(input: Element, context: dict, validation_results: ValidationLogger) bool[source]

Runs the check.

Must be implemented in a derived class.

Parameters:
  • input – The parsed XML element to check

  • context – A context dictionary used across validation

  • validation_results – Object in which to store any validation results

Returns:

True if the input element passes the check, False otherwise

src.xmlChecks.inlineStyleAttributeCheck module

class inlineStyleAttributesCheck[source]

Bases: XmlCheck

Checks for inline style attributes on body, div, p and span.

run(input: Element, context: dict, validation_results: ValidationLogger) bool[source]

Runs the check.

Must be implemented in a derived class.

Parameters:
  • input – The parsed XML element to check

  • context – A context dictionary used across validation

  • validation_results – Object in which to store any validation results

Returns:

True if the input element passes the check, False otherwise

src.xmlChecks.layoutCheck module

class layoutCheck[source]

Bases: XmlCheck

Checks presence and contents of layout element

run(input: Element, context: dict, validation_results: ValidationLogger) bool[source]

Runs the check.

Must be implemented in a derived class.

Parameters:
  • input – The parsed XML element to check

  • context – A context dictionary used across validation

  • validation_results – Object in which to store any validation results

Returns:

True if the input element passes the check, False otherwise

src.xmlChecks.pXmlCheck module

class pCheck(sub_checks: list[XmlCheck] = [])[source]

Bases: XmlCheck

Checks the p element

run(input: Element, context: dict, validation_results: ValidationLogger) bool[source]

Runs the check.

Must be implemented in a derived class.

Parameters:
  • input – The parsed XML element to check

  • context – A context dictionary used across validation

  • validation_results – Object in which to store any validation results

Returns:

True if the input element passes the check, False otherwise

src.xmlChecks.pruner module

class Pruner(no_prune_namespaces: set[str] = {}, no_prune_no_namespace_attributes: set[str] = {})[source]

Bases: XmlCheck

log_pruned_attr(pruned: dict, ns: str, attr_name: str)[source]
log_pruned_el(pruned: dict, ns: str, tag: str)[source]
prune_unrecognised_vocabulary(el: Element, pruned: dict)[source]
run(input: Element, context: dict, validation_results: ValidationLogger) bool[source]

Runs the check.

Must be implemented in a derived class.

Parameters:
  • input – The parsed XML element to check

  • context – A context dictionary used across validation

  • validation_results – Object in which to store any validation results

Returns:

True if the input element passes the check, False otherwise

get_namespace(tag: str) str[source]
get_unqualified_name(tag: str) str[source]

src.xmlChecks.regionRefsCheck module

class regionRefsXmlCheck[source]

Bases: XmlCheck

Checks for unreferenced regions and inappropriate style attributes on region elements.

checkComputedStyles(css: dict[str, str], validation_results: ValidationLogger, location: str, context: dict, error_significance: int = 3) bool[source]
checkSpecifiedStyles(tt_ns: str, sss: dict[str, str], validation_results: ValidationLogger, location: str, error_significance: int = 3) bool[source]
run(input: Element, context: dict, validation_results: ValidationLogger) bool[source]

Runs the check.

Must be implemented in a derived class.

Parameters:
  • input – The parsed XML element to check

  • context – A context dictionary used across validation

  • validation_results – Object in which to store any validation results

Returns:

True if the input element passes the check, False otherwise

src.xmlChecks.spanXmlCheck module

class spanCheck(sub_checks: list[XmlCheck] = [], require_text_in_span: bool = True, permit_nested_spans: bool = False)[source]

Bases: XmlCheck

Checks the span element

run(input: Element, context: dict, validation_results: ValidationLogger) bool[source]

Runs the check.

Must be implemented in a derived class.

Parameters:
  • input – The parsed XML element to check

  • context – A context dictionary used across validation

  • validation_results – Object in which to store any validation results

Returns:

True if the input element passes the check, False otherwise

src.xmlChecks.styleRefsCheck module

class styleRefsXmlCheck[source]

Bases: XmlCheck

Checks for unreferenced styles and inappropriate style attributes.

run(input: Element, context: dict, validation_results: ValidationLogger) bool[source]

Runs the check.

Must be implemented in a derived class.

Parameters:
  • input – The parsed XML element to check

  • context – A context dictionary used across validation

  • validation_results – Object in which to store any validation results

Returns:

True if the input element passes the check, False otherwise

src.xmlChecks.stylingCheck module

class stylingCheck[source]

Bases: XmlCheck

Checks presence and contents of styling element

run(input: Element, context: dict, validation_results: ValidationLogger) bool[source]

Runs the check.

Must be implemented in a derived class.

Parameters:
  • input – The parsed XML element to check

  • context – A context dictionary used across validation

  • validation_results – Object in which to store any validation results

Returns:

True if the input element passes the check, False otherwise

src.xmlChecks.textCheck module

class checkLineBreaks[source]

Bases: XmlCheck

Checks for line breaks instead of <br> elements

run(input: Element, context: dict, validation_results: ValidationLogger) bool[source]

Runs the check.

Must be implemented in a derived class.

Parameters:
  • input – The parsed XML element to check

  • context – A context dictionary used across validation

  • validation_results – Object in which to store any validation results

Returns:

True if the input element passes the check, False otherwise

class noTextChildren[source]

Bases: XmlCheck

Checks that element has no text children

run(input: Element, context: dict, validation_results: ValidationLogger) bool[source]

Runs the check.

Must be implemented in a derived class.

Parameters:
  • input – The parsed XML element to check

  • context – A context dictionary used across validation

  • validation_results – Object in which to store any validation results

Returns:

True if the input element passes the check, False otherwise

src.xmlChecks.timingAttributeCheck module

getParentTimingAttributes(context: dict) set[source]
getTimingAttributes(el: Element) set[source]
class noNestedTimedElementsCheck[source]

Bases: XmlCheck

Checks for nested elements that have timing attributes

run(input: Element, context: dict, validation_results: ValidationLogger) bool[source]

Runs the check.

Must be implemented in a derived class.

Parameters:
  • input – The parsed XML element to check

  • context – A context dictionary used across validation

  • validation_results – Object in which to store any validation results

Returns:

True if the input element passes the check, False otherwise

class noTimingAttributeCheck[source]

Bases: XmlCheck

Checks there are no timing attributes on the input element

run(input: Element, context: dict, validation_results: ValidationLogger) bool[source]

Runs the check.

Must be implemented in a derived class.

Parameters:
  • input – The parsed XML element to check

  • context – A context dictionary used across validation

  • validation_results – Object in which to store any validation results

Returns:

True if the input element passes the check, False otherwise

popParentTimingAttributes(context: dict) set[source]
pushParentTimingAttributes(timing_attributes: set, context: dict) None[source]

src.xmlChecks.ttXmlCheck module

class activeAreaCheck(activeArea_required: bool = False)[source]

Bases: XmlCheck

activeArea_re = re.compile('^(?P<leftOffset>[\\d]+(\\.[\\d]+)?)%[\\s]+(?P<topOffset>[\\d]+(\\.[\\d]+)?)%[\\s]+(?P<width>[\\d]+(\\.[\\d]+)?)%[\\s]+(?P<height>[\\d]+(\\.[\\d]+)?)%$')
run(input: Element, context: dict, validation_results: ValidationLogger) bool[source]

Runs the check.

Must be implemented in a derived class.

Parameters:
  • input – The parsed XML element to check

  • context – A context dictionary used across validation

  • validation_results – Object in which to store any validation results

Returns:

True if the input element passes the check, False otherwise

class cellResolutionCheck(cellResolution_required: bool = False)[source]

Bases: XmlCheck

cellResolution_re = re.compile('^(?P<horizontal>[\\d]+)[\\s]+(?P<vertical>[\\d]+)$')
default_cellResolution = '32 15'
run(input: Element, context: dict, validation_results: ValidationLogger) bool[source]

Runs the check.

Must be implemented in a derived class.

Parameters:
  • input – The parsed XML element to check

  • context – A context dictionary used across validation

  • validation_results – Object in which to store any validation results

Returns:

True if the input element passes the check, False otherwise

class contentProfilesCheck(contentProfiles_atleastonelist: list[str] = [], contentProfiles_denylist: list[str] = [], contentProfiles_required: bool = False)[source]

Bases: XmlCheck

run(input: Element, context: dict, validation_results: ValidationLogger) bool[source]

Runs the check.

Must be implemented in a derived class.

Parameters:
  • input – The parsed XML element to check

  • context – A context dictionary used across validation

  • validation_results – Object in which to store any validation results

Returns:

True if the input element passes the check, False otherwise

class timeBaseCheck(timeBase_acceptlist: list[str] = ['media'], timeBase_required: bool = False)[source]

Bases: XmlCheck

default_timeBase = 'media'
run(input: Element, context: dict, validation_results: ValidationLogger) bool[source]

Runs the check.

Must be implemented in a derived class.

Parameters:
  • input – The parsed XML element to check

  • context – A context dictionary used across validation

  • validation_results – Object in which to store any validation results

Returns:

True if the input element passes the check, False otherwise

class ttTagAndNamespaceCheck[source]

Bases: XmlCheck

run(input: Element, context: dict, validation_results: ValidationLogger) bool[source]

Runs the check.

Must be implemented in a derived class.

Parameters:
  • input – The parsed XML element to check

  • context – A context dictionary used across validation

  • validation_results – Object in which to store any validation results

Returns:

True if the input element passes the check, False otherwise

src.xmlChecks.ttmlRoleCheck module

class ttmlRoleTypeCheck[source]

Bases: XmlCheck

Checks values of ttm:role attribute

run(input: Element, context: dict, validation_results: ValidationLogger) bool[source]

Runs the check.

Must be implemented in a derived class.

Parameters:
  • input – The parsed XML element to check

  • context – A context dictionary used across validation

  • validation_results – Object in which to store any validation results

Returns:

True if the input element passes the check, False otherwise

src.xmlChecks.ttmlUtils module

src.xmlChecks.xmlCheck module

class XmlCheck[source]

Bases: object

run(input: Element, context: dict, validation_results: ValidationLogger) bool[source]

Runs the check.

Must be implemented in a derived class.

Parameters:
  • input – The parsed XML element to check

  • context – A context dictionary used across validation

  • validation_results – Object in which to store any validation results

Returns:

True if the input element passes the check, False otherwise

src.xmlChecks.xmlIdCheck module

class IDREFSelementApplicabilityCheck[source]

Bases: XmlCheck

Checks that IDREFS attributes dereference to an appropriate element.

run(input: Element, context: dict, validation_results: ValidationLogger) bool[source]

Runs the check.

Must be implemented in a derived class.

Parameters:
  • input – The parsed XML element to check

  • context – A context dictionary used across validation

  • validation_results – Object in which to store any validation results

Returns:

True if the input element passes the check, False otherwise

class duplicateXmlIdCheck[source]

Bases: XmlCheck

run(input: Element, context: dict, validation_results: ValidationLogger) bool[source]

Runs the check.

Must be implemented in a derived class.

Parameters:
  • input – The parsed XML element to check

  • context – A context dictionary used across validation

  • validation_results – Object in which to store any validation results

Returns:

True if the input element passes the check, False otherwise

qualify(tag: str, tt_ns: str) str[source]
qualifyTags(attr_to_ell_map: dict[str, list[str]], tt_ns: str) dict[str, list[str]][source]
class requireXmlId[source]

Bases: XmlCheck

Checks that element has an xml:id attribute

run(input: Element, context: dict, validation_results: ValidationLogger) bool[source]

Runs the check.

Must be implemented in a derived class.

Parameters:
  • input – The parsed XML element to check

  • context – A context dictionary used across validation

  • validation_results – Object in which to store any validation results

Returns:

True if the input element passes the check, False otherwise

class unqualifiedIdAttributeCheck[source]

Bases: XmlCheck

run(input: Element, context: dict, validation_results: ValidationLogger) bool[source]

Runs the check.

Must be implemented in a derived class.

Parameters:
  • input – The parsed XML element to check

  • context – A context dictionary used across validation

  • validation_results – Object in which to store any validation results

Returns:

True if the input element passes the check, False otherwise

src.xmlChecks.xsdValidator module

class xsdValidator(xml_schema: XMLSchema10, schema_name: str)[source]

Bases: XmlCheck

run(input: Element, context: dict, validation_results: ValidationLogger) bool[source]

Runs the check.

Must be implemented in a derived class.

Parameters:
  • input – The parsed XML element to check

  • context – A context dictionary used across validation

  • validation_results – Object in which to store any validation results

Returns:

True if the input element passes the check, False otherwise

Module contents