<s> """<STR_LIT>""" <EOL> from pyramid import i18n <EOL> from h import presenters <EOL> from h import util <EOL> import h . feeds . util <EOL> _ = i18n . TranslationStringFactory ( __package__ ) <EOL> def _feed_entry_from_annotation ( <EOL> annotation , annotation_url , annotation_api_url = None ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> name = util . user . split_user ( annotation [ "<STR_LIT:user>" ] ) [ "<STR_LIT:username>" ] <EOL> except ValueError : <EOL> name = annotation [ "<STR_LIT:user>" ] <EOL> entry = { <EOL> "<STR_LIT:id>" : h . feeds . util . tag_uri_for_annotation ( <EOL> annotation . annotation , annotation_url ) , <EOL> "<STR_LIT>" : { "<STR_LIT:name>" : name } , <EOL> "<STR_LIT:title>" : annotation . title , <EOL> "<STR_LIT>" : annotation [ "<STR_LIT>" ] , <EOL> "<STR_LIT>" : annotation [ "<STR_LIT>" ] , <EOL> "<STR_LIT:content>" : annotation . description , <EOL> "<STR_LIT>" : [ <EOL> { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT:type>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : annotation_url ( annotation . annotation ) } , <EOL> ] <EOL> } <EOL> if annotation_api_url : <EOL> entry [ "<STR_LIT>" ] . append ( <EOL> { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT:type>" : "<STR_LIT:application/json>" , <EOL> "<STR_LIT>" : annotation_api_url ( annotation . annotation ) } <EOL> ) <EOL> entry [ "<STR_LIT>" ] . extend ( <EOL> [ { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : link } for link in annotation . target_links ] ) <EOL> return entry <EOL> def feed_from_annotations ( <EOL> annotations , atom_url , annotation_url , annotation_api_url = None , <EOL> html_url = None , title = None , subtitle = None ) : <EOL> """<STR_LIT>""" <EOL> annotations = [ presenters . AnnotationHTMLPresenter ( a ) for a in annotations ] <EOL> links = [ { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT:type>" : "<STR_LIT>" , "<STR_LIT>" : atom_url } ] <EOL> if html_url : <EOL> links . append ( <EOL> { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT:type>" : "<STR_LIT>" , "<STR_LIT>" : html_url } ) <EOL> entries = [ <EOL> _feed_entry_from_annotation ( a , annotation_url , annotation_api_url ) <EOL> for a in annotations ] <EOL> feed = { <EOL> "<STR_LIT:id>" : atom_url , <EOL> "<STR_LIT:title>" : title or _ ( "<STR_LIT>" ) , <EOL> "<STR_LIT>" : subtitle or _ ( "<STR_LIT>" ) , <EOL> "<STR_LIT>" : entries , <EOL> "<STR_LIT>" : links <EOL> } <EOL> if annotations : <EOL> feed [ "<STR_LIT>" ] = annotations [ <NUM_LIT:0> ] [ "<STR_LIT>" ] <EOL> return feed </s>
