<s> from acrylamid import log , helpers <EOL> from acrylamid . filters import Filter <EOL> from acrylamid . lib . html import HTMLParser , HTMLParseError <EOL> class Introducer ( HTMLParser ) : <EOL> paragraph_list = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:p>' ] <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , html , maxparagraphs , href , options ) : <EOL> self . maxparagraphs = maxparagraphs <EOL> self . paragraphs = <NUM_LIT:0> <EOL> self . options = options <EOL> self . href = href <EOL> super ( Introducer , self ) . __init__ ( html ) <EOL> def handle_starttag ( self , tag , attrs ) : <EOL> if self . paragraphs < self . maxparagraphs : <EOL> super ( Introducer , self ) . handle_starttag ( tag , attrs ) <EOL> def handle_data ( self , data ) : <EOL> if self . paragraphs >= self . maxparagraphs : <EOL> pass <EOL> elif len ( self . stack ) < <NUM_LIT:1> or ( self . stack [ <NUM_LIT:0> ] not in self . paragraph_list and self . stack [ - <NUM_LIT:1> ] not in self . paragraph_list ) : <EOL> pass <EOL> else : <EOL> self . result . append ( data ) <EOL> def handle_endtag ( self , tag ) : <EOL> if self . paragraphs < self . maxparagraphs : <EOL> if tag in self . paragraph_list : <EOL> self . paragraphs += <NUM_LIT:1> <EOL> super ( Introducer , self ) . handle_endtag ( tag ) <EOL> if self . paragraphs == self . maxparagraphs : <EOL> for x in self . stack [ : ] : <EOL> self . result . append ( '<STR_LIT>' % self . stack . pop ( ) ) <EOL> if self . options [ '<STR_LIT>' ] != '<STR_LIT>' : <EOL> self . result . append ( self . options [ '<STR_LIT>' ] % self . href ) <EOL> def handle_startendtag ( self , tag , attrs ) : <EOL> if self . paragraphs < self . maxparagraphs and tag not in self . options [ '<STR_LIT:ignore>' ] : <EOL> super ( Introducer , self ) . handle_startendtag ( tag , attrs ) <EOL> def handle_entityref ( self , name ) : <EOL> if self . paragraphs < self . maxparagraphs : <EOL> super ( Introducer , self ) . handle_entityref ( name ) <EOL> def handle_charref ( self , char ) : <EOL> if self . paragraphs < self . maxparagraphs : <EOL> super ( Introducer , self ) . handle_charref ( char ) <EOL> def handle_comment ( self , comment ) : <EOL> if self . paragraphs < self . maxparagraphs : <EOL> super ( Introducer , self ) . handle_comment ( comment ) <EOL> class Introduction ( Filter ) : <EOL> match = [ '<STR_LIT>' , ] <EOL> version = <NUM_LIT:2> <EOL> priority = <NUM_LIT> <EOL> defaults = { <EOL> '<STR_LIT:ignore>' : [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> @ property <EOL> def uses ( self ) : <EOL> return self . env . path <EOL> def transform ( self , content , entry , * args ) : <EOL> options = helpers . union ( Introduction . defaults , self . conf . fetch ( '<STR_LIT>' ) ) <EOL> try : <EOL> options . update ( entry . intro ) <EOL> except AttributeError : <EOL> pass <EOL> try : <EOL> maxparagraphs = int ( options . get ( '<STR_LIT>' ) or args [ <NUM_LIT:0> ] ) <EOL> except ( IndexError , ValueError ) as ex : <EOL> if isinstance ( ex , ValueError ) : <EOL> log . warn ( '<STR_LIT>' , <EOL> options . get ( '<STR_LIT>' ) or args [ <NUM_LIT:0> ] ) <EOL> maxparagraphs = <NUM_LIT:1> <EOL> try : <EOL> return '<STR_LIT>' . join ( Introducer ( <EOL> content , maxparagraphs , self . env . path + entry . permalink , options ) . result ) <EOL> except HTMLParseError as e : <EOL> log . exception ( '<STR_LIT>' + entry . filename ) <EOL> return content <EOL> return content </s>
