<s> from copy import copy <EOL> import reportlab <EOL> from reportlab . platypus . tableofcontents import drawPageNumbers <EOL> import rst2pdf . genelements as genelements <EOL> Table = genelements . Table <EOL> Paragraph = genelements . Paragraph <EOL> '''<STR_LIT>''' <EOL> class DottedTableOfContents ( genelements . MyTableOfContents ) : <EOL> toc_counter = [ <NUM_LIT:0> ] <EOL> def wrap ( self , availWidth , availHeight ) : <EOL> "<STR_LIT>" <EOL> if len ( self . _lastEntries ) == <NUM_LIT:0> : <EOL> if reportlab . Version <= '<STR_LIT>' : <EOL> _tempEntries = [ ( <NUM_LIT:0> , '<STR_LIT>' , <NUM_LIT:0> ) ] <EOL> else : <EOL> _tempEntries = [ ( <NUM_LIT:0> , '<STR_LIT>' , <EOL> <NUM_LIT:0> , None ) ] <EOL> else : <EOL> _tempEntries = self . _lastEntries <EOL> if _tempEntries : <EOL> base_level = _tempEntries [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] <EOL> else : <EOL> base_level = <NUM_LIT:0> <EOL> def drawTOCEntryEnd ( canvas , kind , label ) : <EOL> '''<STR_LIT>''' <EOL> style , page , key , dot = end_info [ int ( label ) ] <EOL> drawPageNumbers ( canvas , style , [ ( page , key ) ] , availWidth , availHeight , dot ) <EOL> toc_counter = self . toc_counter <EOL> toc_counter [ <NUM_LIT:0> ] += <NUM_LIT:1> <EOL> funcname = '<STR_LIT>' % toc_counter [ <NUM_LIT:0> ] <EOL> setattr ( self . canv , funcname , drawTOCEntryEnd ) <EOL> end_info = [ ] <EOL> tableData = [ ] <EOL> for entry in _tempEntries : <EOL> level , text , pageNum = entry [ : <NUM_LIT:3> ] <EOL> left_col_level = level - base_level <EOL> if reportlab . Version > '<STR_LIT>' : <EOL> style = self . getLevelStyle ( left_col_level ) <EOL> else : <EOL> style = self . levelStyles [ left_col_level ] <EOL> if self . dotsMinLevel >= <NUM_LIT:0> and left_col_level >= self . dotsMinLevel : <EOL> dot = '<STR_LIT>' <EOL> else : <EOL> dot = '<STR_LIT>' <EOL> style = copy ( style ) <EOL> style . textColor = self . linkColor <EOL> key = self . refid_lut . get ( ( level , text , pageNum ) , None ) <EOL> if key : <EOL> if not isinstance ( text , unicode ) : <EOL> text = unicode ( text , '<STR_LIT:utf-8>' ) <EOL> text = u'<STR_LIT>' % ( key , text ) <EOL> para = Paragraph ( '<STR_LIT>' % ( text , funcname , len ( end_info ) ) , style ) <EOL> end_info . append ( ( style , pageNum , key , dot ) ) <EOL> if style . spaceBefore : <EOL> tableData . append ( [ Spacer ( <NUM_LIT:1> , style . spaceBefore ) , ] ) <EOL> tableData . append ( [ para , ] ) <EOL> self . _table = Table ( tableData , colWidths = ( availWidth , ) , style = self . tableStyle ) <EOL> self . width , self . height = self . _table . wrapOn ( self . canv , availWidth , availHeight ) <EOL> return ( self . width , self . height ) <EOL> genelements . MyTableOfContents = DottedTableOfContents </s>
