def from_xml( parent_ctx: typing.Optional[TTMLElement.ParsingContext], xml_elem: et.Element ) -> typing.Optional[RbElement.ParsingContext]: rb_ctx = RbElement.ParsingContext(RbElement, parent_ctx, model.Rb(parent_ctx.doc)) rb_ctx.process(parent_ctx, xml_elem) return rb_ctx
def test_push_child(self): s = model.Rbc() s.push_child(model.Rb()) with self.assertRaises(TypeError): s.push_child(model.P())
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()])
def process(context, inherited_space, inherited_lang, ttml_element): element = model.Rb(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 rb 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
def test_remove_child(self): r = model.Ruby() c1 = model.Rb() c2 = model.Rt() r.push_children([c1, c2]) with self.assertRaises(RuntimeError): c1.remove() with self.assertRaises(RuntimeError): r.remove_child(c1)