Esempio n. 1
0
    def test_push_children(self):

        r = model.Rtc()

        r.push_children([model.Rt(), model.Rt()])

        r.remove_children()

        r.push_children([model.Rp(), model.Rt(), model.Rt(), model.Rp()])

        with self.assertRaises(ValueError):
            r.push_children([model.Rb(), model.Rt()])
Esempio n. 2
0
 def from_xml(
   parent_ctx: typing.Optional[TTMLElement.ParsingContext],
   xml_elem: et.Element
 ) -> typing.Optional[RpElement.ParsingContext]:
   rp_ctx = RpElement.ParsingContext(RpElement, parent_ctx, model.Rp(parent_ctx.doc))
   rp_ctx.process(parent_ctx, xml_elem)
   return rp_ctx
Esempio n. 3
0
    def test_push_child(self):

        s = model.Rp()

        s.push_child(model.Span())

        with self.assertRaises(TypeError):
            s.push_child(model.P())
Esempio n. 4
0
    def process(context, inherited_space, inherited_lang, ttml_element):

        element = model.Rp(context.doc)

        # process attributes

        element.set_space(
            XMLSpaceAttribute.extract(ttml_element) or inherited_space)

        element.set_lang(
            XMLLangAttribute.extract(ttml_element) or inherited_lang)

        ContentElement.process_region_property(context, ttml_element, element)

        ContentElement.process_style_properties(context, ttml_element, element)

        # process head text node

        if ttml_element.text is not None:
            element.push_child(
                SpanElement.make_anonymous_span(context.doc,
                                                ttml_element.text))

        # process children elements

        for ttml_child_element in ttml_element:

            child_element = ContentElement.process(context,
                                                   element.get_space(),
                                                   element.get_lang(),
                                                   ttml_child_element)

            if child_element is not None:

                if not isinstance(child_element, model.Span):

                    LOGGER.error("Children of rp must be span instances")

                else:

                    element.push_child(child_element)

            # process tail text node

            if ttml_child_element.tail:
                element.push_child(
                    SpanElement.make_anonymous_span(context.doc,
                                                    ttml_child_element.tail))

        return element