<s> """<STR_LIT>""" <EOL> from datetime import datetime <EOL> from werkzeug . utils import escape <EOL> from werkzeug . wrappers import BaseResponse <EOL> from werkzeug . _compat import implements_to_string , string_types <EOL> XHTML_NAMESPACE = '<STR_LIT>' <EOL> def _make_text_block ( name , content , content_type = None ) : <EOL> """<STR_LIT>""" <EOL> if content_type == '<STR_LIT>' : <EOL> return u'<STR_LIT>' % ( name , XHTML_NAMESPACE , content , name ) <EOL> if not content_type : <EOL> return u'<STR_LIT>' % ( name , escape ( content ) , name ) <EOL> return u'<STR_LIT>' % ( name , content_type , <EOL> escape ( content ) , name ) <EOL> def format_iso8601 ( obj ) : <EOL> """<STR_LIT>""" <EOL> return obj . strftime ( '<STR_LIT>' ) <EOL> @ implements_to_string <EOL> class AtomFeed ( object ) : <EOL> """<STR_LIT>""" <EOL> default_generator = ( '<STR_LIT>' , None , None ) <EOL> def __init__ ( self , title = None , entries = None , ** kwargs ) : <EOL> self . title = title <EOL> self . title_type = kwargs . get ( '<STR_LIT>' , '<STR_LIT:text>' ) <EOL> self . url = kwargs . get ( '<STR_LIT:url>' ) <EOL> self . feed_url = kwargs . get ( '<STR_LIT>' , self . url ) <EOL> self . id = kwargs . get ( '<STR_LIT:id>' , self . feed_url ) <EOL> self . updated = kwargs . get ( '<STR_LIT>' ) <EOL> self . author = kwargs . get ( '<STR_LIT>' , ( ) ) <EOL> self . icon = kwargs . get ( '<STR_LIT>' ) <EOL> self . logo = kwargs . get ( '<STR_LIT>' ) <EOL> self . rights = kwargs . get ( '<STR_LIT>' ) <EOL> self . rights_type = kwargs . get ( '<STR_LIT>' ) <EOL> self . subtitle = kwargs . get ( '<STR_LIT>' ) <EOL> self . subtitle_type = kwargs . get ( '<STR_LIT>' , '<STR_LIT:text>' ) <EOL> self . generator = kwargs . get ( '<STR_LIT>' ) <EOL> if self . generator is None : <EOL> self . generator = self . default_generator <EOL> self . links = kwargs . get ( '<STR_LIT>' , [ ] ) <EOL> self . entries = entries and list ( entries ) or [ ] <EOL> if not hasattr ( self . author , '<STR_LIT>' ) or isinstance ( self . author , string_types + ( dict , ) ) : <EOL> self . author = [ self . author ] <EOL> for i , author in enumerate ( self . author ) : <EOL> if not isinstance ( author , dict ) : <EOL> self . author [ i ] = { '<STR_LIT:name>' : author } <EOL> if not self . title : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> if not self . id : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> for author in self . author : <EOL> if '<STR_LIT:name>' not in author : <EOL> raise TypeError ( '<STR_LIT>' ) <EOL> def add ( self , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if len ( args ) == <NUM_LIT:1> and not kwargs and isinstance ( args [ <NUM_LIT:0> ] , FeedEntry ) : <EOL> self . entries . append ( args [ <NUM_LIT:0> ] ) <EOL> else : <EOL> kwargs [ '<STR_LIT>' ] = self . feed_url <EOL> self . entries . append ( FeedEntry ( * args , ** kwargs ) ) <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' % ( <EOL> self . __class__ . __name__ , <EOL> self . title , <EOL> len ( self . entries ) <EOL> ) <EOL> def generate ( self ) : <EOL> """<STR_LIT>""" <EOL> if not self . author : <EOL> if False in map ( lambda e : bool ( e . author ) , self . entries ) : <EOL> self . author = ( { '<STR_LIT:name>' : '<STR_LIT>' } , ) <EOL> if not self . updated : <EOL> dates = sorted ( [ entry . updated for entry in self . entries ] ) <EOL> self . updated = dates and dates [ - <NUM_LIT:1> ] or datetime . utcnow ( ) <EOL> yield u'<STR_LIT>' <EOL> yield u'<STR_LIT>' <EOL> yield '<STR_LIT:U+0020>' + _make_text_block ( '<STR_LIT:title>' , self . title , self . title_type ) <EOL> yield u'<STR_LIT>' % escape ( self . id ) <EOL> yield u'<STR_LIT>' % format_iso8601 ( self . updated ) <EOL> if self . url : <EOL> yield u'<STR_LIT>' % escape ( self . url ) <EOL> if self . feed_url : <EOL> yield u'<STR_LIT>' % escape ( self . feed_url ) <EOL> for link in self . links : <EOL> yield u'<STR_LIT>' % '<STR_LIT>' . join ( '<STR_LIT>' % ( k , escape ( link [ k ] ) ) for k in link ) <EOL> for author in self . author : <EOL> yield u'<STR_LIT>' <EOL> yield u'<STR_LIT>' % escape ( author [ '<STR_LIT:name>' ] ) <EOL> if '<STR_LIT>' in author : <EOL> yield u'<STR_LIT>' % escape ( author [ '<STR_LIT>' ] ) <EOL> if '<STR_LIT:email>' in author : <EOL> yield '<STR_LIT>' % escape ( author [ '<STR_LIT:email>' ] ) <EOL> yield '<STR_LIT>' <EOL> if self . subtitle : <EOL> yield '<STR_LIT:U+0020>' + _make_text_block ( '<STR_LIT>' , self . subtitle , <EOL> self . subtitle_type ) <EOL> if self . icon : <EOL> yield u'<STR_LIT>' % escape ( self . icon ) <EOL> if self . logo : <EOL> yield u'<STR_LIT>' % escape ( self . logo ) <EOL> if self . rights : <EOL> yield '<STR_LIT:U+0020>' + _make_text_block ( '<STR_LIT>' , self . rights , <EOL> self . rights_type ) <EOL> generator_name , generator_url , generator_version = self . generator <EOL> if generator_name or generator_url or generator_version : <EOL> tmp = [ u'<STR_LIT>' ] <EOL> if generator_url : <EOL> tmp . append ( u'<STR_LIT>' % escape ( generator_url ) ) <EOL> if generator_version : <EOL> tmp . append ( u'<STR_LIT>' % escape ( generator_version ) ) <EOL> tmp . append ( u'<STR_LIT>' % escape ( generator_name ) ) <EOL> yield u'<STR_LIT>' . join ( tmp ) <EOL> for entry in self . entries : <EOL> for line in entry . generate ( ) : <EOL> yield u'<STR_LIT:U+0020>' + line <EOL> yield u'<STR_LIT>' <EOL> def to_string ( self ) : <EOL> """<STR_LIT>""" <EOL> return u'<STR_LIT>' . join ( self . generate ( ) ) <EOL> def get_response ( self ) : <EOL> """<STR_LIT>""" <EOL> return BaseResponse ( self . to_string ( ) , mimetype = '<STR_LIT>' ) <EOL> def __call__ ( self , environ , start_response ) : <EOL> """<STR_LIT>""" <EOL> return self . get_response ( ) ( environ , start_response ) <EOL> def __str__ ( self ) : <EOL> return self . to_string ( ) <EOL> @ implements_to_string <EOL> class FeedEntry ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , title = None , content = None , feed_url = None , ** kwargs ) : <EOL> self . title = title <EOL> self . title_type = kwargs . get ( '<STR_LIT>' , '<STR_LIT:text>' ) <EOL> self . content = content <EOL> self . content_type = kwargs . get ( '<STR_LIT>' , '<STR_LIT:html>' ) <EOL> self . url = kwargs . get ( '<STR_LIT:url>' ) <EOL> self . id = kwargs . get ( '<STR_LIT:id>' , self . url ) <EOL> self . updated = kwargs . get ( '<STR_LIT>' ) <EOL> self . summary = kwargs . get ( '<STR_LIT>' ) <EOL> self . summary_type = kwargs . get ( '<STR_LIT>' , '<STR_LIT:html>' ) <EOL> self . author = kwargs . get ( '<STR_LIT>' , ( ) ) <EOL> self . published = kwargs . get ( '<STR_LIT>' ) <EOL> self . rights = kwargs . get ( '<STR_LIT>' ) <EOL> self . links = kwargs . get ( '<STR_LIT>' , [ ] ) <EOL> self . categories = kwargs . get ( '<STR_LIT>' , [ ] ) <EOL> self . xml_base = kwargs . get ( '<STR_LIT>' , feed_url ) <EOL> if not hasattr ( self . author , '<STR_LIT>' ) or isinstance ( self . author , string_types + ( dict , ) ) : <EOL> self . author = [ self . author ] <EOL> for i , author in enumerate ( self . author ) : <EOL> if not isinstance ( author , dict ) : <EOL> self . author [ i ] = { '<STR_LIT:name>' : author } <EOL> if not self . title : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> if not self . id : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> if not self . updated : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' % ( <EOL> self . __class__ . __name__ , <EOL> self . title <EOL> ) <EOL> def generate ( self ) : <EOL> """<STR_LIT>""" <EOL> base = '<STR_LIT>' <EOL> if self . xml_base : <EOL> base = '<STR_LIT>' % escape ( self . xml_base ) <EOL> yield u'<STR_LIT>' % base <EOL> yield u'<STR_LIT:U+0020>' + _make_text_block ( '<STR_LIT:title>' , self . title , self . title_type ) <EOL> yield u'<STR_LIT>' % escape ( self . id ) <EOL> yield u'<STR_LIT>' % format_iso8601 ( self . updated ) <EOL> if self . published : <EOL> yield u'<STR_LIT>' % format_iso8601 ( self . published ) <EOL> if self . url : <EOL> yield u'<STR_LIT>' % escape ( self . url ) <EOL> for author in self . author : <EOL> yield u'<STR_LIT>' <EOL> yield u'<STR_LIT>' % escape ( author [ '<STR_LIT:name>' ] ) <EOL> if '<STR_LIT>' in author : <EOL> yield u'<STR_LIT>' % escape ( author [ '<STR_LIT>' ] ) <EOL> if '<STR_LIT:email>' in author : <EOL> yield u'<STR_LIT>' % escape ( author [ '<STR_LIT:email>' ] ) <EOL> yield u'<STR_LIT>' <EOL> for link in self . links : <EOL> yield u'<STR_LIT>' % '<STR_LIT>' . join ( '<STR_LIT>' % ( k , escape ( link [ k ] ) ) for k in link ) <EOL> for category in self . categories : <EOL> yield u'<STR_LIT>' % '<STR_LIT>' . join ( '<STR_LIT>' % ( k , escape ( category [ k ] ) ) for k in category ) <EOL> if self . summary : <EOL> yield u'<STR_LIT:U+0020>' + _make_text_block ( '<STR_LIT>' , self . summary , <EOL> self . summary_type ) <EOL> if self . content : <EOL> yield u'<STR_LIT:U+0020>' + _make_text_block ( '<STR_LIT:content>' , self . content , <EOL> self . content_type ) <EOL> yield u'<STR_LIT>' <EOL> def to_string ( self ) : <EOL> """<STR_LIT>""" <EOL> return u'<STR_LIT>' . join ( self . generate ( ) ) <EOL> def __str__ ( self ) : <EOL> return self . to_string ( ) </s>
