Exemplo n.º 1
0
 def from_xml(
   parent_ctx: typing.Optional[TTMLElement.ParsingContext],
   xml_elem: et.Element
 ) -> typing.Optional[RbcElement.ParsingContext]:
   rbc_ctx = RbcElement.ParsingContext(RbcElement, parent_ctx, model.Rbc(parent_ctx.doc))
   rbc_ctx.process(parent_ctx, xml_elem)
   return rbc_ctx
Exemplo n.º 2
0
    def test_push_child(self):

        s = model.Rbc()

        s.push_child(model.Rb())

        with self.assertRaises(TypeError):
            s.push_child(model.P())
Exemplo n.º 3
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()])
Exemplo n.º 4
0
    def process(context, inherited_space, inherited_lang, ttml_element):

        element = model.Rbc(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

        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.Rb):

                    LOGGER.error("Children of rbc must be rb instances")

                else:

                    element.push_child(child_element)

        return element