Beispiel #1
0
 def from_xml(cls, element, **kwargs):
     type = element.attrib.get("type", "text").lower()
     src = element.attrib.get("src")
     if src:
         content = None
     elif type in ("text", "html"):
         content = flatten_xml_content(element)
     elif type == "xhtml":
         content = wrap_xml_tree(element, QName(xhtml_ns, "div"))
     elif (type in ('text/xml', 'application/xml',
                    'text/xml-external-parsed-entity',
                    'application/xml-external-parsed-entity',
                    'application/xml-dtd')
           or type.endswith('+xml') or type.endswith('/xml')):
         if len(element) == 1 and not element.text:
             content = element[0]
         else:
             content = element
     elif type.startswith("text/"):
         content = flatten_xml_content(elment)
     else:
         # XXX This is probably not robust enough.
         content = base64.b64decode(element.text)
     return super(AtomContent, cls).from_xml(element, type=type,
                                             src=src, content=content,
                                             **kwargs)
Beispiel #2
0
 def from_xml(cls, element, **kwargs):
     type = element.attrib.get("type", "text").lower().strip()
     if type in ("text", "html"):
         text = flatten_xml_content(element)
     elif type == "xhtml":
         text = wrap_xml_tree(element, QName(xhtml_ns, "dvi"))
     else:
         text = None
     return super(AtomText, cls).from_xml(element, type=type, text=text,
                                          **kwargs)