<s> '''<STR_LIT>''' <EOL> from copy import copy <EOL> from log import nodeid , log <EOL> from flowables import MySpacer , MyIndenter , Reference , DelayedTable , Table <EOL> from image import MyImage , VectorPdf <EOL> from opt_imports import Paragraph , sphinx <EOL> from nodehandlers import NodeHandler , FontHandler , HandleEmphasis <EOL> import math_flowable <EOL> from reportlab . platypus import Paragraph , TableStyle <EOL> import sphinx <EOL> import docutils <EOL> class SphinxHandler ( NodeHandler ) : <EOL> sphinxmode = True <EOL> dispatchdict = { } <EOL> def __init__ ( self ) : <EOL> '''<STR_LIT>''' <EOL> mydict = { } <EOL> for key , value in self . _baseclass . dispatchdict . iteritems ( ) : <EOL> value = copy ( value ) <EOL> value . sphinxmode = True <EOL> mydict [ key ] = value <EOL> mydict . update ( self . dispatchdict ) <EOL> self . dispatchdict = mydict <EOL> class SphinxFont ( SphinxHandler , FontHandler ) : <EOL> pass <EOL> class HandleSphinxDefaults ( SphinxHandler , sphinx . addnodes . glossary , <EOL> sphinx . addnodes . start_of_file , <EOL> sphinx . addnodes . compact_paragraph , <EOL> sphinx . addnodes . pending_xref ) : <EOL> pass <EOL> class SphinxListHandler ( SphinxHandler ) : <EOL> def get_text ( self , client , node , replaceEnt ) : <EOL> t = client . gather_pdftext ( node ) <EOL> while t and t [ <NUM_LIT:0> ] in '<STR_LIT:U+002CU+0020>' : <EOL> t = t [ <NUM_LIT:1> : ] <EOL> return t <EOL> class HandleSphinxDescAddname ( SphinxFont , sphinx . addnodes . desc_addname ) : <EOL> fontstyle = "<STR_LIT>" <EOL> class HandleSphinxDescName ( SphinxFont , sphinx . addnodes . desc_name ) : <EOL> fontstyle = "<STR_LIT>" <EOL> class HandleSphinxDescReturn ( SphinxFont , sphinx . addnodes . desc_returns ) : <EOL> def get_font_prefix ( self , client , node , replaceEnt ) : <EOL> return '<STR_LIT>' + client . styleToFont ( "<STR_LIT>" ) <EOL> class HandleSphinxDescType ( SphinxFont , sphinx . addnodes . desc_type ) : <EOL> fontstyle = "<STR_LIT>" <EOL> class HandleSphinxDescParamList ( SphinxListHandler , sphinx . addnodes . desc_parameterlist ) : <EOL> pre = '<STR_LIT>' <EOL> post = '<STR_LIT:)>' <EOL> class HandleSphinxDescParam ( SphinxFont , sphinx . addnodes . desc_parameter ) : <EOL> fontstyle = "<STR_LIT>" <EOL> def get_pre_post ( self , client , node , replaceEnt ) : <EOL> pre , post = FontHandler . get_pre_post ( self , client , node , replaceEnt ) <EOL> if node . hasattr ( '<STR_LIT>' ) : <EOL> pre = '<STR_LIT:U+002CU+0020>' + pre <EOL> else : <EOL> pre = '<STR_LIT>' + pre <EOL> post += '<STR_LIT>' <EOL> return pre , post <EOL> class HandleSphinxDescOpt ( SphinxListHandler , SphinxFont , sphinx . addnodes . desc_optional ) : <EOL> fontstyle = "<STR_LIT>" <EOL> def get_pre_post ( self , client , node , replaceEnt ) : <EOL> prepost = FontHandler . get_pre_post ( self , client , node , replaceEnt ) <EOL> return '<STR_LIT>' % prepost , '<STR_LIT>' % prepost <EOL> class HandleDescAnnotation ( SphinxHandler , HandleEmphasis , sphinx . addnodes . desc_annotation ) : <EOL> pass <EOL> class HandleSphinxIndex ( SphinxHandler , sphinx . addnodes . index ) : <EOL> def gather_elements ( self , client , node , style ) : <EOL> try : <EOL> for entry in node [ '<STR_LIT>' ] : <EOL> client . pending_targets . append ( docutils . nodes . make_id ( entry [ <NUM_LIT:2> ] ) ) <EOL> except IndexError : <EOL> if node [ '<STR_LIT>' ] : <EOL> log . error ( "<STR_LIT>" , <EOL> node [ '<STR_LIT>' ] , nodeid ( node ) ) <EOL> return [ ] <EOL> if sphinx . __version__ < '<STR_LIT:1.0>' : <EOL> class HandleSphinxModule ( SphinxHandler , sphinx . addnodes . module ) : <EOL> def gather_elements ( self , client , node , style ) : <EOL> return [ Reference ( '<STR_LIT>' + node [ '<STR_LIT>' ] ) ] <EOL> class HandleSphinxCentered ( SphinxHandler , sphinx . addnodes . centered ) : <EOL> def gather_elements ( self , client , node , style ) : <EOL> return [ Paragraph ( client . gather_pdftext ( node ) , <EOL> client . styles [ '<STR_LIT>' ] ) ] <EOL> class HandleSphinxDesc ( SphinxHandler , sphinx . addnodes . desc ) : <EOL> def gather_elements ( self , client , node , style ) : <EOL> st = client . styles [ node [ '<STR_LIT>' ] ] <EOL> if st == client . styles [ '<STR_LIT>' ] : <EOL> st = copy ( client . styles [ '<STR_LIT>' ] ) <EOL> st . spaceBefore = <NUM_LIT:0> <EOL> pre = [ MySpacer ( <NUM_LIT:0> , client . styles [ '<STR_LIT>' ] . spaceBefore ) ] <EOL> return pre + client . gather_elements ( node , st ) <EOL> class HandleSphinxDescSignature ( SphinxHandler , sphinx . addnodes . desc_signature ) : <EOL> def gather_elements ( self , client , node , style ) : <EOL> targets = [ i . replace ( '<STR_LIT:U+0020>' , '<STR_LIT>' ) for i in node [ '<STR_LIT>' ] ] <EOL> pre = '<STR_LIT>' <EOL> for i in targets : <EOL> if i not in client . targets : <EOL> pre += '<STR_LIT>' % i <EOL> client . targets . append ( i ) <EOL> return [ Paragraph ( pre + client . gather_pdftext ( node ) , style ) ] <EOL> class HandleSphinxDescContent ( SphinxHandler , sphinx . addnodes . desc_content ) : <EOL> def gather_elements ( self , client , node , style ) : <EOL> return [ MyIndenter ( left = <NUM_LIT:10> ) ] + client . gather_elements ( node , client . styles [ "<STR_LIT>" ] ) + [ MyIndenter ( left = - <NUM_LIT:10> ) ] <EOL> class HandleHList ( SphinxHandler , sphinx . addnodes . hlist ) : <EOL> def gather_elements ( self , client , node , style ) : <EOL> cells = [ [ client . gather_elements ( child , style ) for child in node . children ] ] <EOL> t_style = TableStyle ( client . styles [ '<STR_LIT>' ] . commands ) <EOL> cw = <NUM_LIT> / len ( node . children ) <EOL> return [ DelayedTable ( cells , <EOL> colWidths = [ "<STR_LIT>" % cw , ] * len ( cells ) , <EOL> style = t_style <EOL> ) ] <EOL> from sphinx . ext import mathbase <EOL> class HandleHighlightLang ( SphinxHandler , sphinx . addnodes . highlightlang ) : <EOL> pass <EOL> class HandleSphinxMath ( SphinxHandler , mathbase . math , mathbase . displaymath ) : <EOL> def gather_elements ( self , client , node , style ) : <EOL> mflow = math_flowable . Math ( node . get ( '<STR_LIT>' , '<STR_LIT>' ) , node . get ( '<STR_LIT:label>' , None ) ) <EOL> n = node [ '<STR_LIT>' ] <EOL> if n is not None : <EOL> number = '<STR_LIT>' % node [ '<STR_LIT>' ] <EOL> return [ Table ( [ [ mflow , number ] ] , ) ] <EOL> return [ mflow ] <EOL> def get_text ( self , client , node , replaceEnt ) : <EOL> mf = math_flowable . Math ( node . get ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> w , h = mf . wrap ( <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> descent = mf . descent ( ) <EOL> img = mf . genImage ( ) <EOL> client . to_unlink . append ( img ) <EOL> return '<STR_LIT>' % ( <EOL> img , w , h , - descent ) <EOL> class HandleSphinxEq ( SphinxHandler , mathbase . eqref ) : <EOL> def get_text ( self , client , node , replaceEnt ) : <EOL> return '<STR_LIT>' % ( node [ '<STR_LIT:target>' ] , <EOL> client . styles . linkColor , node . astext ( ) ) <EOL> graphviz_warn = False <EOL> try : <EOL> x = sphinx . ext . graphviz . graphviz <EOL> class HandleSphinxGraphviz ( SphinxHandler , sphinx . ext . graphviz . graphviz ) : <EOL> def gather_elements ( self , client , node , style ) : <EOL> global graphviz_warn <EOL> try : <EOL> if hasattr ( VectorPdf , '<STR_LIT>' ) : <EOL> fname , outfn = sphinx . ext . graphviz . render_dot ( node [ '<STR_LIT>' ] , node [ '<STR_LIT:code>' ] , node [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> else : <EOL> if not graphviz_warn : <EOL> log . warning ( '<STR_LIT>' ) <EOL> graphviz_warn = True <EOL> fname , outfn = sphinx . ext . graphviz . render_dot ( node [ '<STR_LIT>' ] , node [ '<STR_LIT:code>' ] , node [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> if outfn : <EOL> client . to_unlink . append ( outfn ) <EOL> client . to_unlink . append ( outfn + '<STR_LIT>' ) <EOL> else : <EOL> return [ ] <EOL> except sphinx . ext . graphviz . GraphvizError , exc : <EOL> log . error ( '<STR_LIT>' % node [ '<STR_LIT:code>' ] + str ( exc ) ) <EOL> return [ Paragraph ( node [ '<STR_LIT:code>' ] , client . styles [ '<STR_LIT:code>' ] ) ] <EOL> return [ MyImage ( filename = outfn , client = client ) ] <EOL> except AttributeError : <EOL> pass <EOL> sphinxhandlers = SphinxHandler ( ) </s>
