Beispiel #1
0
 def from_xml(
   parent_ctx: typing.Optional[TTMLElement.ParsingContext],
   xml_elem: et.Element
 ) -> typing.Optional[RtcElement.ParsingContext]:
   rtc_ctx = RtcElement.ParsingContext(RtcElement, parent_ctx, model.Rtc(parent_ctx.doc))
   rtc_ctx.process(parent_ctx, xml_elem)
   return rtc_ctx
Beispiel #2
0
    def test_push_children(self):

        r = model.Ruby()

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

        r.remove_children()

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

        r.remove_children()

        r.push_children([model.Rbc(), model.Rtc()])

        r.remove_children()

        r.push_children([model.Rbc(), model.Rtc(), model.Rtc()])

        with self.assertRaises(RuntimeError):
            r.push_children([model.Rb(), model.Rt()])
Beispiel #3
0
    def test_remove_child(self):

        r = model.Rtc()

        c1 = model.Rt()

        c2 = model.Rt()

        r.push_children([c1, c2])

        with self.assertRaises(RuntimeError):
            c1.remove()

        with self.assertRaises(RuntimeError):
            r.remove_child(c1)
Beispiel #4
0
    def process(context, inherited_space, inherited_lang, ttml_element):

        element = model.Rtc(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 children elements

        children = []

        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:

                children.append(child_element)

        try:

            element.push_children(children)

            return element

        except (RuntimeError, TypeError):

            LOGGER.error("Malformed rtc element")

            return None
Beispiel #5
0
    def test_push_child(self):

        r = model.Rtc()

        with self.assertRaises(RuntimeError):
            r.push_child(model.P())