(entry, data, name)
Add a text subelement to an entry
Add a text subelement to an entry
Add a text subelement to an entry
def _add_text_elm(entry, data, name):
    """Add a text subelement to an entry"""
    if not data:
        return

    elm = xml_elem(name, entry)
    type_ = data.get('type')
    if data.get('src'):
        if name != 'content':
            raise ValueError("Only the 'content' element of an entry can "
                             "contain a 'src' attribute")
        elm.attrib['src'] = data['src']
    elif data.get(name):
        # Surround xhtml with a div tag, parse it and embed it
        if type_ == 'xhtml':
            xhtml = '<div xmlns="http://www.w3.org/1999/xhtml">' \
                    + data.get(name) + '</div>'
            elm.append(xml_fromstring(xhtml))
        elif type_ == 'CDATA':
            elm.text = CDATA(data.get(name))
        # Parse XML and embed it
        elif type_ and (type_.endswith('/xml') or type_.endswith('+xml')):
            elm.append(xml_fromstring(data[name]))
        # Embed the text in escaped form
        elif not type_ or type_.startswith('text') or type_ == 'html':
            elm.text = data.get(name)
        # Everything else should be included base64 encoded
        else:
            raise NotImplementedError(
                'base64 encoded {} is not supported at the moment. '
                'Pull requests adding support are welcome.'.format(name)
            )
    # Add type description of the content
    if type_:
        elm.attrib['type'] = type_
def _add_text_elm ( entry , data , name ) : if not data : return elm = xml_elem ( name , entry ) type_ = data . get ( 'type' ) if data . get ( 'src' ) : if name != 'content' : raise ValueError ( "Only the 'content' element of an entry can " "contain a 'src' attribute" ) elm . attrib [ 'src' ] = data [ 'src' ] elif data . get ( name ) : # Surround xhtml with a div tag, parse it and embed it if type_ == 'xhtml' : xhtml = '<div xmlns="http://www.w3.org/1999/xhtml">' + data . get ( name ) + '</div>' elm . append ( xml_fromstring ( xhtml ) ) elif type_ == 'CDATA' : elm . text = CDATA ( data . get ( name ) ) # Parse XML and embed it elif type_ and ( type_ . endswith ( '/xml' ) or type_ . endswith ( '+xml' ) ) : elm . append ( xml_fromstring ( data [ name ] ) ) # Embed the text in escaped form elif not type_ or type_ . startswith ( 'text' ) or type_ == 'html' : elm . text = data . get ( name ) # Everything else should be included base64 encoded else : raise NotImplementedError ( 'base64 encoded {} is not supported at the moment. ' 'Pull requests adding support are welcome.' . format ( name ) ) # Add type description of the content if type_ : elm . attrib [ 'type' ] = type_