(self, extensions=True)
return entry
Create an ATOM entry and return it.
Create an ATOM entry and return it.
Create an ATOM entry and return it .
def atom_entry(self, extensions=True):
        '''Create an ATOM entry and return it.'''
        entry = xml_elem('entry')
        if not (self.__atom_id and self.__atom_title and self.__atom_updated):
            raise ValueError('Required fields not set')
        id = xml_elem('id', entry)
        id.text = self.__atom_id
        title = xml_elem('title', entry)
        title.text = self.__atom_title
        updated = xml_elem('updated', entry)
        updated.text = self.__atom_updated.isoformat()

        # An entry must contain an alternate link if there is no content
        # element.
        if not self.__atom_content:
            links = self.__atom_link or []
            if not [l for l in links if l.get('rel') == 'alternate']:
                raise ValueError('Entry must contain an alternate link or ' +
                                 'a content element.')

        # Add author elements
        for a in self.__atom_author or []:
            # Atom requires a name. Skip elements without.
            if not a.get('name'):
                continue
            author = xml_elem('author', entry)
            name = xml_elem('name', author)
            name.text = a.get('name')
            if a.get('email'):
                email = xml_elem('email', author)
                email.text = a.get('email')
            if a.get('uri'):
                uri = xml_elem('uri', author)
                uri.text = a.get('uri')

        _add_text_elm(entry, self.__atom_content, 'content')

        for l in self.__atom_link or []:
            link = xml_elem('link', entry, href=l['href'])
            if l.get('rel'):
                link.attrib['rel'] = l['rel']
            if l.get('type'):
                link.attrib['type'] = l['type']
            if l.get('hreflang'):
                link.attrib['hreflang'] = l['hreflang']
            if l.get('title'):
                link.attrib['title'] = l['title']
            if l.get('length'):
                link.attrib['length'] = l['length']

        _add_text_elm(entry, self.__atom_summary, 'summary')

        for c in self.__atom_category or []:
            cat = xml_elem('category', entry, term=c['term'])
            if c.get('scheme'):
                cat.attrib['scheme'] = c['scheme']
            if c.get('label'):
                cat.attrib['label'] = c['label']

        # Add author elements
        for c in self.__atom_contributor or []:
            # Atom requires a name. Skip elements without.
            if not c.get('name'):
                continue
            contrib = xml_elem('contributor', entry)
            name = xml_elem('name', contrib)
            name.text = c.get('name')
            if c.get('email'):
                email = xml_elem('email', contrib)
                email.text = c.get('email')
            if c.get('uri'):
                uri = xml_elem('uri', contrib)
                uri.text = c.get('uri')

        if self.__atom_published:
            published = xml_elem('published', entry)
            published.text = self.__atom_published.isoformat()

        if self.__atom_rights:
            rights = xml_elem('rights', entry)
            rights.text = self.__atom_rights

        if self.__atom_source:
            source = xml_elem('source', entry)
            if self.__atom_source.get('title'):
                source_title = xml_elem('title', source)
                source_title.text = self.__atom_source['title']
            if self.__atom_source.get('link'):
                xml_elem('link', source, href=self.__atom_source['link'])

        if extensions:
            for ext in self.__extensions.values() or []:
                if ext.get('atom'):
                    ext['inst'].extend_atom(entry)

        return entry
def atom_entry ( self , extensions = True ) : entry = xml_elem ( 'entry' ) if not ( self . __atom_id and self . __atom_title and self . __atom_updated ) : raise ValueError ( 'Required fields not set' ) id = xml_elem ( 'id' , entry ) id . text = self . __atom_id title = xml_elem ( 'title' , entry ) title . text = self . __atom_title updated = xml_elem ( 'updated' , entry ) updated . text = self . __atom_updated . isoformat ( ) # An entry must contain an alternate link if there is no content # element. if not self . __atom_content : links = self . __atom_link or [ ] if not [ l for l in links if l . get ( 'rel' ) == 'alternate' ] : raise ValueError ( 'Entry must contain an alternate link or ' + 'a content element.' ) # Add author elements for a in self . __atom_author or [ ] : # Atom requires a name. Skip elements without. if not a . get ( 'name' ) : continue author = xml_elem ( 'author' , entry ) name = xml_elem ( 'name' , author ) name . text = a . get ( 'name' ) if a . get ( 'email' ) : email = xml_elem ( 'email' , author ) email . text = a . get ( 'email' ) if a . get ( 'uri' ) : uri = xml_elem ( 'uri' , author ) uri . text = a . get ( 'uri' ) _add_text_elm ( entry , self . __atom_content , 'content' ) for l in self . __atom_link or [ ] : link = xml_elem ( 'link' , entry , href = l [ 'href' ] ) if l . get ( 'rel' ) : link . attrib [ 'rel' ] = l [ 'rel' ] if l . get ( 'type' ) : link . attrib [ 'type' ] = l [ 'type' ] if l . get ( 'hreflang' ) : link . attrib [ 'hreflang' ] = l [ 'hreflang' ] if l . get ( 'title' ) : link . attrib [ 'title' ] = l [ 'title' ] if l . get ( 'length' ) : link . attrib [ 'length' ] = l [ 'length' ] _add_text_elm ( entry , self . __atom_summary , 'summary' ) for c in self . __atom_category or [ ] : cat = xml_elem ( 'category' , entry , term = c [ 'term' ] ) if c . get ( 'scheme' ) : cat . attrib [ 'scheme' ] = c [ 'scheme' ] if c . get ( 'label' ) : cat . attrib [ 'label' ] = c [ 'label' ] # Add author elements for c in self . __atom_contributor or [ ] : # Atom requires a name. Skip elements without. if not c . get ( 'name' ) : continue contrib = xml_elem ( 'contributor' , entry ) name = xml_elem ( 'name' , contrib ) name . text = c . get ( 'name' ) if c . get ( 'email' ) : email = xml_elem ( 'email' , contrib ) email . text = c . get ( 'email' ) if c . get ( 'uri' ) : uri = xml_elem ( 'uri' , contrib ) uri . text = c . get ( 'uri' ) if self . __atom_published : published = xml_elem ( 'published' , entry ) published . text = self . __atom_published . isoformat ( ) if self . __atom_rights : rights = xml_elem ( 'rights' , entry ) rights . text = self . __atom_rights if self . __atom_source : source = xml_elem ( 'source' , entry ) if self . __atom_source . get ( 'title' ) : source_title = xml_elem ( 'title' , source ) source_title . text = self . __atom_source [ 'title' ] if self . __atom_source . get ( 'link' ) : xml_elem ( 'link' , source , href = self . __atom_source [ 'link' ] ) if extensions : for ext in self . __extensions . values ( ) or [ ] : if ext . get ( 'atom' ) : ext [ 'inst' ] . extend_atom ( entry ) return entry